我目前使用的集合检测方法可以解释碰撞,但根据方向会产生奇怪的效果。它会:
这是当前的碰撞检测代码:
if(player.playerBounds.intersects(portal.bounds)&&player.isMovingLeft){
player.playerX=(portal.x+portal.width);
player.playerX++;
}
else if(player.playerBounds.intersects(portal.bounds)&&player.isMovingRight){
player.playerX=(portal.x-player.width);
player.playerX--;
}
else if(player.playerBounds.intersects(portal.bounds)&&player.isMovingUp){
player.playerY=(portal.y+portal.height);
player.playerY--;
}
else if(player.playerBounds.intersects(portal.bounds)&&player.isMovingDown){
player.playerY=(portal.y+player.height);
player.playerY++;
}
答案 0 :(得分:0)
您可以尝试以下代码并查看它是否有效吗?
bool collide = player.playerBounds.intersects(portal.bounds);
if(collide && player.isMovingLeft){
player.playerX = (portal.x + portal.width) + 1;
}
else if(collide && player.isMovingRight){
player.playerX = (portal.x - player.width) - 1;
}
else if(collide && player.isMovingUp){
player.playerY = (portal.y + portal.height) + 1;
}
else if(collide && player.isMovingDown){
player.playerY = (portal.y + player.height) - 1;
}
可能的原因可能是:
答案 1 :(得分:0)
在这里回答我自己的问题。方向移动的旗帜从未改变过真,这是问题的根源。一个方向是正常的,因为它排列着我通常会移动的第一个方向。