开发者

Using setTexture for animating in Cocos2d?

开发者 https://www.devze.com 2023-04-08 19:36 出处:网络
Let\'s say that I got 120 image files in my project. And I want to animate a sprite with all of them.

Let's say that I got 120 image files in my project. And I want to animate a sprite with all of them.

I was thinking about this method:

            CCSprite *temp = [CCSprite spriteWithFile:@"TheNextSprite.png"];
            [sprite setTexture:[temp texture]];

The above code will run like once every 0.03 seconds.

sprite is my animated CCS开发者_如何学Cprite. temp is simply a temporary CCSprite initialized with the image file for the next animation frame, so I can take its texture later.

Is that way efficient? I heard that I could use CCAnimate with a CCSpriteBatchNode, but this is only for one single sprite. Plus I got 120 (big) frames - they won't fit in a 2048x2048 texture canvas.


Have a look at the CCAnimation, CCAnimate and CCSpriteFrame classes.

Sprite frames are what you are trying to mimic, a 'piece' of a texture to which a sprite is mapped. They are best used when combined with spritesheets, not all of the sprites in the animation need to be in the same sprite sheet.

CCAnimation allows you to create an animation out of a sequence of such frames.

And CCAnimate allows you to run that animation as an action:

[node runAction:[CCAnimate actionWithAnimation:animationInstance restoreOriginal:NO]];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号