0

I'm making a tank game, and I've got problems with the Cocos2d CCAnimate - more specifically my CCAnimation variables are spontaneously losing their data!

They get used in the state changer of tank object (tank.m)

-(void)changeState:(CharacterStates)newState {
    [self stopAllActions];
    id movementAction = nil;
    action = nil;
    //CCLOG(@"Change state from %i to %i",self.characterState, newState);
    [self setCharacterState:newState];

    switch (newState) {
        case kStateIdle:
            action = [CCAnimate actionWithAnimation: idleAnim       //**ANIM
                               restoreOriginalFrame:NO];            //**ANIM
            [action setTag:kStateIdle];
            break;

        case kStateMoving:
            action = [CCAnimate actionWithAnimation: movingAnim  //**ANIM
                               restoreOriginalFrame:NO];         //**ANIM
            break;

    }

    if (action != nil) {
        [self runAction:action];
    }
}

'action' is predefined in the tank's .h file - "id action;"

When the game initialises, the tanks (there's four of them) get initialised no problems, and they all get set to 'kStateIdle' no problems.

Then the GameEngine main loop calls the tanks for an update - there's a test on their velocity, and checks to make sure they're not already moving or taking damage, and the state is changed to 'kStateMoving' -

if (self.characterState != kStateMoving && self.characterState != kStateTakingDamage && abs(velocity)>0.4) {
        [self changeState:kStateMoving];

But then when the game gets to

[CCAnimate actionWithAnimation: movingAnim restoreOriginalFrame:NO];

Cocos2d crashes with 'EXC_BAD_ACCESS' in 'CCActionInterval', (the debugger reports the _cmd as 'initWithAnimation: restoreOriginalFrame')

The reason why, is because the CCAnimation 'movingAnim' (and idleAnim) are suddenly corrupted.. If I inspect them in the debugger, they have a memory address, but report no value for their frames. They were all there fine when the tank was initialised. And they're all there fine on the player tank. There's nothing that's releasing them (i even removed them from the Dealloc method).

I've got them defined as (monatomic, retain) properties in the tank.h header file.

So where could they possibly have gone? Is there any way of placing a watchpoint on them? (I've got Xcode 4.3.2, so nothing in the menu).. Or is there a way of defining them so they keep their data?

Cheers!

Carl

(PS. Wow! and then I start getting angles calculated at 3259 degrees, I start scratching my head and tracing numbers (which go back to normal whenever I look at them) and bam! Xcode just closes up completely.

Quite hard to debug my program when the Editor itself starts throwing a wobbler!)

CarlosTheJackal
  • 220
  • 1
  • 14

0 Answers0