SpriteSheets 是我无法理解的一件事。我正在寻找一种非常清晰易懂的方式来了解它们。我已经阅读并研究了它们,但仍然有问题。
我不知道为什么我的代码不起作用。
-(void) addPlayer {
CGSize winSize = [[CCDirector sharedDirector] winSize];
CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"walk1.png"];
sprite.position = ccp(winSize.width/2, winSize.height/2);
CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:@"player-walk.png"];
[batchNode addChild:sprite];
[self addChild:batchNode z:350];
NSMutableArray *frames = [NSMutableArray array];
for(int i = 1; i <= 4; ++i) {
[frames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"walk%d.png", i]]];
}
CCAnimation *anim = [CCAnimation animation];
CCAnimate *animate = [CCAnimate actionWithAnimation:anim];
CCRepeatForever *repeat = [CCRepeatForever actionWithAction:animate];
[self runAction:repeat];
}
为什么我的播放器没有动画?