2013-03-13 24 views
0

我想使文件路徑可由用戶更改。但據我所知,爲了做到這一點,它必須是靜態的。這是我得到的。在文件路徑中使用非變量

private String texturePath; 
more code... 
public String getTexturePath() 
{ 
return (String)texturePath; 
} 

public void onUpdate() 
{ 
super.onUpdate(); 
this.texture = "/adventure/" + this.getTexturePath() + ".png"; 
} 

有多個對象,並且當使用靜態變量時,它將所有對象都改爲相同的,而不能改變它們的個性。

回答

0

您需要將該參數作爲參數發送給該方法。

public void onUpdate(String path){ 
    super.onUpdate(); 
    this.texture = path + this.getTexturePath() + ".png"; 
} 

靜態變量屬於類,而不屬於實例。

+0

這沒有奏效。添加(字符串路徑)onUpdate停止它覆蓋其擴展的onUpdate – user2163502 2013-03-13 19:33:49

+0

那麼,你需要調整你的其他代碼。當然,如果這種方法壓倒一切,那麼你需要進行其他調整。我的回答僅基於該片段。 – 2013-03-13 23:33:12

+0

還有其他的方式,實際上我不喜歡,因爲它似乎只需要這個方法...如果你不想改變方法簽名(從update()到update(String path)) ,只需創建一個「私人字符串路徑」,使用該var的get/set方法,並在調用方法之前設置var值。然後,該方法將保持如下狀態: public void onUpdate(){ super.onUpdate(); this.texture = this.getPath()+ this.getTexturePath()+「.png」; } – 2013-03-13 23:34:00

相關問題