今、画面として Title、Gameがあるとすると。
最初の画面は
[[CCDirector sharedDirector] runWithScene: [Title scene]];
次の画面に行きたいときとは
[[CCDirector sharedDirector] replaceScene:[Game scene]];
CCSprite *player = [CCSprite spriteWithFile:@"6464.png"];
画面に追加する
[self addChild:player z:0 tag:1];
zは奥行き、tagの数値を使うと後で
CCSprite *player = (CCSprite *)[self getChildByTag:1];
とやって取り出せる。 位置はpotisionプロパティで指定、角度はrotationプロパティで指定
画面の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
が呼ばれるのでそこに書く。
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"];