我目前正在尝试使用 libGDX 在 Android 操作系统上制作游戏,并且正在为它开发屏幕管理器。我基于我在 VB.NET 中使用的屏幕管理器并尝试将其转换为 java。这是我到目前为止所拥有的,我会告诉你我的确切问题是什么。
管理器.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(){
}
}
屏幕.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();
}
和我的测试屏幕
调试.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 变量,我将添加到屏幕列表(列表)中,但它不允许我以这种方式设置/访问我的屏幕我想要。但它适用于 VB.NET 我知道这并不意味着什么,但我只是想知道如何在 Java 中实现这一点。
我希望能够将新屏幕添加到屏幕列表中,并为它们命名并使用列表访问每个屏幕中的每个方法和变量。
谢谢!