消息处理方式更新
This commit is contained in:
parent
bdbe00e228
commit
61b384767e
|
|
@ -3,8 +3,7 @@
|
|||
#include "..\e2dmanager.h"
|
||||
|
||||
e2d::Scene::Scene()
|
||||
: _autoUpdate(true)
|
||||
, _root(nullptr)
|
||||
: _root(nullptr)
|
||||
{
|
||||
_root = new (e2d::autorelease) Node();
|
||||
_root->retain();
|
||||
|
|
@ -37,16 +36,13 @@ void e2d::Scene::render()
|
|||
|
||||
void e2d::Scene::update()
|
||||
{
|
||||
if (_autoUpdate)
|
||||
{
|
||||
onUpdate();
|
||||
}
|
||||
this->onUpdate();
|
||||
_root->_update();
|
||||
}
|
||||
|
||||
void e2d::Scene::dispatch(const MouseEvent & e)
|
||||
{
|
||||
if (onMouseEvent(e))
|
||||
if (onEvent(e))
|
||||
return;
|
||||
|
||||
_root->dispatch(e);
|
||||
|
|
@ -54,17 +50,12 @@ void e2d::Scene::dispatch(const MouseEvent & e)
|
|||
|
||||
void e2d::Scene::dispatch(const KeyEvent & e)
|
||||
{
|
||||
if (onKeyEvent(e))
|
||||
if (onEvent(e))
|
||||
return;
|
||||
|
||||
_root->dispatch(e);
|
||||
}
|
||||
|
||||
void e2d::Scene::setAutoUpdate(bool bAutoUpdate)
|
||||
{
|
||||
_autoUpdate = bAutoUpdate;
|
||||
}
|
||||
|
||||
void e2d::Scene::add(Node * child, int order /* = 0 */)
|
||||
{
|
||||
_root->addChild(child, order);
|
||||
|
|
|
|||
|
|
@ -77,12 +77,12 @@ void e2d::CollisionManager::__updateCollider(Collider* collider)
|
|||
auto passiveNode = passive->getNode();
|
||||
// 触发两次碰撞事件
|
||||
Collision activeCollision(passiveNode, relation);
|
||||
activeNode->getParentScene()->onCollision(activeCollision);
|
||||
activeNode->onCollision(activeCollision);
|
||||
activeNode->getParentScene()->onEvent(activeCollision);
|
||||
activeNode->onEvent(activeCollision);
|
||||
|
||||
Collision passiveCollision(activeNode, passive->getRelationWith(collider));
|
||||
passiveNode->getParentScene()->onCollision(passiveCollision);
|
||||
passiveNode->onCollision(passiveCollision);
|
||||
passiveNode->getParentScene()->onEvent(passiveCollision);
|
||||
passiveNode->onEvent(passiveCollision);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,6 @@ e2d::Node::Node()
|
|||
, _clipEnabled(false)
|
||||
, _needSort(false)
|
||||
, _needTransform(false)
|
||||
, _autoUpdate(true)
|
||||
, _positionFixed(false)
|
||||
, _collider(this)
|
||||
, _extrapolate(Property::Origin)
|
||||
|
|
@ -127,7 +126,7 @@ void e2d::Node::_updateSelf()
|
|||
}
|
||||
}
|
||||
|
||||
if (_autoUpdate && !Game::getInstance()->isPaused())
|
||||
if (!Game::getInstance()->isPaused())
|
||||
{
|
||||
this->onUpdate();
|
||||
}
|
||||
|
|
@ -278,12 +277,17 @@ bool e2d::Node::dispatch(const MouseEvent & e)
|
|||
{
|
||||
if (_visible)
|
||||
{
|
||||
if (onMouseEvent(e))
|
||||
if (onEvent(e))
|
||||
return true;
|
||||
|
||||
for (auto iter = _children.rbegin(); iter != _children.rend(); ++iter)
|
||||
if ((*iter)->dispatch(e))
|
||||
for (size_t i = _children.size(); i >= 0 && i < _children.size(); --i)
|
||||
{
|
||||
if (_children[i]->dispatch(e))
|
||||
return true;
|
||||
|
||||
if (i == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -293,12 +297,17 @@ bool e2d::Node::dispatch(const KeyEvent & e)
|
|||
{
|
||||
if (_visible)
|
||||
{
|
||||
if (onKeyEvent(e))
|
||||
if (onEvent(e))
|
||||
return true;
|
||||
|
||||
for (auto iter = _children.rbegin(); iter != _children.rend(); ++iter)
|
||||
if ((*iter)->dispatch(e))
|
||||
for (size_t i = _children.size(); i >= 0 && i < _children.size(); --i)
|
||||
{
|
||||
if (_children[i]->dispatch(e))
|
||||
return true;
|
||||
|
||||
if (i == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -957,11 +966,6 @@ bool e2d::Node::intersects(Node * node)
|
|||
relation != D2D1_GEOMETRY_RELATION_DISJOINT;
|
||||
}
|
||||
|
||||
void e2d::Node::setAutoUpdate(bool bAutoUpdate)
|
||||
{
|
||||
_autoUpdate = bAutoUpdate;
|
||||
}
|
||||
|
||||
void e2d::Node::resumeAllActions()
|
||||
{
|
||||
ActionManager::getInstance()->resumeAllBindedWith(this);
|
||||
|
|
|
|||
|
|
@ -984,14 +984,14 @@ public:
|
|||
|
||||
// 按键消息
|
||||
// 说明:返回 true 将阻止消息继续传递
|
||||
virtual bool onKeyEvent(KeyEvent e) { return false; }
|
||||
virtual bool onEvent(KeyEvent e) { return false; }
|
||||
|
||||
// 鼠标消息
|
||||
// 说明:返回 true 将阻止消息继续传递
|
||||
virtual bool onMouseEvent(MouseEvent e) { return false; }
|
||||
virtual bool onEvent(MouseEvent e) { return false; }
|
||||
|
||||
// 碰撞消息
|
||||
virtual void onCollision(Collision collision) { }
|
||||
virtual void onEvent(Collision collision) { }
|
||||
|
||||
// 关闭窗口
|
||||
// 说明:返回 false 将阻止窗口关闭
|
||||
|
|
@ -1000,11 +1000,6 @@ public:
|
|||
// 重写这个函数,它将在每一帧画面刷新时执行
|
||||
virtual void onUpdate() {}
|
||||
|
||||
// 开启或禁用 onUpdate 函数
|
||||
void setAutoUpdate(
|
||||
bool bAutoUpdate
|
||||
);
|
||||
|
||||
// 添加节点到场景
|
||||
void add(
|
||||
Node * child, /* 要添加的节点 */
|
||||
|
|
@ -1058,7 +1053,6 @@ protected:
|
|||
E2D_DISABLE_COPY(Scene);
|
||||
|
||||
protected:
|
||||
bool _autoUpdate;
|
||||
Node * _root;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -54,14 +54,14 @@ public:
|
|||
|
||||
// 按键消息
|
||||
// 说明:返回 true 将阻止消息向下传递
|
||||
virtual bool onKeyEvent(KeyEvent e) { return false; }
|
||||
virtual bool onEvent(KeyEvent e) { return false; }
|
||||
|
||||
// 鼠标消息
|
||||
// 说明:返回 true 将阻止消息向下传递
|
||||
virtual bool onMouseEvent(MouseEvent e) { return false; }
|
||||
virtual bool onEvent(MouseEvent e) { return false; }
|
||||
|
||||
// 碰撞消息
|
||||
virtual void onCollision(Collision collision) { }
|
||||
virtual void onEvent(Collision collision) { }
|
||||
|
||||
// 获取节点显示状态
|
||||
virtual bool isVisible() const;
|
||||
|
|
@ -188,11 +188,6 @@ public:
|
|||
bool value
|
||||
);
|
||||
|
||||
// 开启或禁用 onUpdate 函数
|
||||
void setAutoUpdate(
|
||||
bool bAutoUpdate
|
||||
);
|
||||
|
||||
// 设置节点名称
|
||||
void setName(
|
||||
const String& name
|
||||
|
|
@ -458,7 +453,6 @@ protected:
|
|||
float _pivotY;
|
||||
int _order;
|
||||
bool _visible;
|
||||
bool _autoUpdate;
|
||||
bool _clipEnabled;
|
||||
bool _needSort;
|
||||
bool _needTransform;
|
||||
|
|
|
|||
Loading…
Reference in New Issue