난 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'
0x7f808d93e9f0
는 runningAnimation
의 주소입니다.
- 내가 뭘 잘못하고 있니?
- 더 좋은 방법이 있나요?
고마워요!
애니메이션에서 retain을 호출하면 문제가 해결되었습니다. 감사! – jonmorgan