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
protected void onCreate(final Bundle pSavedInstanceState) { super.onCreate(pSavedInstanceState); this.mPaused = true; this.mEngine = this.onLoadEngine(); this.applyEngineOptions(this.mEngine.getEngineOptions()); this.onSetContentView(); }
时,
this.mEngine = this.onLoadEngine(); this.applyEngineOptions(this.mEngine.getEngineOptions());
这句代码会调用BaseGameActivity中四个onLoadEngine(), onLoadScene(),onLoadComplete(),onLoadResource()中的onLoadEngine()执行引擎的初始化操作,
并设置主View
this.onSetContentView();
其中onSetContentView()的具体代码如下: protected void onSetContentView() { this.mRenderSurfaceView = new RenderSurfaceView(this); this.mRenderSurfaceView.setEGLConfigChooser(false); this.mRenderSurfaceView.setRenderer(this.mEngine); this.setContentView(this.mRenderSurfaceView, this.createSurfaceViewLayoutParams()); }
可以看到在上面的代码中主要对SurfaceView进行了设置,引擎将在它上面进行绘制操作。
this.setContentView(this.mRenderSurfaceView, this.createSurfaceViewLayoutParams());
设置主视图,与使用Activity的setContentView一样。
2.
public interface IGameInterface { // =========================================================== // Final Fields // =========================================================== // =========================================================== // Methods // =========================================================== public Engine onLoadEngine(); public void onLoadResources(); public void onUnloadResources(); public Scene onLoadScene(); public void onLoadComplete(); public void onGamePaused(); public void onGameResumed(); }
baseGameActivity实现了IGameInterface,这个类主要是定义了游戏中需要的主要回调方法,可以理解成类似于Activity的生命周期方法。