修复了Sprite的碰撞判断bug

This commit is contained in:
Nomango 2017-10-09 01:16:08 +08:00
parent 282fc1bc38
commit 3e31a3af55
3 changed files with 11 additions and 6 deletions

View File

@ -38,13 +38,15 @@ void BatchNode::_onDraw()
return; return;
} }
// 在相对位置绘制子节点
App::setOrigin(App::getOriginX() + getX(), App::getOriginY() + getY());
for (auto child : m_vChildren) for (auto child : m_vChildren)
{ {
// 将子节点移动到相对位置
child->move(getX(), getY());
// 绘制子节点
child->_onDraw(); child->_onDraw();
// 将子节点移回原位
child->move(-getX(), -getY());
} }
App::setOrigin(App::getOriginX() - getX(), App::getOriginY() - getY());
} }
void BatchNode::add(Node * child, int z_Order) void BatchNode::add(Node * child, int z_Order)

View File

@ -99,12 +99,15 @@ void BatchSprite::_onDraw()
} }
// 在相对位置绘制子节点 // 在相对位置绘制子节点
App::setOrigin(App::getOriginX() + getX(), App::getOriginY() + getY());
for (auto sprite : m_vSprites) for (auto sprite : m_vSprites)
{ {
// 将子节点移动到相对位置
sprite->move(getX(), getY());
// 绘制子节点
sprite->_onDraw(); sprite->_onDraw();
// 将子节点移回原位
sprite->move(-getX(), -getY());
} }
App::setOrigin(App::getOriginX() - getX(), App::getOriginY() - getY());
} }
Sprite * BatchSprite::isCollisionWith(Sprite * sprite) Sprite * BatchSprite::isCollisionWith(Sprite * sprite)

View File

@ -60,7 +60,7 @@ void Sprite::setImage(Image * image)
bool Sprite::isCollisionWith(Sprite * sprite) bool Sprite::isCollisionWith(Sprite * sprite)
{ {
return IntersectRect(NULL, &getRect(), &sprite->getRect()); return IntersectRect(new CRect(), &getRect(), &sprite->getRect());
} }
void Sprite::addAction(Action * action) void Sprite::addAction(Action * action)