2012-05-20 38 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

太好了。很高興我能幫上忙 :-) –