2012-06-03 3 views
0

CCAnimations을 cocos2D에 처음 사용하고 있으며, 힘든 시간을 보냈다는 문제가 있습니다.CCAnimations를 전환 할 때 EXC_BAD_ACCESS

저는 기본 플랫폼 게임을 만들고 있는데, 플레이어 스프라이트에는 플레이어의 상태에 따라 달리해야하는 다양한 애니메이션이 있습니다. 두 애니메이션 중 하나 예상대로이 작동

sprite = [CCSprite spriteWithSpriteFrameName:@"stand.png"]; 

standingSprites = [NSArray arrayWithObjects: 
        [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"stand.png"], 
        nil]; 
runningSprites = [NSArray arrayWithObjects: 
        [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"run1.png"], 
        [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"run2.png"], 
        nil]; 

standingAnimation = [CCAnimation animationWithFrames:standingSprites delay:0.2f]; 
runningAnimation = [CCAnimation animationWithFrames:runningSprites delay:0.2f]; 
animationAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:standingAnimation]]; 
[sprite runAction:animationAction]; 

:

나는 나의 레이어의 init 방법에 다음과 같은 코드가 있습니다. 그러나 플레이어가 정지 상태 일 때 standingAnimation을 실행하고 플레이어가 실행 중일 때 runningAnimation을 실행하고 싶습니다.

-(void)walk { 

    if(!isWalking) { 
     isWalking = true; 
     [sprite stopAction:animationAction]; 
     animationAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:runningAnimation]]; 
     [sprite runAction:animationAction]; 
    } 
} 

마지막 줄에 두 번째는 EXC_BAD_ACCESS (0x0를 참조에) 일으키는 원인이되는 프로그램을 충돌 다음과 같이 나는이 작업을 수행하려고했습니다. 디버거에서 walk을 밟으면 관련 포인터가 null 인 것으로 나타나지 않습니다. 스택 추적에서

:

2012-06-03 10:59:59.907 ThirtyMinutes[9876:6403] *** Terminating app 
due to uncaught exception 'NSInvalidArgumentException', reason: 
'-[NSCTFontDescriptor frames]: unrecognized selector sent to instance 
0x7f808d93e9f0' 

0x7f808d93e9f0runningAnimation의 주소입니다.

  1. 내가 뭘 잘못하고 있니?
  2. 더 좋은 방법이 있나요?

고마워요!

답변

2

오류 메시지는 오류 발생시 0x7f808d93e9f0가 NSCTFontDescriptor 개체의 주소임을 나타냅니다. 그 이유는 runningAnimation을 유지하지 않고 다른 개체에 대한 메모리를 확보했기 때문입니다.

(즉 일어나는 방법은 분명하지 경우 runningAnimation의 선언을 표시합니다.)

+0

애니메이션에서 retain을 호출하면 문제가 해결되었습니다. 감사! – jonmorgan

0

당신은 행동을 당신이 그들을 사용할 때마다 다시해야합니다. 귀하의 경우, 할당 취소 된 작업을 사용하려고했습니다.

관련 문제