A Starter Class defines the entry point (starting point) of a Libgdx application,Starter Class定义libgdx应用的的进入口
Once booting has finished, the
Libgdx framework hands over control from the Starter Class (for example, the
demo-desktop project) to your shared application code (for example, the demo
project) by calling the different methods from the ApplicationListener interface
that the MyDemo class implements(英文原文)
一旦启动完成,libgdx框架就会将控制权从启动类转移给你的共享代码区,也就是核心代码区,其中的原理就是调用ApplicationListener接口中的各种方法,下面让我们来看代码
下面给出demo-desktop中的Main.java
package com.packtpub.libgdx.demo; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; public class Main { public static void main(String[] args) { LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration(); cfg.title = "demo"; cfg.useGL20 = false; cfg.width = 480; cfg.height = 320; new LwjglApplication(new MyDemo(), cfg); } }
new LwjglApplication(new MyDemo(), cfg);中传入的第一个参数为LwjglApplication实例,MyDemo实现了
LwjglApplication,第二个参数为LwjglApplicationConfiguration的实例。
运行后得到如下画面
下面给出demo-android中的MainActivity.java
package com.packtpub.libgdx.demo; import android.os.Bundle; import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android .AndroidApplicationConfiguration; public class MainActivity extends AndroidApplication { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration(); cfg.useGL20 = false; initialize(new MyDemo(), cfg); } }
it is an instance of the MyDemo class. The instances of MyDemo
and AndroidApplicationConfiguration are passed as arguments to the
initialize() method. The configuration is set to not request OpenGL ES 2.0
support on an Android device.