I don't understand why this doesn't work
TextIconX = Core.class(Sprite)
function TextIconX:init(xparams)
local params = xparams or {}
params.tex = xparams.tex or "life.png"
params.text = xparams.text or "xxx"
--
local ico = Bitmap.new(Texture.new(params.tex))
local tf = TextField.new(nil, params.text)
tf:setPosition(ico:getX(), ico:getY())
self:addChild(ico)
self:addChild(tf)
--
return ico, tf
end |
Then in another class I call:local ico, tf = TextIconX.new(
{
tex="life.png", text=0
}
)
print(ico, tf) -- *** table: 032F9230 nil *** |
Why tf is nil please ???
Comments
you can try calling ico,tf=TextIconX:init(...) instead of ico,tf=TextIconX.new(...)
but it would be less confusing if you'd name your function something else, like
TextIconX:generate(xparams) and then call it like ico,tf=TextIconX:generate(...)
Likes: MoKaLux
Fragmenter - animated loop machine and IKONOMIKON - the memory game
I think you are right: ".new" is somewhat special and automatically returns an object of that class
I tried your solutions but cannot make it work
I am a bit surprised as it seems I did it many times before
EDIT: ok I found some code I did before and that worked calling "normal" functions, not Class.new() nor Class:init()
Thank you
http://forum.giderosmobile.com/discussion/comment/62322/#Comment_62322
Likes: MoKaLux
Likes: vitalitymobile, MoKaLux
Thank you all for the help .