I have a Tank class that contains a sprite (this seemed like a good design pattern so I can have custom game logic in my classes, have the classes keep physics and sprites in sync, etc). My master GameLayer creates a Tank and then lets the Tank initialize itself. Later, the GameLayer gets an update call, and tells the tank to update itself. In the Tank’s update it is currently just playing some sprite animation over and over (the tank “rumbles” up and down for a few frames and I want to play that animation while it’s just sitting there). So it’s an animation that needs to run for 4 frames, and then repeat until its time for the tank to do something else.
So in the Tank class, I’ve setup an action to play a few frames animating my sprite. After setting up my animation, the call looks like this:
_tankRumble = CCSequence::create(
then on my update loop, I just look at some internal state variable (isAnimating) for the Tank, and if it’s not animating, I make a call to run the animating sequence using _tankRumble from above, and set the state variable to tell me it’s animating so I don’t call it every frame. And then eventually my tankRumbleDone() method will get called back so I can reset my state variable to tell me it’s time to start the animation again on the next loop.
The problem is that the callback seems to go into a black hole. It doesn’t seem to call my Tank object in memory, so the isAnimating state doesn’t work properly. It animates once, and then kaput. Now, if I make my Tank class inherit from CCNode, and then change the call above from the selector to be “this” instead of “sprite” then things work fine. I’ve also tried passing it the layer that contains the tank, and that doesn’t work either. either the layer can have all the logic to do this stuff and it’s fine, or the Tank class needs to inherit from some node (CCNode, CCObject, etc).
why is that? I’m clearly missing something fundamental.