AndEngine引擎的生命周期

来源:互联网 发布:网络平台建设 编辑:程序博客网 时间:2024/05/16 05:42

在下面的图中,可以看到游戏在创建、最小化、销毁的时间

AndEngine引擎包含一些的方法,用来创建EngineOptions对象、Scene对象和用子实体来填充Scene。这些方法按照一下顺序被调用:

1)定义onCreateEngineOptions()方法

mCamera = new Camera(0, 0, WIDHT, HEIGHT);//Declare & Define our engine options to be applied to our//Engine objectEngineOptions engineOptions = new EngineOptions(true,ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(),mCamera);//It is necessary in a lot of applications to define the following wake lock options // in order to disable the device's display from turning off during gameplay due to 
                //inactivityengineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);// Return the engineOptions object, passing it to the enginereturn engineOptions;
2、定义onCreateResources()方法

@Overridepublic void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback)throws Exception {// We should notify the pOnCreateResourcesCallback that we've finished//loading all of the necessary resources in our game AFTER they are loaded.//onCreateResourcesFinished() should be the last method called. pOnCreateResourcesCallback.onCreateResourcesFinished();}
3、定义onCreateScene()方法

@Overridepublic void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)throws Exception {// Create the Scene objectfinal Scene mScene = new Scene();// Notify the callback that we're finished creating the scene,// returning mScene to the mEngine object (handled automatically)pOnCreateSceneCallback.onCreateSceneFinished(mScene);}

4、定义onPopulateScene()方法

@Overridepublic void onPopulateScene(Scene pScene,OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {// onPopulateSceneFinished(), similar to the resource and scene//callback methods, should be called once we are finished populating the scene.pOnPopulateSceneCallback.onPopulateSceneFinished();}
在启动期间生命周期如下: