到目前为止,我已经尝试扭转速度,所以他们理论上应该重新开始,但事实并非如此。
public void update() {
if (x > gameView.getWidth() - bmp_width - xSpeed){
xSpeed = xSpeed * -1;
ySpeed = ySpeed * -1;
}
if (y > gameView.getHeight() - bmp_height - ySpeed){
xSpeed = xSpeed * -1;;
ySpeed = ySpeed * -1;;
}
if(x + xSpeed < 0){
x = 0;
xSpeed = 0;
ySpeed = -5;
}
if(y + ySpeed < 0){
y = 0;
xSpeed = 5;
ySpeed = 0;
}
x = x + xSpeed;
y = y + ySpeed;
}
提前致谢!
答案 0 :(得分:0)
尝试这样的事情:
public void update() {
x += xSpeed;
y += ySpeed;
if (x >= gameView.getWidth() - bmp_width){
xSpeed = -xSpeed;
x = gameView.getWidth() - bmp_width;
}else if(x <= 0){
xSpeed = -xSpeed;
x = 0;
}
if (y >= gameView.getHeight() - bmp_height){
ySpeed = -ySpeed;
y = gameView.getHeight() - bmp_height;
}else if(y <= 0){
ySpeed = -ySpeed;
y = 0;
}
}