有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我不理解一些libgdx编译错误

我是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;
    }
  }
}

我用了this example 也许我得写“类输入测试扩展GdxTest”? 但如果我插入“import com.badlogic.gdx.tests.utils.GdxTest;”,就会出现错误

在互联网上的许多例子中,没有“导入”行 和库名称,应添加到项目中。 有人能解释一下怎么找到它吗

谢谢


共 (1) 个答案

  1. # 1 楼答案

    第一个错误

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

    您正在传递类型为Gamethis引用,但Gdx.input.setInputProcessor需要一个参数,该参数是对InputProcessor对象的引用

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

    如果取消注释implements InputProcessor,应该可以消除该错误