协助我的Java AndroidOS游戏

时间:2013-04-21 05:27:46

标签: java android libgdx

我目前正在尝试使用libGDX在Android操作系统上制作游戏,而我正在为它设置屏幕管理器。我基于我在VB.NET中使用的屏幕管理器,并尝试将其转换为java。这是我到目前为止所做的,我会告诉你我的确切问题是什么。

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变量,我将添加到屏幕列表(列表)但是它不允许我设置/访问我的屏幕我想要的方式。但它适用于VB.NET我知道这并不意味着什么,但只是想知道如何用Java实现这一点。

我希望能够在屏幕列表中添加新屏幕并为其命名,并使用列表访问每个屏幕中的每个方法和变量。

谢谢!

1 个答案:

答案 0 :(得分:0)

默认情况下,接口中的变量是静态的和最终的。 删除屏幕界面中的所有变量。

Make Screen,一个具体的类,有私有变量,并为它生成getter和setter。