gpt4 book ai didi

java - Android libgdx... Sprite 水平来回移动

转载 作者:行者123 更新时间:2023-12-01 08:48:52 24 4
gpt4 key购买 nike

我不知道这段代码有什么问题。当 Sprite 到达右端角时,它应该向左移动。但这段代码会在它( Sprite )到达右端角时执行, Sprite 就会停止。

The startM is the left end corner, and the endM is the right end corner

 //in constructor
position = new Vector2(ShootingTreys.WIDTH*0.48f, ShootingTreys.HEIGHT*0.025f);

// in update
delta = Gdx.graphics.getDeltaTime();
if(ps.touch == false){

if(leftEnd == false && (startM <= ballMeter.getX()) ){
position.x = ballMeter.getX();
position.x += 20 *delta;

if(endM == ballMeter.getX()){
leftEnd =true;
}
}
else {
position.x = ballMeter.getX();
position.x -= 20 *delta;

if(startM == ballMeter.getX()){
leftEnd = false;
}
}

ballMeter.setPosition(position.x , ballMeter.getY() );

最佳答案

对代码进行一些小的更改。

if(endM == ballMeter.getX()){
leftEnd =true;
}

转换为

if(endM <= ballMeter.getX()){
leftEnd =true;
}

if(startM == ballMeter.getX()){
leftEnd = false;
}

if(startM >= ballMeter.getX()){
leftEnd = false;
}

关于java - Android libgdx... Sprite 水平来回移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42512993/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com