问题描述
我正在尝试检查2D数组中存储的形状是否存在碰撞。
我正在尝试在创建的Pacman克隆中使用逻辑。我检测两个Sprite之间的碰撞没有问题,但是我似乎无法用它来检测Pacman Sprite与矩形形状之间的碰撞。如何使精灵与数组中的任何矩形发生碰撞,以及如何检查与之碰撞的图块的值。谢谢!
const int rows = 28; //width
const int columns = 36; //height
int gridArray[rows][columns];
gridArray[6][3] = 1; //I want to check if the rectangle I collide with is = to 1,then do logic.
sf::RectangleShape grid1;
grid1.setFillColor(sf::Color::Transparent);
grid1.setoutlineColor(sf::Color::White);
grid1.setoutlineThickness(.5f);
grid1.setSize(sf::Vector2f(16,16)); //each square is 16 x 16
int positionx = -16;
int positiony = 0;
for (int i = 0; i < 28; i++)
{
positionx = positionx + 16;
positiony = 0;
for (int j = 0; j < 36; j++)
{
grid1.setPosition(positionx,positiony);
window.draw(grid1);
positiony = positiony + 16;
}
}
window.draw(pacman->pacMansprite);
if (pacman->pacMansprite.getGlobalBounds().intersects(grid1.getGlobalBounds())) //me attempting to detect collision of ANY rectangle.
{
pacman->canMove = false;
std::cout << "UGHGHGHGHG" << std::endl;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)