From 85a4c0584a20474bbf04bf5407ca641e7a483548 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Tue, 17 Jul 2018 14:08:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E6=AC=A1=E7=A2=B0=E6=92=9E=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E4=B8=A4=E6=AC=A1=E7=A2=B0=E6=92=9E=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E4=B8=A4=E6=AC=A1=E9=83=BD=E8=B0=83=E7=94=A8Scene::on?= =?UTF-8?q?Collision?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Manager/CollisionManager.cpp | 10 ++++++++-- core/Node/Node.cpp | 4 ++-- core/e2dcommon.h | 3 +++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/core/Manager/CollisionManager.cpp b/core/Manager/CollisionManager.cpp index 08c5ffce..bca87b15 100644 --- a/core/Manager/CollisionManager.cpp +++ b/core/Manager/CollisionManager.cpp @@ -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); } } } diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index 661ee7d9..29bed8c6 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -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) diff --git a/core/e2dcommon.h b/core/e2dcommon.h index c07a9f00..98690f0b 100644 --- a/core/e2dcommon.h +++ b/core/e2dcommon.h @@ -911,6 +911,9 @@ public: // 说明:返回 false 将阻止消息继续传递 virtual bool onMouseEvent(MouseEvent e) { return true; } + // 碰撞消息 + virtual void onCollision(Collision collision) { } + // 关闭窗口 // 说明:返回 false 将阻止窗口关闭 virtual bool onCloseWindow() { return true; }