La hoja de sprites de Cocos2d no está animada
Frecuentes
Visto 408 veces
0
SpriteSheets are one thing I just can't get my head around. I'm looking for a very clear and easy to follow way to learn about them. I have read and studied up on them but still have problems.
I don't know why my code isn't working.
-(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];
}
Why is my player not animating?
1 Respuestas
1
Spritesheet is just a convenient way to store textures.
Your CCAnimation object has no frames. You gather an array of frames, but you never use it. Change your
CCAnimation *anim = [CCAnimation animation];
línea a
CCAnimation *anim = [CCAnimation animationWithFrames:frames delay:0.2f];
If you want to animate a sprite, you have to run animating action on this sprite. Use [sprite runAction:repeat]
en lugar de [self runAction:repeat];
.
Respondido 29 ago 12, 14:08
Hey, thank you so much for your help with that. I spent all day today trying to figure it out. animationWithFrames is deprecated. I used animationWithSpriteFrames and it worked fine. Thank you again. - El aprendiz
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas cocos2d-iphone sprite or haz tu propia pregunta.
don't see in your code, where do you use array of frames. you just create empty animation object - Morion
Hi, thanks for your help. I'm trying to get the frames from the plist using CCSpriteFrameCache. - The Learner