Cocos2d-x実践講座~少人数で実際にアプリ作りを体験しよう~
株式会社TKS2 清水友晶
in 鹿児島
清水 友晶株式会社TKS2スマートフォンアプリ開発(iOS, Android, Windows Phone 8) Webコンテンツ開発Cocos2d-xへの開発参加Cocos2d-xを利用したアプリ開発講演活動執筆活動Twitter: tks2shimizuBlog: http://tks2.net/memoSlideShare: http://www.slideshare.net/doraemonsssFacebook: http://www.facebook.com/doraemonsss
2
目次ゲームの説明必要なクラスの説明ゲーム作成カードの配置カードのタップ時間表示ハイスコア表示ゲームのリトライ
3
ゲームの説明1から25まで順番にタップするカードゲーム今回の対象はiPhone4を想定iPhoneシミュレータではiPhone(Retina 3.5inch)
4
カードの配置に必要なクラスの説明CCSpriteクラス
create関数
setPosition関数
setTag関数
5
CCSprite* button = CCSprite::create("xxx.png");
button->setPosition(ccp(100,200));
button->setTag(10);
カードの配置に便利なクラスの説明CCStringクラス
create関数
createWithFormat関数
6
CCString* string = CCString::create("xxxxxx");
CCString* string = CCString::createWithFormat( "frontside%02d.png", 10);
カードのタップに必要なクラスの説明CCLayerクラス
setTouchEnabled関数
7
this->setTouchEnabled(true);this->setTouchMode(kCCTouchesOneByOne);
とすると、
カードのタップに必要なクラスの説明
タップ時に次のイベントが発生するccTouchBegan関数ccTouchMoved関数ccTouchEnded関数ccTouchCancelled関数
マルチタップは別の関数8
時間カウントに必要なクラスの説明CCNodeクラス
schedule関数
countTimer関数(関数名は任意)
9
this->schedule( schedule_selector( HelloWorld::countTimer));
voidHelloWorld::countTimer(float time) { gameTime += time;}
時間カウントに必要なクラスの説明CCNodeクラス
unschedule関数
10
this->unschedule( schedule_selector( HelloWorld::countTimer));
永続データに必要なクラスの説明CCUserDefaultクラス(シングルトン)
getFloatForKey関数
setFloatForKey関数flush関数
11
float hoge = CCUserDefault::sharedUserDefault()-> getFloatForKey("xxx", 0);
CCUserDefault::sharedUserDefault()-> setFloatForKey("xxx", 10.5f);CCUserDefault::sharedUserDefault()-> flush();
ボタンの作成に必要なクラスの説明CCMenuItemFontクラス
create関数
CCMenuクラス
12
CCMenuItemFont* item = CCMenuItemFont::create( "xxx", this, menu_selector(HelloWorld::yyy));
CCMenu* menu = CCMenu::create(item, NULL);menu->setPosition(CCPointZero);this->addChild(menu);
ゲームを作ってみよう!
まずはカードの配置
13
カードのダウンロードはhttp://tks2.net/other/cards.zip
ここまでのコードカードの配置https://gist.github.com/4239354
次はカードのタップ
14
カードのダウンロードはhttp://tks2.net/other/cards.zip
ここまでのコードカードのタップhttps://gist.github.com/4239351
次は時間表示
15
カードのダウンロードはhttp://tks2.net/other/cards.zip
ここまでのコード時間表示https://gist.github.com/4239350
次はハイスコア表示
16
カードのダウンロードはhttp://tks2.net/other/cards.zip
ここまでのコードハイスコア表示https://gist.github.com/4239338
次はゲームのリトライ
17
カードのダウンロードはhttp://tks2.net/other/cards.zip
できあがりのコード
できあがりhttps://gist.github.com/4238817
18
ありがとうございました
19