在LibGdx中移动纹理的速度越来越快

时间:2013-02-25 06:57:11

标签: java libgdx

我让纹理移动就像减少它的X轴一样。但问题是,当我以越来越快的速度移动它时,它无法正确添加。我的示例代码如下所示。

picx = 0;
newpicx = 1024;
if(speed<20) speed+=.05f;

picx -=speed;
newpicx -= speed;

if ((picx + 1024 - speed-4) <0) {
    picx = 1024;
}

if ((newpicx + 1024 - speed-4) <0) {
    newpicx = 1024;     
}

1 个答案:

答案 0 :(得分:0)

你的代码没有多大意义,但这是我的尝试:

picx = 0;
newpicx = 1024;
if(speed<20) speed+=.05f;

picx -=speed;
newpicx -= speed;

if ((picx + 1024 - speed-4) <0) {
    picx = 1024;
}

if ((newpicx + 1024 - speed-4) <0) {
    newpicx = 1024;     
}

你正在制作两张“pic”,无论是什么,它们的x位置从1st = 0,2nd = 1024开始。然后你使用稳定在20的增加速度向左移动(负x),当它们在x轴上低于0时超过1024个单位时,它们传送到正1024.

然后当你开始增加x而不是减少时,你会遇到问题。那是因为当他们+1024单位正x时你没有处理。

picx +=speed*delta; //use delta for FrameIndependant Movement
newpicx += speed*delta;

if (picx > 1024){
    picx = -1024;
}

if (newpicx > 1024){
    newpicx = -1024;     
}
相关问题