Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java lidbgx从右向左移动对象_Java_Android_Libgdx - Fatal编程技术网

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;
}