AndEngine 分析之一-----BaseGameActivity

BaseGameActivity: 
The BaseGameActivity is the root of a game, that contains an Engine and manages to create a SurfaceView the contents of the Engine will be drawn into. There is always exactly one Engine for one BaseGameActivity. You can proceed from one BaseGameActivity to another using common Android mechanisms.

 

BaseGameActivity是游戏的基础,它包含一个Engine并负责完成游戏页面的初始化设定工作。

 

1.public abstract class BaseGameActivity extends BaseActivity implements IGameInterface {}

可以看出BaseGameAcitivity继承自BaseActivity,所以它本质上就是一个Activity,自然也就应该实现Activity

Java代码  

1. protected void onCreate(final Bundle pSavedInstanceState) {  

2.         super.onCreate(pSavedInstanceState);  

3.         this.mPaused = true;  

4.   

5.         this.mEngine = this.onLoadEngine();  

6.   

7.         this.applyEngineOptions(this.mEngine.getEngineOptions());  

8.   

9.         this.onSetContentView();  

10.     }  

 时,

Java代码  

1. this.mEngine = this.onLoadEngine();  

2. this.applyEngineOptions(this.mEngine.getEngineOptions());  

这句代码会调用BaseGameActivity中四个onLoadEngine(), onLoadScene(),onLoadComplete(),onLoadResource()中的onLoadEngine()执行引擎的初始化操作,

并设置主View

Java代码  

1. this.onSetContentView();  

 

Java代码  

1. 其中onSetContentView()的具体代码如下:  

2.   

3. protected void onSetContentView() {  

4.         this.mRenderSurfaceView = new RenderSurfaceView(this);  

5.         this.mRenderSurfaceView.setEGLConfigChooser(false);  

6.         this.mRenderSurfaceView.setRenderer(this.mEngine);  

7.   

8.         this.setContentView(this.mRenderSurfaceView, this.createSurfaceViewLayoutParams());  

9.     }  

 

可以看到在上面的代码中主要对SurfaceView进行了设置,引擎将在它上面进行绘制操作。

Java代码  

1. this.setContentView(this.mRenderSurfaceView, this.createSurfaceViewLayoutParams());  

设置主视图,与使用ActivitysetContentView一样。

 

 

2.

Java代码  

1. public interface IGameInterface {  

2.     // ===========================================================  

3.     // Final Fields  

4.     // ===========================================================  

5.   

6.     // ===========================================================  

7.     // Methods  

8.     // ===========================================================  

9.   

10.     public Engine onLoadEngine();  

11.     public void onLoadResources();  

12.     public void onUnloadResources();  

13.     public Scene onLoadScene();  

14.     public void onLoadComplete();  

15.       

16.     public void onGamePaused();  

17.     public void onGameResumed();   

18. }  

 baseGameActivity实现了IGameInterface,这个类主要是定义了游戏中需要的主要回调方法,可以理解成类似于Activity的生命周期方法。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值