画面はレイヤー(CCLayer)

今、画面として Title、Gameがあるとすると。

最初の画面は

[[CCDirector sharedDirector] runWithScene: [Title scene]];

次の画面に行きたいときとは

 [[CCDirector sharedDirector] replaceScene:[Game scene]];

   

登場人物はスプライト(CCSprite)

CCSprite *player = [CCSprite spriteWithFile:@"6464.png"];

  画面に追加する

[self addChild:player z:0 tag:1];

zは奥行き、tagの数値を使うと後で

 CCSprite *player  = (CCSprite *)[self getChildByTag:1];

とやって取り出せる。   位置はpotisionプロパティで指定、角度はrotationプロパティで指定  

画面(CCLayer)も登場人物(CCSprite)もノード(CCNode)を継承している。

画面のタッチ検知

画面のisTouchEnabledプロパティをYESにして

- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

等でキャッチできる。座標は

   UITouch *touch = [touches anyObject];
   CGPoint point = [touch locationInView:[touch view]];

で取得する。

フレーム毎の処理

 [self scheduleUpdate];

- (void)update:(ccTime)delta

が呼ばれるのでそこに書く。

スプライト(やLayer)を動かしたい(アクション)

3秒間かけて(100,100)まで動かしたいとして

CCMoveTo *move = [CCMoveTo actionWithDuration:3 position:CGPointMake(100, 100)];
[mySprite runAction:move];

回転させたければCCRotationBy

繰り返したい時は

CCRepeatForever *repeat = [CCRepeatForever actionWithAction:move];
[mySprite runAction:repeat];

音楽を鳴らしたい時は

SimpleAudioEngine.hをインポートしておいて

   [[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"test.mp3"];

効果音を鳴らしたい時は

    [[SimpleAudioEngine sharedEngine] playEffect:@"test.caf"];

最終更新:2011年09月19日 16:30