1

我是 Java 和 libgdx 的新手,不了解那里的重要内容。我尝试获取触摸(鼠标)事件。在我在下面的代码中添加几行之前,我的代码示例运行良好:

    ...
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.InputProcessor;
...
public class Game implements ApplicationListener /*, InputProcessor*/
...
@Override
public void create() 
{
    Gdx.input.setInputProcessor(this); 
    //*** ERROR:setInputProcessor(InputProcessor) in the type Input
    //is not applicable for the arguments Game
    ...
}
...

    @Override
    public boolean touchDown (int x, int y, int pointer, int button) { 
        //*** ERROR: The method touchDown(int, int, int, int) of type Game 
        //must override or implement a supertype method     

        Gdx.app.log("Input Test", "touch down: " + x + ", " + y + ", button: " +
           getButtonString(button));
        return false;
    }
  }
}

我用了这个例子 也许我必须写“class InputTest extends GdxTest”?但是如果我插入“import com.badlogic.gdx.tests.utils.GdxTest;”就会出错

在互联网上的许多示例中,没有“导入”行和库名称,应将其添加到项目中。任何人都可以解释如何找出它吗?

谢谢

4

1 回答 1

2

第一个错误

ERROR:setInputProcessor(InputProcessor) in the type 
Input is not applicable for the arguments Game

您传入的this是类型的引用,GameGdx.input.setInputProcessor需要一个作为InputProcessor对象引用的参数

为了完全理解第二个错误,您需要了解 Overriding 参见http://www.tutorialspoint.com/java/java_overriding.htm

如果您取消注释implements InputProcessor那应该摆脱该错误。

于 2012-05-20T04:49:33.437 回答