【发布时间】:2013-04-22 17:32:14
【问题描述】:
我正在尝试在 mario zechner 的框架 badlogicgames 上制作一个简单的游戏。我只是想放置一些瓷砖,比如说......树木,灌木等,并希望我的玩家在经过它们时停下来......以产生良好的效果......我尝试了很多替代方案......但没有奏效......
1.) 我试图定义一个布尔值playerBolcked = false; ...在碰撞检测循环中,我将其设置为 true .. 当它为 true 时 .. 我阻止了玩家移动 ..update();
2.) 我试图在检查碰撞之前存储玩家的位置..如果玩家与瓷砖碰撞... 然后我再次将位置重新设置...它也没有工作...
我的检测码是这样的……
private void checkTreeCollisions() {
int len = trees.size();
float x = allen.position.x;
float y =allen.position.y;
for (int i = 0; i < len; i++) {
Tree tree = trees.get(i);
if (OverlapTester.overlapRectangles(allen.bounds, tree.bounds)) {
// this is not working
allen.position.set(x, y);
break;
}
}
}
请给我一个好的方法...
【问题讨论】:
标签: java libgdx collision-detection collision