I am doing some tests with animations in Cocos2D using sprite-sheets. The animation works ok except that the anchor-point is in the center. I need to put it in the bottom. With the code below i am not able to add an anchor-point to my sprites, after quite a few tests.
Would someone nice be able to help me with this?
-(id) init {
if((self = [super init])) {
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"ratHammer.plist" textureFile:@"ratHammer.pvr.ccz"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"ratHammer.pvr.ccz"];
[self addChild:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for (int i = 0; i <= 5 ; ++i) {
[walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"ratHammer_anim%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.1f];
CGSize winSize = [CCDirector sharedDirector].winSize;
self.bear = [CCSprite spriteWithSpriteFrameName:@"ratHammer_anim0.png"];
_bear.position = ccp(winSize.width/2, winSize.height/2);
self.walkAction = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[_bear runAction:_walkAction];
[spriteSheet addChild:_bear];
}
return self;
}