我不知道这段代码有什么问题。当精灵到达右端角落时,它应该向左移动。但是这个代码在它(精灵)到达右端时,精灵就停止了。
startM是左端角落,endM是右角落
//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() );
答案 0 :(得分:1)
对代码进行少量更改。
if(endM == ballMeter.getX()){
leftEnd =true;
}
转换为
if(endM <= ballMeter.getX()){
leftEnd =true;
}
并且
if(startM == ballMeter.getX()){
leftEnd = false;
}
到
if(startM >= ballMeter.getX()){
leftEnd = false;
}
答案 1 :(得分:0)
谢谢@AbhishekAryan
$myArray = $_POST["myInputs"];
for ($count=0; $count<count($myArray); $count++)
{ echo $myArray[$count]."<br>"; }