【发布时间】:2015-05-03 15:07:03
【问题描述】:
我正在尝试创建一个环绕方法来使屏幕每一侧的精灵反弹。我的底部和右侧都在工作,但似乎无法弄清楚为什么它不会离开顶部或左侧。任何帮助将非常感激。这是我的代码:
public void wrapAround(){
wrapAround = true;
//Code to wrap around
if (x < 0) x = x + gameView.getWidth(); //increment x whilst not off screen
if (x >= gameView.getWidth()){ //if gone of the right sides of screen
xSpeed = (xSpeed * -1);
}
if (x <= gameView.getWidth())
{
xSpeed = (xSpeed * -1);
}
if (y < 0) y = y + gameView.getHeight();//increment y whilst not off screen
if (y >= gameView.getHeight()){//if gone of the bottom of screen
ySpeed = (ySpeed * -1);
}
if (y <= gameView.getHeight())
{
ySpeed = (ySpeed * -1);
}
【问题讨论】:
-
精灵只是来回摆动