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:
class('ParentSprite').extends(gfx.sprite)
function ParentSprite:init(startingX, startingY, radius)
ParentSprite.super.init(self)
local parentSpriteImage = gfx.image.new(radius * 3, radius * 3)
gfx.pushContext(parentSpriteImage)
gfx.fillCircleAtPoint(radius, radius, radius)
gfx.popContext()
self:setImage(parentSpriteImage)
self:moveTo(startingX, startingY)
local childSpriteImage = gfx.image.new(radius * 2 * 1.125)
gfx.pushContext(childSprite)
gfx.drawCircleAtPoint(radius, radius, radius * 1.125)
gfx.popContext()
self.childSprite = gfx.sprite.new()
self.childSprite:setImage(childSpriteImage)
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?
Thanks!