hello,
I have problems to understand the gideros class system (I have used java so far)...
I want to inherit a class from another class that is inherited from another class...
like so:
Particl2D.lua
particle2D = Core.class(Sprite)
function particle2D:init(texRegion, ID)
self.ID = ID
self:addChild(Bitmap.new(texRegion))
end
Blob.lua
blob = Core.class(Particle2D)
function blob:init(x, y, texRegion)
particle2D.init(self, texRegion, 1)
self:setPosition(x, y)
stage:addChild(self)
end
and then in main.lua
b = blob.new(someTexRegion, 10, 10)
but I get this error message:
buddi/Particle2D.lua:47: attempt to call method 'addChild' (a nil value)
stack traceback:
buddi/Particle2D.lua:47: in function 'init'
buttons/SlotButton.lua:12: in function 'init'
[string "property.lua"]:52: in function '__new'
[string "property.lua"]:59: in function 'new'
main.lua:54: in main chunk
(where line 47 is the line with self:addChild(Bitmap.new(texRegion)) in Particle2D.lua)
however... when I create a particle2D object directly in main.lua then it works...
like so:
p = particle.new(someTexregion, 1)
somewhere here I read that init() is the constructor and I could call the super class with .init(self)...
but I think I'd need some better explanation on how classes in gideros work (and how I can create/inherite them)...
thanks for any help...
PS:
and how can I tag code as code in a post for better reading?
Comments
Try this thread, it may help.
To tag code use
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
So basically inheritance can not work good with classes with different constructor arguments (at least same amount of arguments should be the same by type etc).
So there are different workarounds:
1) check inside particle2D:init which arguments have been passed, so you could determine who is calling constructor and what to do
2) in particle2D leave the init without argumetns and create antoher method like particle2D:create(texRegion, ID) which you could call from blob:init
3) Do not inherit from particle2D but make the instance of it inside blob:init and store as a property so you could use it for anything you wanted to use it
thanks for the quick response...
unfortunately it still doesn't work... even when I use the same arguments for both classes... and also the code dependencies seem to be right...
so I have given up this way for now... and created a new class for blob... it's a bit unhandy but should do for now...
thanks!
Best regards