Created
November 24, 2010 04:51
-
-
Save ecpplus/713131 to your computer and use it in GitHub Desktop.
Cocos2d(0.99.4) create animation by CCSpriteSheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CCSpriteSheet *animationSheet = [CCSpriteSheet spriteSheetWithFile:@"animation_sheet.png"]; | |
[self addChild:animationSheet]; | |
CCSprite *animationSprite = [CCSprite spriteWithTexture:animationSheet.texture | |
rect:CGRectMake(0, 0, 256, 290)]; | |
animationSprite.position = ccp(self.contentSize.width / 2, self.contentSize.height / 2); | |
[animationSheet addChild:animationSprite]; | |
CCAnimation *animation = [CCAnimation animationWithName:@"an_animation" delay:0.04f]; | |
// this example is.. | |
// per frame : width -> 256, height -> 128, | |
// sheet size : 640 x 768 | |
// 15 frames | |
for (int i = 0; i < 14; i++) { | |
CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:animationSheet.texture | |
rect:CGRectMake((int)(i / 5) * 256, (int)(i % 5) * 128, 256, 128) | |
offset:ccp(0,0)]; | |
[animation addFrame:frame]; | |
} | |
CCAnimate *anime = [CCAnimate actionWithAnimation:animation]; | |
id delaying = [CCDelayTime actionWithDuration:1.5f]; | |
id sequence = [CCSequence actions:anime, delaying, nil]; | |
CCRepeatForever *repeat = [CCRepeatForever actionWithAction:sequence]; | |
[animationSprite runAction:repeat]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment