Upload
toshio-ehara
View
14.647
Download
0
Embed Size (px)
DESCRIPTION
2013年4月21日福岡市西区プログラミング勉強会(福岡県福岡市西区で開催)で発表した資料です。ご参考になれば幸いです。
Citation preview
�/#/2�$�7�£�ěĀ»Ě���
ħĥĦĨÛĩòħĦëăħÍďÆ� ���Ãܯ
�|¡�dmOQO���~vµýOT\ĠC\FqiRġ(330���666�&/.3.!�#/-�",/'�����
13年4月22日月曜日
ċÙƬ
13年4月22日月曜日
36)33%1������)3/+!-)��
Fíc©d���� �������!5!�#1)03]R>ôÅËK�%"x��´Z\iR>� ¡�Ģþğ¸ģH�z¡]R>
F©HBseìĞ_DVġġ
ñė=�/#/2�$�7]Ò¶ËK���|x��v´q¿QiQW>
13年4月22日月曜日
)�(/.%ËKx��Õ°
(330���666�)3/+!-)���#/-�2/&3��]���v½ěQ\CiR>ČGZWp_DVA>
13年4月22日月曜日
^Mt]·ª]���|�£�v´tDġ^áD^
13年4月22日月曜日
Ctw`ěĀûÏvĐE`C^
CK`C]Rob>>
�!5!� �"*%#3)5%���
���
13年4月22日月曜日
©GpÚZ\Ö]Rrad
îĜHĖq`C���/19
13年4月22日月曜日
ī_mĤUM]�/#/2�$�7]Rġ
`w^Ħ�£�])����.$1/)$§×àġ
(windows phoneもいけるみたいですけど未検証。。)
13年4月22日月曜日
Õ°?Dzºü@´qiQWA>
�/#/2�$�7cFGL]ÚÓÞcØ`CîĜ]Ác)�(/.%^�.$1/)$§×à]IiQW>
13年4月22日月曜日
ñÁ³RrcĪ
13年4月22日月曜日
�/#/2�$�7c�z�Gp�{¡ £�ġ(330���666�#/#/2�$�7�/1'
ごめんなさい…今日は環境構築は省略します。«ÍcĔédYnZ^Âaz¡��£�QW#/#/2�$���"%3!��7����vµZ\iR>
13年4月22日月曜日
#/$%�)���^�#,)02%��.$1/)$�c�ûÏõąd
:HFirěĀ� �:H^Z\kÀGqmRC]Rġ
(330���'!/-!1�",/'�&#��#/-�",/'�%.318���(3-,
13年4月22日月曜日
_w`´q`cĪ
13年4月22日月曜日
Director
iS¼\vĄúRr�)1%#3/1HCiR
Fsd�¡���¡XVA
13年4月22日月曜日
Director
�£�OiMwYuA
�)1%#3/1d=ßS�#%.%v¤[´iR
ñÁcÎğv_£Vġ
BssiX³kĎĂOs\C`C¢¢
13年4月22日月曜日
�#%.%d�!8%1våZ\CiR>
BssiX³kĎĂOs\C`C¢¢
13年4月22日月曜日
Ċïm}��~�þ¹d�01)3%^ĒCiR>
�!8%1c¥acTiR>
ĤMwYuAī
MsH�01)3%
F=þğaĎĂOsWġ
13年4月22日月曜日
Dggæ´QYlDoA
æ´v�!8%1HÉK®KiR>
Ĥæ´ÝZ\iRAī
�£�Oi
13年4月22日月曜日
�£�y¡�dĪ
13年4月22日月曜日
x���£��¡HĕÄRr^ñÁa�00�%,%'!3%�#00c
!00,)#!3)/.�)$�).)2(�!4.#().'HÌesiR>
13年4月22日月曜日
bool AppDelegate::applicationDidFinishLaunching(){ // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
// turn on display FPS pDirector->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60);
// create a scene. it's an autorelease object CCScene *pScene = MenuScene::scene();
// run pDirector->runWithScene(pScene);
return true;}
�00�%,%'!3%��!00,)#!3)/.�)$�).)2(�!4.#().'c¨]���)1%#3/1vÌf¿Q\ēÔvčCiR>Ģ«ÍdøaÐðQ\iTw>ģ
CCDirectorシングルトンを取得します。頭にCocos2dを示す”CC”が付きます!
13年4月22日月曜日
bool AppDelegate::applicationDidFinishLaunching(){ // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
// turn on display FPS pDirector->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60);
// create a scene. it's an autorelease object CCScene *pScene = MenuScene::scene();
// run pDirector->runWithScene(pScene);
return true;}
���)1%#3/1d���#%.%vĕÄQiR>
最初のシーンを起動!
13年4月22日月曜日
bool AppDelegate::applicationDidFinishLaunching(){ ・・・省略・・・ CCScene *pScene = MenuScene::scene(); ・・・省略・・・
���#%.%üâîa�!8%1vĘĉQiR>
シーン生成
CCScene* MenuScene::scene(){ // 'scene' is an autorelease object CCScene *scene = CCScene::create(); // 'layer' is an autorelease object MenuLayer *layer = MenuLayer::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene;} レイヤーを配置
�%.4�#%.%d���#%.%vĈäQ\´Z\iRġ
13年4月22日月曜日
�/#/2�$�7]dz¡��¡�üâîa).)3ĝèvÌh©HÑCjWC]R>³XG�"*%#3)5%��c�£�a±\iR>
CCScene *CCScene::create(){ CCScene *pRet = new CCScene(); if (pRet && pRet->init()) { pRet->autorelease(); return pRet; } else { CC_SAFE_DELETE(pRet); return NULL; }}
initを呼ぶルール
!43/1%,%!2%d=Þ]���đçRrćjjWC]R>
13年4月22日月曜日
���!8%1c).)3ĝè]���01)3%vüâQ=���!8%1¥aĘĉQ\jiR>
bool MenuLayer::init(){ // super init を最初に呼びます~ if ( !CCLayer::init() ){ return false; } // このレイヤーにスプライトを追加します this->addSprites(); return true;}
void MenuLayer::addSprites(){ // まず画面サイズを ディレクターに聞いて CCSize size = CCDirector::sharedDirector()->getWinSize(); // 猫のスプライト CCSprite* cat = CCSprite::create("cat.png"); cat->setPosition( ccp(size.width/2, size.height/2)); this->addChild(cat, 0);
}
画像ファイル名を指定で作れます
13年4月22日月曜日
ÄGQ\jiQnDA>
13年4月22日月曜日
class MenuLayer : public cocos2d::CCLayer{public: virtual bool init(); CREATE_FUNC(MenuLayer); virtual bool ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent); virtual void ccTouchMoved(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent); virtual void ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent); virtual void ccTouchCancelled(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent); private: void addSprites();};
���!8%1a���z�¡�āęê÷Ħ
タッチイベントを使う場合はヘッダで宣言する
13年4月22日月曜日
#include "SimpleAudioEngine.h"#include "MenuLayer.h"
using namespace cocos2d;using namespace CocosDenshion;
bool MenuLayer::init(){ // super init を最初に呼びます~ if ( !CCLayer::init() ){ return false; } // このレイヤーにスプライトを追加します this->addSprites(); // レイヤーのタッチイベント監視を開始します this->setTouchMode(kCCTouchesOneByOne); this->setTouchEnabled(true); return true;}
���!8%1c���z�¡�āęê÷ħ
初期化処理でタッチを有効化
13年4月22日月曜日
bool MenuLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent){ CCLog("ccTouchBegan"); return true; // タッチイベントを開始}
void MenuLayer::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent){ CCLog("ccTouchMoved");}
void MenuLayer::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent){ CCLog("ccTouchEnded"); }
void MenuLayer::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent){ CCLog("ccTouchCancelled");}
���!8%1c���z�¡�āęê÷Ĩ
���]ÕĒQWĝè]z�¡�¾úHÄJöa`qiR>
ログを出す関数
13年4月22日月曜日
ñÞa���îaùc���z�H��¡�Rrãv´Z\jiQnDA>
this->addChild(cat, 0, 0);
ùc���z�v�!8%1�MM]d3()2�aāęîÈq¿Tröa��v[KrM^H¿óiR>;<¤ÿÊcH��]R>
Þ]¦coDa�!8%1��MM]d3()2��GpÈq¿TiR>
CCSprite* cat = (CCSprite*)this->getChildByTag(0);
13年4月22日月曜日
���îaùcx��£��¡v»siQW>
bool MenuLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent){
CCPoint location = pTouch->getLocation();
float animationTime = 1.0, jumpHeight=100, jumpNum =1; float scale = 6.0;
CCSpawn* spawn = CCSpawn::create( CCJumpTo::create( animationTime, location, jumpHeight, jumpNum ), CCScaleTo::create( animationTime, scale ), NULL);
CCSprite* cat = (CCSprite*)this->getChildByTag(0); cat->runAction( spawn );
return true; // タッチイベントを開始}
タップ時の座標
猫のアニメーション設定
アニメーション実行
13年4月22日月曜日
ùcx��£��¡��
13年4月22日月曜日
FQiCA<BqH^DNPCiQW<A
13年4月22日月曜日