Hi all,
I am trying for a simple animation of a character using atlassprite, where a character walks towards his right. I have created the texture file using zwoptex. Each sprite of the walking character has different widths. As I am initiating the atlassprite with a fixed dimension, some of the frames of the character stretches out on animation.
Here is my sample code:
AtlasSpriteManager *mngr = [AtlasSpriteManager spriteManagerWithFile:@"step_forward.png" capacity:50];
textureReader = [[AtlasTextureReader alloc] initWithAtlasManager:mngr :@"step_forward_coordinates.plist"];
AtlasSprite *sprite = [textureReader getSprite:@"0.png"]; // here "0.png" is the first sprite of "step_forward.png"
// the getSprite method returns an AtlasSprite with rect that of 0.png and mngr as AtlasSpriteManager
AtlasAnimation *animation = [AtlasAnimation animationWithName:@"step_forward" delay:0.06f];
for(int i=0;i<=10;i++) {
NSString *name = [NSString stringWithFormat:@"%d", i];
NSString *post_name = @".png";
NSString *sprite_name = [name stringByAppendingString:post_name];
[animation addFrameWithRect: [textureReader getSpriteRect:sprite_name]];
}
[mngr addChild:sprite];
CGSize s = [[Director sharedDirector] winSize];
sprite.position = ccp( s.width /2, s.height/2);
id action1 = [Animate actionWithAnimation: animation];
sprite.scale = 1.0f;
[sprite runAction:action1];
---------------------------------
May be I am doing the animation in the wrong way or else there is a way to alter the sprite rect on runtime.
Any help here will be highly appreciated.