【发布时间】:2018-09-11 22:56:19
【问题描述】:
我正在制作 Frogger 的 C++ SFML 版本,目前正在尝试实现青蛙与其他物体(汽车、卡车、原木等)之间的碰撞检测。我对青蛙和游戏对象有单独的类,并希望使用边界框来检测交叉点,如下所示。
// get the bounding box of the entity
sf::FloatRect boundingBox = entity.getGlobalBounds();
// check collision with another box (like the bounding box of another
entity)
sf::FloatRect otherBox = ...;
if (boundingBox.intersects(otherBox))
{
// collision!
}
我遇到的问题是,我不知道如何使用来自不同类的两个精灵来完成这项工作,经过几天的搜索,我找不到如何做到这一点的解释。
【问题讨论】:
标签: c++ class collision sfml detection