2012-05-20 35 views
1

我是Java和libgdx的新手,不理解那里重要的东西。 我尝试获取触摸(鼠标)事件。 我的代码示例工作好之前,我添加下面的几行代码:我不明白一些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 也许我必须写“类InputTest扩展GdxTest”? 但如果我插入“import com.badlogic.gdx.tests.utils.GdxTest;”,则出现错误

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

由于

+1

为什么类不再执行'InputProcessor'? –

+1

你有*什么*错误?发布像'我得到错误'这样的模糊陈述是完全浪费时间。它只是导致这样的问题,并失去了时间。 – EJP

回答

2

第一误差

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

您传入this参考这是Game类型的,但Gdx.input.setInputProcessor想要一个参数是一个InputProcessor对象的引用

在为了充分理解你需要理解的第二个错误覆盖 请参阅http://www.tutorialspoint.com/java/java_overriding.htm

如果您取消注释implements InputProcessor应该排除该错误。

+1

是的。在我取消注释“实现InputProcessor”并添加了所有@Override后,编译错误消失了。 ...一切正常。谢谢。 – user993354

+0

太好了。很高兴我能帮上忙 :-) –