看了一點(diǎn)官網(wǎng)的文檔和教程,發(fā)現(xiàn)有幾篇基礎(chǔ)講的挺好。把網(wǎng)址貼上來。
(怎么制作一個(gè)簡(jiǎn)單的游戲)
(怎么制作一個(gè)基于TileMap 的函數(shù))
首先是一些概念的理解。
scene 里可以包含很多l(xiāng)ayer。
this 的指代,我覺得相當(dāng)于一個(gè)類對(duì)象?
主要學(xué)了:
1. cocos2d-x的一些內(nèi)存機(jī)制,為了避免內(nèi)存泄漏,不在屏幕內(nèi)的精靈應(yīng)當(dāng)removeChild()
2. tile 地圖的一些基本用法
每個(gè)Tile都有自己的屬性,可以拿到這些屬性,實(shí)現(xiàn)不可走的區(qū)域,可拾取的物品,等
3 點(diǎn)擊事件和鍵盤事件的監(jiān)聽
(1)要先創(chuàng)建一個(gè)事件監(jiān)聽器。
auto touchListener = EventListenerTouchOneByOne::create();
(2)重載相關(guān)的函數(shù)。
touchListener->onTouchBegan = [](Touch* t, Event* e)
{
return true;
};
onTouchBegan設(shè)置返回true ,接下來幾個(gè)函數(shù)才會(huì)有用。
touchListener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
(3)事件分發(fā)
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener, this);
//重載 onTouchEnd(Touch*t,Event*e)
void onTouchEnded(Touch*t, Event*e);
//鍵盤監(jiān)聽
auto keyListener = EventListenerKeyboard::create();
keyListener->onKeyPressed = CC_CALLBACK_2(HelloWorld::onKeyPressed, this);
keyListener->onKeyReleased = CC_CALLBACK_2(HelloWorld::onKeyReleased, this);
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(keyListener, this);
void onKeyPressed(EventKeyboard::KeyCode keyCode, Event* e);
void onKeyReleased(EventKeyboard::KeyCode keyCode, Event*e);
4. schedule 函數(shù)的使用
//函數(shù)名就是 void update(float dt)
scheduleUpdate();
this->schedule(schedule_selector(HelloWorld::updateMonster), 1.0f);