Hey guys. I got another question.
I'm currently trying to figure out the best way to handle animation for my game when the player is walking down.
I have it so that when the button is pressed, it will check to see which leg should go in front then do a small animation of the leg going in front and then going back to the standing still pose.
The animation is being loaded from a spritesheet (you'll see in the code below)
But my framerate drops after loading the texture (it's nearly cut in half because the spritesheet is like 1024 by 1024 pixels).
I was looking on advice on how to code this better.
This code is called everytime the player takes a step in a direction, so if the player is holding the dpad, this code is being called every second or so (so I'm sure it's bad lol).
<I tried to comment it through to help you understand my limited understanding of working with spritesheets>
//Animation for walking
//player sheet
CCTexture2D *texture;
//player frames for animation
CCSpriteFrame *frame0;
CCSpriteFrame *frame1;
NSMutableArray *animFrames;
//Animation test
texture = [[CCTextureCache sharedTextureCache] addImage:@"overworldSheet.png"];
//Animating the player
if (playerWalkingFrame ==1){
//Animation test
frame0 = [CCSpriteFrame frameWithTexture:texture rect:CGRectMake(0,127,32,64) offset:CGPointZero]; //Right leg foward.
frame1 = [CCSpriteFrame frameWithTexture:texture rect:CGRectMake(33,127,32,64) offset:CGPointZero]; //Standing still
// manually add frames to the frame cache
animFrames = [NSMutableArray array];
[animFrames addObject:frame0];
[animFrames addObject:frame1];
playerWalkingFrame--;
} else { //player walking frame =0
//Animation test
frame0 = [CCSpriteFrame frameWithTexture:texture rect:CGRectMake(65,127,32,64) offset:CGPointZero]; //Right leg foward.
frame1 = [CCSpriteFrame frameWithTexture:texture rect:CGRectMake(33,127,32,64) offset:CGPointZero]; //Standing still
// manually add frames to the frame cache
animFrames = [NSMutableArray array];
[animFrames addObject:frame0];
[animFrames addObject:frame1];
playerWalkingFrame++;
}
CCAnimation *animation = [CCAnimation animationWithName:@"walkLeft" delay:0.2f frames:animFrames];
CCAnimate *animate = [CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO];
CCSequence *seq = [CCSequence actions: animate,
nil];
[player runAction:seq ];