B. 在 HelloWorldScene.m:
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init] )) {
....
// 從左上角往右下角切割圖檔
//CCSprite *sprite = [CCSprite spriteWithFile:@"Icon.png" rect:CGRectMake(20, 20, 57, 57)];
CCSprite *sprite = [CCSprite spriteWithFile:@"Icon.png"]; // source size
sprite.position = ccp(240, 50);
/* 動畫效果: case01 -> normal */
id action = // (1). CCJumpTo: 跳躍至絕對座標
// [CCJumpTo actionWithDuration:2 position:ccp(300,0) height:50 jumps:4]; // -> 300, 0
// (2). CCJumpBy: 跳躍至相對座標(以原始座標累加距離的跳躍)
// [CCJumpBy actionWithDuration:2 position:ccp(300,0) height:50 jumps:4]; // -> 540, 50
// (3). CCRotateTo: 旋轉
// [CCRotateTo actionWithDuration:2 angle:180];
// (4). 淡入
// [CCFadeIn actionWithDuration:2];
// (5). 淡出
// [CCFadeOut actionWithDuration:2];
// (6). 移至絕對座標
// [CCMoveTo actionWithDuration:2 position: ccp(100, 100)];
// (7). 移至相對座標
// [CCMoveBy actionWithDuration:2 position: ccp(100, 100)]; // 340, 150
// 混合動作
// (8). CCSequence: one by one (連續動作)
[CCSequence actions:
// [CCRotateTo actionWithDuration:2 angle:180], // ---> error with reverse happend?
[CCRotateBy actionWithDuration:2 angle:180],
[CCJumpBy actionWithDuration:2 position:ccp(300,0) height:50 jumps:4],
[CCFadeOut actionWithDuration:2],
[CCCallFunc actionWithTarget:self selector:@selector(callback1)],
nil];
// 混合動作
// (9). CCSpawn: do it the sametime (同時動作)
/*
[CCSpawn actions:
[CCRotateTo actionWithDuration:2 angle:180], // ---> error with reverse happend?
[CCRotateBy actionWithDuration:2 angle:180],
[CCJumpBy actionWithDuration:2 position:ccp(300,0) height:50 jumps:4],
[CCFadeOut actionWithDuration:2],
[CCCallFunc actionWithTarget:self selector:@selector(callback1)],
nil];
*/
/* 動畫效果: case02 -> repeat */
// (10). CCRepeatForever: 無限重複執行
// CCRepeatForever *repeat = [CCRepeatForever actionWithAction:action];
// (11). CCRepeat: 重複執行
// CCRepeat *repeat = [CCRepeat actionWithAction:action times:2];
/* 動畫效果: case03 -> reverse */
// (12). reverse: 反向執行
// id t_reverse = [CCSequence actions:action, [action reverse], nil];
// runAction
// case 1: for normal
[sprite runAction:action];
// case 2: for repeat
// [sprite runAction:repeat];
// case 3: for reverse
// [sprite runAction:t_reverse];
[self addChild: sprite];
}
return self;
}
- (void) callback1
{
CCLabel *labelEnd = [CCLabel labelWithString:@"Game Over" fontName:@"Marker Felt" fontSize:64];
CGSize size = [[CCDirector sharedDirector] winSize];
// position the label on the center of the screen
labelEnd.position = ccp( size.width /2 , size.height/2 - 100 );
[self addChild: labelEnd];
}
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。