I'm using cocos2d-x [lua binding] to port my cocos2d [objective-c] game and I had few classes subclassed. For example I've got a subclass of CCScene [nevermind what it does], which has a onEnter method. In my subclass, KCCScene I also had onEnter and there I called [super onEnter].
So I've read quite a few docs describing inheritance in Lua, but I have never seen a call to the super method.
Is it possible to do? If it is, how should I do something like super:onEnter() ?
Thanks
It really depends on the particular way on which you are doing OO. Some libs provide an "out of the box" way of doing super, others don't. I'm not familiar with Cocos2d-x, but I think it doesn't have one.
A way to achieve that is to use the superclass directly, like this:
function KCCScene:onEnter()
doThis()
CCScene.onEnter(self)
doThat()
end
That should work with all libs doing OO, including Cocos2d-x. However, you lose the nice ":" syntax, and you need to include an explicit "self" parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With