2015-03-30 51 views
0

Sry我的英語不好。 所以我正在做一個遊戲,我有問題。 (Libgdx但無所謂) SolarGame是一個主類,它是一個輸入處理程序。 TesterClass有一個渲染方法。 閃電正在產生一些數據。沒有包含的實例我需要解決方案

public class SolarGame implements ApplicationListener, InputProcessor { 
TesterClass testerClass; 
bool inputbool = false; //That bool is change, when event is happen 

public bool getBool(){ 
    return inputbool 
} 

public void create() { 
    testerClass = new TesterClass(); 
} 
//some other code here 

public class TesterClass { 

Lightning lightning; 

public void _init_() { 
    lightning = new Lightning(); 
} 
//Some code here 

public class Lightning { 

    public Lightning() { 
     bool input = SolarGame.this.getBool(); 
//This line cause an error. 

如果將SolarGame更改爲靜態,我會得到一些其他錯誤。 但我需要在Lightning類中輸入inputbool。 當事件發生時,我需要停止閃電數據生成方式。

重複我的英語。

回答

1

所以,如果我明白這個權利,你需要在你的閃電類的SolarGame的一個實例?因爲它很難理解實際問題是什麼,代碼也沒有多大幫助。

在Lightning中獲得SolarGame實例的操作非常簡單。您只需通過它當U創建照明上:

public class Lightning{ 

SolarGame game; 

public Lightning(SolarGame game){ 
     this.game = game; 
} 
} 

現在,您可以訪問您的inputbool沒有任何問題,在不改變任何類的靜態:

bool inputbool = game.getBool(); 

既然你創建閃電類在TesterClass需要SolarGame合格實例到TesterClass一樣DESCR如上所述。我想我已經解決了你的問題