Sprite Animations Without Sprite Sheets

By | April 7, 2012

You can simulate any animations if you have a sequence of images which makes the illusion of that
animations and rendering those images to the screen. In cocos2D it can be done in two ways, with sprite sheet
animation and without sprite sheets. Here we are going to see how it can be done with out sprite sheet.

CCAnimation *sitDown = [CCAnimation animationWithName:@"sitDown" delay:0.1f];

[sitDown addFrameWithFilename:@"sit1.png"];
[sitDown addFrameWithFilename:@"sit2.png"];

[mySprite addAnimation:sitDown];

id sitAction = [CCAnimate actionWithAnimation:sitDown restoreOriginalFrame:YES];

[yourSprite runAction:sitAction];

Here CCAnimation holds a series of images known as Frames and CCAnimate is simply the action which will run the
CCAnimation. Simple.

Suppose that we have two images named, sit1.png and sit2.png which simulates a sitting animation of our sprite. First
we have added that images/frames to our CCAnimation object sitDown. Then we CCAnimate our CCAnimation frames and
deploy those actions to our sprite. We can set the delay time between the individual frames in CCAnimation. Also we can restore the original image before sprite animation after animatin completes or not!That’s it.

We will later see in here how Sprite Animations can be done by using Sprite Sheets. Keep in touch.


Leave a Reply

Your email address will not be published. Required fields are marked *