gdx-metagunl分析-整体框架(com.dozingcatsoftware.bouncy)
gdx-metagunl分析--整体框架(com.dozingcatsoftware.bouncy)
一、Metagun.java
Metagun类是整个游戏的入口也是资源和UI创建的入口。
见下面libdex游戏的生命周期图:

1. create():
由于Bouncy继承了InputAdapter类和实现了ApplicationListener接口,所以当Application运行时会先调用create(),具体代码如下:
Art类封装装载了所有的资源,包括背景、舞台以及演员。
Sound实现了对声音的封装。
setScreen函数设置屏幕。
Gdx.input.setInputProcessor(input);
这句比较关键,设置的对输入的处理:Sets the InputProcessor that will receive all touch and key input events. It will be called before the ApplicationListener.render() method each frame.
在渲染前会对收到这些输入的事件。
2. render
render function:Called when the Application should render itself.
这里的screen为TitleScreen,即开始屏幕,这里的render主要检测用户是否点击开始
若超时,则进入setScreen(new ExpositionScreen());
整个Metagun比较简单,是整个游戏的入口。
gdx-metagun分析--整体框架(com.dozingcatsoftware.bouncy)
一、Metagun.java
Metagun类是整个游戏的入口也是资源和UI创建的入口。
public class MetagunAndroid extends AndroidApplication { /** Called when the activity is first created. */ @Override public void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); initialize(new Metagun(), false); } }
见下面libdex游戏的生命周期图:
1. create():
由于Bouncy继承了InputAdapter类和实现了ApplicationListener接口,所以当Application运行时会先调用create(),具体代码如下:
public void create () { Art.load(); Sound.load(); Gdx.input.setInputProcessor(input); running = true; setScreen(new TitleScreen()); }
Art类封装装载了所有的资源,包括背景、舞台以及演员。
Sound实现了对声音的封装。
setScreen函数设置屏幕。
Gdx.input.setInputProcessor(input);
这句比较关键,设置的对输入的处理:Sets the InputProcessor that will receive all touch and key input events. It will be called before the ApplicationListener.render() method each frame.
在渲染前会对收到这些输入的事件。
2. render
public void render () { Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); accum += Gdx.graphics.getDeltaTime(); while (accum > 1.0f / 60.0f) { screen.tick(input); input.tick(); accum -= 1.0f / 60.0f; } screen.render(); }
render function:Called when the Application should render itself.
这里的screen为TitleScreen,即开始屏幕,这里的render主要检测用户是否点击开始
若超时,则进入setScreen(new ExpositionScreen());
整个Metagun比较简单,是整个游戏的入口。