[英]Moving Texture in LibGdx with increasing speed
我使紋理移動,就像減小其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;
}
您的代碼沒有多大意義,但這是我的嘗試:
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而不是減小x時,就會遇到問題。 那是因為當它們為+1024單位正x時,您無法處理。
picx +=speed*delta; //use delta for FrameIndependant Movement
newpicx += speed*delta;
if (picx > 1024){
picx = -1024;
}
if (newpicx > 1024){
newpicx = -1024;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.