我正在创造一个移动的角色,它向上移动很好但是当它向侧面移动时它非常慢。这是运动代码:
p.getPosition()。y + = playerSpeed;
这是处理输入的代码:
World world;
Player p;
WorldHandler wh;
public boolean touchUp(int screenX, int screenY, int pointer, int button)
{
p = world.getPlayer();
wh = new WorldHandler(world);
if(screenX >= Gdx.graphics.getWidth() / 2) // Right side of the screen
{
p.getVel().x = wh.playerSpeed;
}
if(screenX <= Gdx.graphics.getWidth() / 2) // Left side of the screen
{
p.getVel().x = -wh.playerSpeed;
}
return false;
}
感谢您的帮助! :)
答案 0 :(得分:0)
我修好了,我猜它以一种欺骗的方式修好了。而不是做: if(screenX&gt; = Gdx.graphics.getWidth()/ 2)//屏幕右侧 { p.getVel()。x = wh.playerSpeed; }
if(screenX <= Gdx.graphics.getWidth() / 2) // Left side of the screen
{
p.getVel().x = -wh.playerSpeed;
}
我这样做了:if(screenX&gt; = Gdx.graphics.getWidth()/ 2)//屏幕右侧 { p.getVel()。x = 12; }
if(screenX <= Gdx.graphics.getWidth() / 2) // Left side of the screen
{
p.getVel().x = -12;
}
还有y运动我将其固定为更平滑的运动风格,感谢Fish,这里是代码:p.getPosition()。y + = playerSpeed * Gdx.graphics.getDeltaTime();
这对我来说都是! :)