이상한 Cocos2d 애니메이션 문제가 있습니다.Cocos2d CCSprite 애니메이션을로드 할 수 없습니다.
내 createAndRunAnimationonSprite 메소드가 호출되면 초기화시 완벽하게 작동합니다.
하지만 show sprite 메서드를 사용하여 버튼에 할당하면 스프라이트가 표시되지 않습니다. 나는이 행동이 왜 일어나고 있는지에 관해서 분실하고있다. 다른 방법이나 수업이 없습니다.
HelloWorldLayer.h
@interface AnimationViewerLayer : CCLayer
{
CCSprite *sprite;
}
HelloWorldLayer.m
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if((self=[super init])) {
CGSize winSize = [[CCDirector sharedDirector] winSize];
// initialize the sprite
sprite = [CCSprite node];
sprite.position = ccp(winSize.width/2 , winSize.height/2);
[self addChild: sprite];
// If this is uncommented the sprite will show up.
// [self createAndRunAnimationOnSprite];
}
return self;
}
- (void) showSprite {
[self createAndRunAnimationOnSprite];
}
-(void) createAndRunAnimationOnSprite {
// stop all previous ones
[sprite stopAllActions];
NSLog(@"Create and Run Animation");
CGSize winSize = [CCDirector sharedDirector].winSize;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"ThisSprite.plist"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"ThisSprite.png"];
[self addChild:spriteSheet];
NSMutableArray *aniFrames = [NSMutableArray array];
for(int i = 1; i <= 3; ++i) {
[aniFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"ThisSprite_walking_%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation animationWithFrames:aniFrames delay:0.1f];
sprite = [CCSprite spriteWithSpriteFrameName:@"ThisSprite_walking_1.png"];
sprite.position = ccp(winSize.width/2, winSize.height/2);
id walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[sprite runAction:walkAction];
[spriteSheet addChild:sprite];
}
[self addChild : sprite]를 제거한 후에도 문제는 동일하게 유지됩니다. 초기화하는 동안 나는 createAndRunAnimationOnSprite를 호출 할 수 있습니다. – JasonBourne
다른 안내는? 나는 정말로 내 머리카락을 꺼내. @ LearnCocos2D – JasonBourne