Game 和Screen分析
来源:互联网 发布:数据挖掘与r语言 .mobi 编辑:程序博客网 时间:2024/06/05 17:12
libgdx 的整体架构如下:
入口:Game-->screen-->stage-->actor
具体如图:
因此我们需要分析下Game.java 和Screen.java 了。
game类位置为:
libgdx-master\gdx\src\com\badlogic\gdx
内容为:
public abstract class Game implements ApplicationListener {
private Screen screen;
@Override
public void dispose () {
if (screen != null) screen.hide();
}
@Override
public void pause () {
if (screen != null) screen.pause();
}
@Override
public void resume () {
if (screen != null) screen.resume();
}
@Override
public void render () {
if (screen != null) screen.render(Gdx.graphics.getDeltaTime());
}
@Override
public void resize (int width, int height) {
if (screen != null) screen.resize(width, height);
}
/** Sets the current screen. {@link Screen#hide()} is called on any old screen, and {@link Screen#show()} is called on the new
* screen, if any.
* @param screen may be {@code null} */
public void setScreen (Screen screen) {
if (this.screen != null) this.screen.hide();
this.screen = screen;
if (this.screen != null) {
this.screen.show();
this.screen.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
}
/** @return the currently active {@link Screen}. */
public Screen getScreen () {
return screen;
}
}
我们可以看到继承了ApplicationListener,因此他可以作为渲染对象增加到androidApplication的初始化接口里面,作为主线程的渲染对象。
它的各个接口处理了screen的生命周期。
主要来看看setScreen 和render 接口。
setScreen 完成将屏幕添加进来,以便后面其它接口调用。
render 则直接调用screen.render(Gdx.graphics.getDeltaTime()); 传递下去。
Screen对象代码为:
public interface Screen {
/** Called when the screen should render itself.
* @param delta The time in seconds since the last render. */
public void render (float delta);
/** @see ApplicationListener#resize(int, int) */
public void resize (int width, int height);
/** Called when this screen becomes the current screen for a {@link Game}. */
public void show ();
/** Called when this screen is no longer the current screen for a {@link Game}. */
public void hide ();
/** @see ApplicationListener#pause() */
public void pause ();
/** @see ApplicationListener#resume() */
public void resume ();
/** Called when this screen should release all resources. */
public void dispose ();
}
如此我们继承Screen实现我们的接口,添加进Game类里面,即可实现多个屏幕的切换。
入口:Game-->screen-->stage-->actor
具体如图:
因此我们需要分析下Game.java 和Screen.java 了。
game类位置为:
libgdx-master\gdx\src\com\badlogic\gdx
内容为:
public abstract class Game implements ApplicationListener {
private Screen screen;
@Override
public void dispose () {
if (screen != null) screen.hide();
}
@Override
public void pause () {
if (screen != null) screen.pause();
}
@Override
public void resume () {
if (screen != null) screen.resume();
}
@Override
public void render () {
if (screen != null) screen.render(Gdx.graphics.getDeltaTime());
}
@Override
public void resize (int width, int height) {
if (screen != null) screen.resize(width, height);
}
/** Sets the current screen. {@link Screen#hide()} is called on any old screen, and {@link Screen#show()} is called on the new
* screen, if any.
* @param screen may be {@code null} */
public void setScreen (Screen screen) {
if (this.screen != null) this.screen.hide();
this.screen = screen;
if (this.screen != null) {
this.screen.show();
this.screen.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
}
/** @return the currently active {@link Screen}. */
public Screen getScreen () {
return screen;
}
}
我们可以看到继承了ApplicationListener,因此他可以作为渲染对象增加到androidApplication的初始化接口里面,作为主线程的渲染对象。
它的各个接口处理了screen的生命周期。
主要来看看setScreen 和render 接口。
setScreen 完成将屏幕添加进来,以便后面其它接口调用。
render 则直接调用screen.render(Gdx.graphics.getDeltaTime()); 传递下去。
Screen对象代码为:
public interface Screen {
/** Called when the screen should render itself.
* @param delta The time in seconds since the last render. */
public void render (float delta);
/** @see ApplicationListener#resize(int, int) */
public void resize (int width, int height);
/** Called when this screen becomes the current screen for a {@link Game}. */
public void show ();
/** Called when this screen is no longer the current screen for a {@link Game}. */
public void hide ();
/** @see ApplicationListener#pause() */
public void pause ();
/** @see ApplicationListener#resume() */
public void resume ();
/** Called when this screen should release all resources. */
public void dispose ();
}
如此我们继承Screen实现我们的接口,添加进Game类里面,即可实现多个屏幕的切换。
0 0
- Game 和Screen分析
- libgdx 同步screen的dispose和game的dispose
- Screen.Width 和 Screen.Height
- 第一章 第七节 Game Splash Screen
- Android Game Development - Moving Images on Screen
- Real-Time Strategy Game with Touch Screen
- libGDX screen game 多界面游戏
- Libgdx之Game场景切换Screen
- 关于Screen.availWidth和Screen.availHeight
- nohup和screen
- Libgdx专题系列:对象篇 Game游戏控制中心 Screen 场景
- nohup和screen的比较
- screen对象和Event对象
- Screen, Viewport 和 Rect 浅析
- linux日志和screen工具
- mosh和screen的操作
- Screen
- screen
- Xamarin - Disadvantages
- S2SH通用分页
- ListView下拉刷新,上拉自动加载更多
- 优秀的样式扫描与处理工具-AWK
- 绘图
- Game 和Screen分析
- 10个最强大的java开源中文CMS
- git创建远程版本库
- MEF程序设计指南四:使用MEF声明导出(Exports)与导入(Imports)
- 组合聚合的区别
- android 小备忘录
- 苹果所有常用证书,appID,Provisioning Profiles配置说明及制作图文教程(精)
- openstack-folsom-architecture
- 制作自己的浏览器,进行定制服务