看了一点官网的文档和教程,发现有几篇基础讲的挺好。把网址贴上来。
(怎么制作一个简单的游戏)
首先是一些概念的理解。
scene 里可以包含很多layer。
this 的指代,我觉得相当于一个类对象?
主要学了:
1. cocos2d-x的一些内存机制,为了避免内存泄漏,不在屏幕内的精灵应当removeChild()
2. tile 地图的一些基本用法
每个Tile都有自己的属性,可以拿到这些属性,实现不可走的区域,可拾取的物品,等
3 点击事件和键盘事件的监听
(1)要先创建一个事件监听器。
auto touchListener = EventListenerTouchOneByOne::create();
(2)重载相关的函数。
touchListener->onTouchBegan = [](Touch* t, Event* e)
{
return true;
};
onTouchBegan设置返回true ,接下来几个函数才会有用。
touchListener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
(3)事件分发
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener, this);
//重载 onTouchEnd(Touch*t,Event*e)
void onTouchEnded(Touch*t, Event*e);
//键盘监听
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 函数的使用
//函数名就是 void update(float dt)
scheduleUpdate();
this->schedule(schedule_selector(HelloWorld::updateMonster), 1.0f);