La hoja de sprites de Cocos2d no está animada

SpriteSheets son una cosa que simplemente no puedo entender. Estoy buscando una manera muy clara y fácil de seguir para aprender sobre ellos. He leído y estudiado sobre ellos, pero todavía tengo problemas.

No sé por qué mi código no funciona.

-(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];
}

¿Por qué mi reproductor no está animado?

preguntado el 29 de agosto de 12 a las 13:08

no vea en su código, ¿dónde usa la matriz de marcos? simplemente creas un objeto de animación vacío -

Hola, Gracias por tu ayuda. Estoy tratando de obtener los marcos del plist usando CCSpriteFrameCache. -

1 Respuestas

Spritesheet es solo una forma conveniente de almacenar texturas.

Su objeto CCAnimation no tiene marcos. Reúne una serie de marcos, pero nunca los usa. Cambia tu

CCAnimation *anim = [CCAnimation animation];

línea a

CCAnimation *anim = [CCAnimation animationWithFrames:frames delay:0.2f];

Si desea animar un sprite, debe ejecutar la acción de animación en este sprite. Usar [sprite runAction:repeat] en lugar de [self runAction:repeat];.

Respondido 29 ago 12, 14:08

Oye, muchas gracias por tu ayuda con eso. Hoy pasé todo el día tratando de averiguarlo. animationWithFrames está en desuso. Usé animationWithSpriteFrames y funcionó bien. Gracias de nuevo. - El aprendiz

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.