にしあぷ

札幌在住のエンジニア。コンサドーレ、甘いもの、ドット絵が好き。

Chapter 2. Playing with Sprites(スプライトで遊ぶ)

Cocos2d for Iphone 0.99 Beginner's Guide

Cocos2d for Iphone 0.99 Beginner's Guide

  • Make use of sprites
  • Learn how to change properties of sprites
  • Create sprites using Spritesheets with the CCSpriteBatchNode class
  • Implement touches on sprites
  • Use OpenGL calls
  • スプライトを使う
  • スプライトのプロパティを変更
  • スプライトシートでスプライトを生成(CCSpriteBatchNodeクラス)
  • スプライトのタッチ処理
  • OpenGLの関数を使う

creating a new project (P.38)

新規プロジェクトの作成
f:id:tmuramoto:20121228135618p:plain

adding a background image to the game (P.41)

ゲームの背景画像を追加
f:id:tmuramoto:20121228140559p:plain

        CCSprite* background = [CCSprite spriteWithFile:@"background.png"];
        [self addChild:background z:0];
        [background setPosition:ccp(240, 160)];

creating the Stone class (P.44)

Stoneクラスの作成

@interface Stone : CCNode <CCTargetedTouchDelegate>
{
    CCSprite* mySprite;
    GameLayer* theGame;
    int stoneType;
    int curVGroup;
    int curHGroup;
    touchState state;
    BOOL disappearing;
    CGPoint initDir;
}

placing stones in the grid (P.49)

マス目にストーンを配置
f:id:tmuramoto:20121229105711p:plain

registering the stones for receiving touches (P.54)

(ストーンが)タッチを受け取る

-(void)onExit
{
    [[[CCDirector sharedDirector] touchDispatcher] removeDelegate:self];
    [super onExit];
}

handling touches for swapping stones (P.55)

ストーン交換のためのタッチ処理

canceling the swap (P.58)

交換のキャンセル(指があまり動かなかった時は交換しない):ccpDistance メソッド

swapping the stones around (P.59)

ストーンを交換する
左上のストーンをフリック操作で交換。
f:id:tmuramoto:20121230142602p:plain
f:id:tmuramoto:20121230142606p:plain

doing more with the CCTouchDispatcher (P.62)

フリックではなく、タッチ操作での交換

checking for matches (P.62)

揃っているかチェックする
3つ以上ストーンが揃うと消える(右中段)
f:id:tmuramoto:20121230150043p:plain
f:id:tmuramoto:20121230150051p:plain

refilling the grid (P.68)

マス目にストーンを補充する

making a time bar (P.74)

タイムバーを作る
f:id:tmuramoto:20130106172356p:plain

changing textures on the fly (P.77)

テキスチャを変更する
f:id:tmuramoto:20130106172410p:plain

creating sprites from Spritesheets (P.81)

スプライトシートからスプライトを作る

changing the rest of the elements (P.85)

ストーン以外の画像も、スプライトシートから読み込む(colouredSheet.plist を参照)
GameScene.h > -(id) init

        CCSprite *background = [CCSprite spriteWithTexture:sSheet.texture rect:CGRectMake(504, 1, 480, 320)];
		[self addChild:background z:0];

creating more colored stones with Spritesheets (P.86)

Zwoptex
http://www.zwopple.com/zwoptex/

preloading your images (P.89)

画像をプリロードしておく

selecting a stone for swapping (P.90)

交換するストーンを選択する(OpenGLの関数を呼ぶ)
f:id:tmuramoto:20130108095700p:plain

Cocos2d for Iphone 0.99 Beginner's Guide

Cocos2d for Iphone 0.99 Beginner's Guide