Java lidbgx从右向左移动对象
它从左向右移动,然后回到起始位置。当Java lidbgx从右向左移动对象,java,android,libgdx,Java,Android,Libgdx,它从左向右移动,然后回到起始位置。当tr\u ball到达右侧时,如何将其从右向左移动?为班级创建一个球速变量 batch.begin(); batch.draw(tr_background, 0, 0, 3024, 1443); batch.draw(tr_ball, x, 110, 100, 100); batch.end(); x = x + 100 * Gdx.graphics.getDeltaTime(); if(x > came
tr\u ball
到达右侧时,如何将其从右向左移动?为班级创建一个球速变量
batch.begin();
batch.draw(tr_background, 0, 0, 3024, 1443);
batch.draw(tr_ball, x, 110, 100, 100);
batch.end();
x = x + 100 * Gdx.graphics.getDeltaTime();
if(x > camera.viewportWidth)
x = -100;
然后当球越过屏幕末端时将其翻转。因此,在上面的batch.end()
之后替换代码:
float ballSpeed = 100;
x+=ballSpeed*Gdx.graphics.getDeltaTime();
如果(x>=camera.viewportWidth-100){
x=camera.viewportWidth;//防止超调
球速*=-1;
}否则如果(x嘿,兄弟,谢谢你!!!!!当它再次到达左侧时,它不会回到右侧。怎么做?谢谢你,阿加尼应该使用=
和
和我刚刚更新了它,以处理球到达终点前有一个很长的框架,然后再也不能从该区域弹起的情况。现在它是当球过冲时,fts将球移回准确的边缘。
x += ballSpeed * Gdx.graphics.getDeltaTime();
if (x >= camera.viewportWidth - 100) {
x = camera.viewportWidth; // prevent overshooting
ballSpeed *= -1;
} else if (x <= 0) {
x = 0; // prevent overshooting
ballSpeed *= -1;
}