Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Libgdx运动问题_Libgdx - Fatal编程技术网

Libgdx运动问题

Libgdx运动问题,libgdx,Libgdx,我正在创造一个移动的角色,它向上移动的很好,但当它向一边移动时,速度非常慢。以下是移动代码: p、 getPosition().y+=玩家速度 这是处理输入的代码: World world; Player p; WorldHandler wh; public boolean touchUp(int screenX, int screenY, int pointer, int button) { p = world.getPlayer(); wh = new WorldH

我正在创造一个移动的角色,它向上移动的很好,但当它向一边移动时,速度非常慢。以下是移动代码:

p、 getPosition().y+=玩家速度

这是处理输入的代码:

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;
}
世界;
玩家p;
WorldHandler wh;
公共布尔补色(整数屏幕X、整数屏幕Y、整数指针、整数按钮)
{
p=world.getPlayer();
wh=新WorldHandler(世界);
if(screenX>=Gdx.graphics.getWidth()/2)//屏幕右侧
{
p、 getVel().x=wh.playerSpeed;
}

如果(screenX我把它修好了,我想我是用一种欺骗的方式修好的。而不是做: if(screenX>=Gdx.graphics.getWidth()/2)//屏幕右侧 { p、 getVel().x=wh.playerSpeed; }

    if(screenX <= Gdx.graphics.getWidth() / 2) // Left side of the screen
    {
        p.getVel().x = -12;
    }
if(screenX=Gdx.graphics.getWidth()/2)//屏幕右侧
{
p、 getVel().x=12;
}

    if(screenX <= Gdx.graphics.getWidth() / 2) // Left side of the screen
    {
        p.getVel().x = -12;
    }

if(screenX如果我是你,我会使用“p.getPosition().y+=playerSpeed*Gdx.graphics.getDeltaTime();”,因为它会根据每秒的渲染帧更新你的位置。它消除了跳跃和滞后。谢谢你的帮助!)