【问题标题】:libGDX drag and drop very slowlibGDX 拖拽很慢
【发布时间】:2014-05-23 18:25:27
【问题描述】:

我正在使用 libgdx 和 box2d 制作一个简单的拖放游戏。 在桌面上它运行良好并且对象的运动是流动的,但在 android (Galaxy SIII) 上是对象和输入之间的延迟,所以对象不在点上,输入创建。

在桌面上,一切正常:

在 Android 上,延迟:

代码很简单,所以我不明白,为什么它不起作用...

Character= new Texture(Gdx.files.internal("Character.jpg"));
cam = new OrthographicCamera();
        cam.setToOrtho(false, 480, 800);

    dx.input.setInputProcessor(this);
    public void render(float delta) {
        // TODO Auto-generated method stub
        Gdx.gl.glClearColor(0.128f,0.128f,0.128f,1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        game.batch.setProjectionMatrix(cam.combined);

        game.batch.begin();
        game.batch.draw(Character, object.x, object.y);

        game.batch.end();
        cam.update();



    @Override
    public boolean touchDragged(int screenX, int screenY, int pointer) {
        // TODO Auto-generated method stub
        Vector3 touchPos = new Vector3();
        touchPos.set(screenX, screenY, 0);
        cam.unproject(touchPos);


        object.x = touchPos.x - 56 / 2;
        object.y=touchPos.y-56/2;


        cam.update();

        return false;
    }

没有 libGdx 的拖放动作效果更好。但是 libGdx 是其他游戏功能所必需的...

有人给点建议吗?? 问候

【问题讨论】:

  • 我也有同样的问题,你找到解决办法了吗?
  • 对不起,我没有找到解决方案...但现在我认为是这样,因为您的屏幕刷新率为 60Hz。但是当你移动你的精灵时,速度超过每秒 60 像素,一些像素会被跳过。这就是为什么运动看起来“不平衡”....

标签: java libgdx


【解决方案1】:

通过在 Android 启动器中设置 config.touchSleepTime = 16;,我看到了轻微的改进。

public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        config.useAccelerometer = false;
        config.useCompass = false;
        config.touchSleepTime = 16;
        initialize(new SomeGame(), config);
    }
}

仍有明显的滞后,但希望这会有所帮助。

【讨论】:

  • 谢谢,我试试-
【解决方案2】:

您检查了 FPS 吗? S3限制帧率是很常见的。 确保禁用所有省电模式以达到 60 FPS。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    • 1970-01-01
    相关资源
    最近更新 更多