今日のテーマ
【サンプルコードの書き換え】
参照しているサンプルが2010とかで
cocos2dとしても大分古いので、コピーしながら
2013年版に変更しました。
【本日の前提】
今後、昔のサンプルコードを使用する場合があると思います。
そのため似たようなコードが出てきたときに、いちいちネットで検索せず
自分のサイトで見つけられるようにメモを残します。
まずは必要そうなclassファイルと
画像ファイルをコピーして、トライ&エラー開始!
変更点1
|
1 2 3 4 5 |
//元 CCSpriteSheet * sSheet = [CCSpriteSheet spriteSheetWithFile:@"Sheet.png"]; //書き換え CCSpriteBatchNode *sSheet = [CCSpriteBatchNode batchNodeWithFile:@"Sheet.png" capacity:100]; |
変更点2
|
1 2 3 4 5 6 7 |
//そのまま bar = [CCSprite spriteWithFile:@"bar.png"]; //元 [self addChild:bar]; //書き換え [self addChild:bar z:0 tag:0]; |
変更点3
|
1 2 3 4 5 6 7 8 |
//元 animation = [CCAnimation animationWithName:@"fBlue" delay:0.1f frames:theGame.blueFrames]; //書き換え animation = [CCAnimation animationWithSpriteFrames:theGame.blueFrames delay:0.1f]; //そのまま [self.mySprite runAction:[CCRepeatForever actionWithAction: [CCSequence actions:[CCDelayTime actionWithDuration:arc4random()%5],[CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO],nil] ]]; |
こんな感じ。その他ラベルの使い方が分からない場所があったので
”/* .. */”で華麗にスルーw
処理に直接関係ないのでこれはいいでしょう。
以外と移行に時間がかからなくてびっくり。
後はこれに対して変更加えてテストを実施し
コアな部分を理解できたら
分解して、組み立て直してゲームにしよう。

日曜日なので遅めですが、ブログ書きました// 【サンプルコードの書き換え】アプリ開発日記(7/14): http://t.co/mznGvFZCak