一次碰撞触发两次碰撞事件,两次都调用Scene::onCollision

This commit is contained in:
Nomango 2018-07-17 14:08:03 +08:00
parent be8972f52a
commit 85a4c0584a
3 changed files with 13 additions and 4 deletions

View File

@ -70,8 +70,14 @@ void e2d::CollisionManager::__updateCollider(Collider* collider)
if (relation != Collider::Relation::Unknown &&
relation != Collider::Relation::Disjoin)
{
active->onCollision(Collision(passive, relation));
passive->onCollision(Collision(active, relation));
// 触发两次碰撞事件
Collision activeCollision(passive, relation);
active->getParentScene()->onCollision(activeCollision);
active->onCollision(activeCollision);
Collision passiveCollision(active, passive->getCollider()->getRelationWith(active->getCollider()));
passive->getParentScene()->onCollision(passiveCollision);
passive->onCollision(passiveCollision);
}
}
}

View File

@ -149,7 +149,7 @@ void e2d::Node::_render()
// 转换渲染器的二维矩阵
Renderer::getInstance()->getRenderTarget()->SetTransform(_finalMatri);
// 渲染自身
//this->onRender();
this->onRender();
}
else
{
@ -174,7 +174,7 @@ void e2d::Node::_render()
// 转换渲染器的二维矩阵
Renderer::getInstance()->getRenderTarget()->SetTransform(_finalMatri);
// 渲染自身
//this->onRender();
this->onRender();
// 访问剩余节点
for (; i < _children.size(); ++i)

View File

@ -911,6 +911,9 @@ public:
// 说明:返回 false 将阻止消息继续传递
virtual bool onMouseEvent(MouseEvent e) { return true; }
// ÅöײÏûÏ¢
virtual void onCollision(Collision collision) { }
// 关闭窗口
// 说明:返回 false 将阻止窗口关闭
virtual bool onCloseWindow() { return true; }