Last Update: 2010/07/14 20:43
前置
環境:
XCode 3.2.2
Cocos2d 0.99.4
準備工作:
連續圖片
步驟
新增Cocos2d專案
將圖片直接加入Resource
將 init 函式裡的 Code 用下列程式碼代換
滿淺顯易懂的, 就不說明了
if( (self=[super init] )) {
CCSprite *mySprite = [[CCSprite alloc] initWithFile:@"fox_0001.png"];
CCSprite *mySprite2 = [[CCSprite alloc] initWithFile:@"fox_0001.png"];
CCAnimation *walk = [[CCAnimation alloc] initWithName:@"walk" delay:0.1];
for(int i=1;i<=10;i++){
[walk addFrameWithFilename:[NSString stringWithFormat:@"fox_%04d.png", i]];
}
[mySprite addAnimation:walk];
[mySprite2 addAnimation:walk];
//[mySprite setDisplayFrame:@"walk" index:0];
//[mySprite setDisplayFrame:@"walk" index:1];
CCAction *action = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walk restoreOriginalFrame:NO]];
CCAction *action2 = [CCAnimate actionWithAnimation:walk restoreOriginalFrame:NO];
[mySprite runAction:action];
[mySprite2 runAction:action2];
mySprite.position = ccp(150,150);
mySprite2.position = ccp(300,150);
[self addChild:mySprite];
[self addChild:mySprite2];
}
return self;
沒有留言:
張貼留言