In the Gideros game development book there is an example on page 50.
It looks like this.
Button = Core.class(Sprite)
function Button:init()
self:addChild(sprite)
end
local bitmap=Bitmap.new(Texture.new("images/balls.png", true))
local btn = Button.new(bitmap)
stage:addChild(btn)
btn:setPosition(100,100)
However this results in an error message:
main.lua:4: bad argument #1 to 'addChild' (Sprite expected, got nil)
stack traceback:
main.lua:4: in function 'init'
[string "property.lua"]:52: in function '__new'
[string "property.lua"]:59: in function 'new'
main.lua:8: in main chunk
Why?
If I leave out the that self:addChild, then it compiles but nothing is rendered.
Comments
- Why do I need the addChild, even when Button is derived from a Sprite class?