简体   繁体   中英

Cocos2d animation from sprite sheet

So i have the action build to make my frog jump but i have 5 images and i want to run them in the order 1,2,3,4,5,4,3,2,1 using the coordinates. I only want to loop them once everytime the from jumps.

Thanks

while defining your image you can use the following code:

CCAnimation* anim = [CCAnimation animationWithName:@"frog"];
CCSpriteFrame* frames[5];
CGRect Rect;
// some code to initialize Rect position
for(int i=0;i<5;i++)
{
    frames[i] = [CCSpriteFrame frameWithTexture:@"frog.png" rect:Rect];
    // some code to move Rect so that it will mark next frame;
}
for(int i=0;i<5;i++)
    [anim addFrame:frames[i]];
for(int i=3;i>=0;i--)
    [anim addFrame:frames[i]];

use ccanimation and ccspritebatchnodefile

save your image sequence in spritesheet

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM