Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.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
Android libdgx矢量3转换错误_Android_Libgdx - Fatal编程技术网

Android libdgx矢量3转换错误

Android libdgx矢量3转换错误,android,libgdx,Android,Libgdx,各位晚上好, 通过阅读教程,我试图熟悉libdgx和android。所有这些看起来都不错,除了抓取屏幕坐标,因为它们在Vector3转换中倾斜 因此,101的x输入转换为-796,968的y输入转换为-429(触摸屏幕左上角,emulator的结果与我的手机的结果相同)。当点击右下角时,动画在屏幕中部闪烁。 这一切似乎都很基本,所以我不确定我设置不正确,以获得一个扭曲的转换。感谢您的帮助 摄影机创建: camera = new OrthographicCamera(Gdx.graphics.ge

各位晚上好,

通过阅读教程,我试图熟悉libdgx和android。所有这些看起来都不错,除了抓取屏幕坐标,因为它们在Vector3转换中倾斜

因此,101的x输入转换为-796,968的y输入转换为-429(触摸屏幕左上角,emulator的结果与我的手机的结果相同)。当点击右下角时,动画在屏幕中部闪烁。

这一切似乎都很基本,所以我不确定我设置不正确,以获得一个扭曲的转换。感谢您的帮助

摄影机创建:

camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.position.set(camera.viewportWidth * .5f, camera.viewportHeight * .5f, 0f);
抓触坐标:

public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    touchCoordinateX = screenX;
    touchCoordinateY = screenY;
    stateTime = 0;
    explosionHappening = true;
    return true;
}
渲染循环:

public void render () {
    Gdx.gl.glClearColor(1, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    stateTime += Gdx.graphics.getDeltaTime();
    batch.begin();

    if (!explosionAnimation.isAnimationFinished(stateTime) && explosionHappening) {
        Vector3 touchPoint = new Vector3();
        touchPoint.set(touchCoordinateX,touchCoordinateY,0);
        TextureRegion currentFrame = explosionAnimation.getKeyFrame(stateTime, false);  // #16
        camera.unproject(touchPoint);
        batch.draw(currentFrame, touchPoint.x, touchPoint.y);
    }
            //  batch.draw(img, 0, 0);
    batch.end();
    if (explosionAnimation.isAnimationFinished(stateTime)){explosionHappening = false;}
}

我想你忘了将相机投影矩阵设置为SpriteBatch。加上

batch.setProjectionMatrix(camera.combined);
以前

batch.begin();

耶普,加上这句话就解决了!非常感谢。除了特别教程之外,还有什么好的资料可以概述在哪里、为什么以及如何做?每个项目的列表都描述了它的功能,但不一定描述了如何将它们组合在一起。如果我的答案修复了,你应该将其标记为已接受。有关教程,请参见官方libGDX wiki: