2009-11-20 4 views
4

Comment puis-je modifier une position d'image dans cocos2d comme la position d'arrière-plan dans css? Par position je ne veux pas dire la position de fond comme ccp (200,150), je veux dire par exemple, j'ai une image avec une résolution de (1000,200) qui contient 5 (200,200) images. Je montre cette image dans (200,200) sprite et je veux changer la position de l'image pour que je puisse montrer 5 images dans 1 image. Je pense que si vous voulez montrer un mouvement comme courir, vous utilisez des sprites avec 10 images de mouvement et vous changez la position de l'image pour donner l'impression qu'une personne est en train de courir. Comment puis je faire ça? Merci à l'avanceanimation de sprites cocos2d

Répondre

9

Je l'ai trouvé:

AtlasSpriteManager *mgr = [AtlasSpriteManager spriteManagerWithFile:@"ax.png" capacity:6]; 
AtlasSprite *sprite = [AtlasSprite spriteWithRect:CGRectMake(0, 0, 200, 200) spriteManager:mgr]; 
[sprite setTransformAnchor:ccp(0,0)]; 
sprite.position = ccp(100,100); 
[mgr addChild:sprite z:0]; 

// Add manager to this layer 
[self addChild:mgr z:3]; 

// Create animation 
AtlasAnimation* animation = [AtlasAnimation animationWithName:@"testAnimation" delay:0.1]; 
assert(animation != nil); 

// Define the frames in the sprite sheet used for the animation 
[animation addFrameWithRect:CGRectMake(0, 0, 200, 200)]; 
[animation addFrameWithRect:CGRectMake(300, 0, 200, 200)]; 
[animation addFrameWithRect:CGRectMake(400, 0, 200, 200)]; 
[animation addFrameWithRect:CGRectMake(500, 0, 200, 200)]; 
[animation addFrameWithRect:CGRectMake(600, 0, 200, 200)]; 
[animation addFrameWithRect:CGRectMake(700, 12, 200, 200)]; 
id action = [Animate actionWithAnimation:animation]; 
assert(action != nil); 

// Run the animation 
id repeatAction = [Repeat actionWithAction:action times:100]; 

// To repeat forever, use this 
// id repeatAction = [RepeatForever actionWithAction:action]; 

[sprite runAction:repeatAction];