我目前正在嘗試使用libGDX在Android操作系統上製作遊戲,並且我正在爲其設置屏幕管理器。我基於這個我在VB.NET中使用的屏幕管理器,並試圖將其轉換爲Java。這是我目前爲止的內容,我會告訴你我確切的問題是什麼。幫助我的Java AndroidOS遊戲
Manager.java
package rawct.gamename.Screen;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.badlogic.gdx.Gdx;
import rawct.gamename.GameName;
import rawct.gamename.Screen.Screens.*;
public class Manager extends GameName {
private static List<Screen> Screens = new ArrayList<Screen>();
private static List<Screen> NewScreens = new ArrayList<Screen>();
private Screen Debug = new Debug("Debug");
public Manager() {
//Gdx.app.log("Manager", "New Instance!");
AddScreen(Debug);
//Testing to see which screens were loaded and testing unload
UnloadScreen();
}
public void AddScreen(Screen NewScreen){
NewScreens.add(NewScreen);
}
public void Draw(){
}
public void UnloadScreen(){
Gdx.app.log("UnloadScreen", "Start");
for(Iterator<Screen> s = NewScreens.iterator(); s.hasNext();){
Gdx.app.log("Screen", ""+s.next().Name);
//Should output Debug.Name but isn't, outputting Screen.Name
}
Gdx.app.log("UnloadScreen", "End");
}
public void Update(){
}
}
Screen.java
package rawct.gamename.Screen;
public interface Screen {
enum ScreenState {
Active,
Hidden,
ShutDown
}
public static String Name = null;
public ScreenState State = ScreenState.Active;
public float Position = 0;
public boolean Focused = false;
public boolean GrabFocus = true;
public void HandleInput();
public void Update();
public void Draw();
public void Unload();
}
和我的測試屏幕
Debug.java現在
package rawct.gamename.Screen.Screens;
import com.badlogic.gdx.Gdx;
import rawct.gamename.Screen.Screen;
public class Debug implements Screen {
public Debug(String sName){
// TODO Constructor
Gdx.app.log("Debug", "New Instance!");
Name = sName;
//Won't let me set name, says "The final sfield Screen.Name cannot be assigned"
}
@Override
public void HandleInput() {
// TODO Auto-generated method stub
}
@Override
public void Update() {
// TODO Auto-generated method stub
}
@Override
public void Draw() {
// TODO Auto-generated method stub
}
@Override
public void Unload() {
// TODO Auto-generated method stub
}
}
好吧,我已經發布的所有代碼,我是什麼要做的就是訪問每個屏幕的每個.Name變量,我將添加到屏幕列表(List)中,但它不會讓我按照自己的方式設置/訪問屏幕。但它在VB.NET中有效我知道這並不意味着太多,但只是想知道如何在Java中完成這項工作。
我希望能夠添加新的屏幕到屏幕列表中,併爲它們命名並使用列表訪問每個屏幕中的每個方法和變量。
謝謝!
你想用HashMap中的鍵來訪問屏幕嗎? – 2013-04-21 05:33:36
你在哪裏實現屏幕界面?你在AddScreen()中傳遞具體的屏幕對象嗎? – 2013-04-21 05:40:02
作爲屏幕名稱的關鍵是。我只想訪問我添加到列表中的屏幕變量和方法。 – Richard 2013-04-21 05:40:20