**************************************************
❤️游戏引擎
超大的第三方库,主要由四个关键因素:
①导演 Director
②场景 Scene
③图层 Layer
④精灵
一个导演有多个场景
同一个时间点 一个界面只有一个场景
一个场景有多个图层
一个图层有多个精灵
**************************************************
director->setOpenGLView(eglView);
相当于makeKeyvisible
一般在delegate中的写法是差不多的
**************************************************
❤️添加精灵步骤:
①创建精灵
Sprite::create("hero1.png")
②设置精灵的位置
Sprite->setPosition(
③将精灵添加到当前图层
this->addChild(
**************************************************
❤️刷新
设置刷新频率
director->setAnimationInterval(1.0 / 60);
令当前对象在每一帧刷新的时候
this->scheduleUpdate();
this->unscheduleUpdate();
**************************************************
❤️给精灵添加动作步骤:
①创建action
MoveTo* MoveTo::create(float duration, const Point& position)
②精灵调用方法运行action
Action * Node::runAction(Action* action)
③精灵停止action
void Node::stopAllActions()
**************************************************
❤️获取屏幕点击事件
EventListenerTouchOneByO
①创建一个点击事件监听器
EventListenerTouchOneByO
②创建监听响应函数
void EventListenerTouchOneByO
③添加监听响应函数
④添加监听器到当前图层
_eventDispatcher调用
void EventDispatcher::addEventListenerWithScen
※注意:要重写touch对应的方法
bool Layer::onTouchBegan(Touch *touch, Event *unused_event)
**************************************************
❤️常用类和方法
※class CC_DLL Size
※class CC_DLL Point
※typedef Point Vect;
这个vect重载了+-运算符
※class CC_DLL Node : public Object
※class CC_DLL Layer : public Node
void Node::onEnter()
Point Node::convertTouchToNodeSpace(Touch *touch) const
※class CC_DLL Sprite : public NodeRGBA, public TextureProtocol
Sprite* Sprite::create(const std::string& filename)
void Sprite::setPosition(const Point& pos)
void Sprite::addChild(Node* child)
const Point& Node::getPosition() const
void Node::removeFromParent()
void Node::setTag(int var)
※math.h
extern double fabs(double);
※class CC_DLL Array : public Object, public Clonable
long count() const
long Array::getIndexOfObject(Object* object) const
*****************************
❤️注意
※cocoas2D是MRC
所以要考虑内存泄露的问题
※原点在左下角