Can't draw sprites contained inside other sprites

This could be a simple question, but I have an custom sprite that has several properties inside, and one of the properties is another sprite. I'm using SDK 2.4.0 on an M1 Mac. I'm trying to draw a circle around a filled circle. Here's a chunk of the code:


function ParentSprite:init(startingX, startingY, radius)
  local parentSpriteImage = * 3, radius * 3)
      gfx.fillCircleAtPoint(radius, radius, radius)

  self:moveTo(startingX, startingY)
  local childSpriteImage = * 2 * 1.125)
      gfx.drawCircleAtPoint(radius, radius, radius * 1.125)
  self.childSprite =
  self.childSprite:moveTo(startingX, startingY)

I'm able to create the child sprite and its properties, but calling the child sprite's add() (via parentSprite.childSprite:add()) method would not draw it on the screen. Moving the child sprite out of the parent and making it its own sprite class does work with the same code. Is there something I'm missing to be able to use it like this?


Here are some problems with the code you've shared:

  1. The height argument is missing when creating the child sprite image
  2. The child sprite is pushed onto the graphics context instead of the child sprite image

Thanks a lot! I had fixed the wrong context but I missed the missing height arg. It works like a charm now

1 Like