在Android上处理Libgdx应用程序的屏幕

时间:2016-08-05 18:41:39

标签: libgdx screen

这是我处理屏幕的方式

我有class dClass1 : IBaseClass { int x; int y; baseClass someMethod(); } class dClass2 : IBaseClass { int x; int y; baseClass someMethod(); } 我在每个屏幕上创建了它的实例,所以我可以使用这样的内容dClass1 c1=new dClass1 (); c1.x=4; c1.y=5; dClass2 c2=c1;//cast to dClass2 , but value of property set by according to the own algorithm Console.WriteLine("{0}, {1}", c1.x, c1.y);//4,5 Console.WriteLine("{0}, {1}", c2.x, c2.y);//7,1

我的问题是如何从一个屏幕正确移动到另一个屏幕?

我有以下内容:

在GameMain中我class GameMain extends Game

在启动画面中,gameMain.setScreen()setScreen(new SplashScreen(this))的闪光灯中,我将其称为setScreen(new MenuScreen(this)),依此类推,当玩家点击菜单画面中的播放按钮I hide()时,播放到新的playScreen I也可以在dispose()中致电setScreen(),然后返回菜单I dispose()

我做错了什么?

1 个答案:

答案 0 :(得分:1)

我通常做的是在我的主游戏类中有一个函数,例如名为setPlayScreen(),在那个方法中我做了类似的事情:

public void setPlayScreen(params){
    //Do something with params
    setScreen(new PlayScreen())
}

如果你的屏幕hide()方法中有dispose(),那么你应该没有任何问题。

相关问题