From 3e31a3af55099c675f494f6f271b156f8095312e Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Mon, 9 Oct 2017 01:16:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86Sprite=E7=9A=84?= =?UTF-8?q?=E7=A2=B0=E6=92=9E=E5=88=A4=E6=96=ADbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Easy2D/Object/BatchNode.cpp | 8 +++++--- Easy2D/Object/BatchSprite.cpp | 7 +++++-- Easy2D/Object/Sprite.cpp | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Easy2D/Object/BatchNode.cpp b/Easy2D/Object/BatchNode.cpp index 316c40b8..1c05f832 100644 --- a/Easy2D/Object/BatchNode.cpp +++ b/Easy2D/Object/BatchNode.cpp @@ -38,13 +38,15 @@ void BatchNode::_onDraw() return; } - // 在相对位置绘制子节点 - App::setOrigin(App::getOriginX() + getX(), App::getOriginY() + getY()); for (auto child : m_vChildren) { + // 将子节点移动到相对位置 + child->move(getX(), getY()); + // 绘制子节点 child->_onDraw(); + // 将子节点移回原位 + child->move(-getX(), -getY()); } - App::setOrigin(App::getOriginX() - getX(), App::getOriginY() - getY()); } void BatchNode::add(Node * child, int z_Order) diff --git a/Easy2D/Object/BatchSprite.cpp b/Easy2D/Object/BatchSprite.cpp index 4170629d..cd36394e 100644 --- a/Easy2D/Object/BatchSprite.cpp +++ b/Easy2D/Object/BatchSprite.cpp @@ -99,12 +99,15 @@ void BatchSprite::_onDraw() } // 在相对位置绘制子节点 - App::setOrigin(App::getOriginX() + getX(), App::getOriginY() + getY()); for (auto sprite : m_vSprites) { + // 将子节点移动到相对位置 + sprite->move(getX(), getY()); + // 绘制子节点 sprite->_onDraw(); + // 将子节点移回原位 + sprite->move(-getX(), -getY()); } - App::setOrigin(App::getOriginX() - getX(), App::getOriginY() - getY()); } Sprite * BatchSprite::isCollisionWith(Sprite * sprite) diff --git a/Easy2D/Object/Sprite.cpp b/Easy2D/Object/Sprite.cpp index e2f59d23..0daf260d 100644 --- a/Easy2D/Object/Sprite.cpp +++ b/Easy2D/Object/Sprite.cpp @@ -60,7 +60,7 @@ void Sprite::setImage(Image * image) bool Sprite::isCollisionWith(Sprite * sprite) { - return IntersectRect(NULL, &getRect(), &sprite->getRect()); + return IntersectRect(new CRect(), &getRect(), &sprite->getRect()); } void Sprite::addAction(Action * action)