【问题标题】:Get actual touch position LibGDX获取实际触摸位置 LibGDX
【发布时间】:2013-09-15 15:27:46
【问题描述】:

当使用Gdx.input.getX()Gdx.input.getY() 时,该位置在计算机上似乎没问题,但当我将它放在Android 平板电脑上时,该位置完全关闭。

我做了一些研究,在某处看到有人提到我应该使用camera.unproject(Vector3),但我不确定这是否是我需要使用或如何使用它。

【问题讨论】:

    标签: java android libgdx


    【解决方案1】:
    class Pause extends Screen
    {
    Vector3 touchPoint;
    Pause()
    {
     touchPoint = new Vector3();
    }
    void update(float deltaTime)
    {       
    if(Gdx.input.justTouched())
        {
            cam.unproject(touchPoint.set(Gdx.input.getX(),Gdx.input.getY(), 0));
            if(OverlapTester.pointInRectangle(Assets.resumeButton.getBoundingRectangle(), touchPoint.x,touchPoint.y))
            {
                some thing u want to do
            }
    
    }
    

    【讨论】:

    • 希望你熟悉 OverlapTester 类
    • 从来没有听说过.. 哈哈,我可能会弄明白,谢谢
    • public class OverlapTester { public static boolean overlayRectangles(Rectangle r1, Rectangle r2) { if (r1.x r2.x && r1.y r2.y) 返回真;否则返回假; } public static boolean pointInRectangle(Rectangle r, Vector2 p) { return r.x = p.x && r.y = p.y; } public static boolean pointInRectangle(Rectangle r, float x, float y) { return r.x = x && r.y = y; } }
    • 矩形是什么类型的?必须从 Libgdx 或 java.awt 导入?
    • 来自 libgdx。 Awt 无法在安卓设备上运行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多