读书人

AndEngine 分析之4-Engine

发布时间: 2012-09-12 09:21:30 作者: rapoo

AndEngine 分析之四-----Engine

Engine:
The Engine make the game proceed in small discrete steps of time. The Engine manages to synchronize a periodic drawing and updating of the Scene, which contains all the content that your game is currently handling actively. There usually is one Scene per Engine, except for the SplitScreenEngines.

?

Engine使游戏在不连续的时间进行,它设法同步更新和画场景,通常每一个Engine对应一个Scene,除了SplitScreenEngines

?

1.通常在客户端实现BaseGameActivity时在覆写onLoadEngine()方法时执行的操作:

public Engine onLoadEngine() {this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));}

?其中在Engine类中的Engine(EngineOptions opts)具体方法如下:

?

public Engine(final EngineOptions pEngineOptions) {TextureRegionFactory.setAssetBasePath("");SoundFactory.setAssetBasePath("");MusicFactory.setAssetBasePath("");FontFactory.setAssetBasePath("");BufferObjectManager.setActiveInstance(this.mBufferObjectManager);this.mEngineOptions = pEngineOptions;this.setTouchController(new SingleTouchControler());this.mCamera = pEngineOptions.getCamera();if(this.mEngineOptions.needsSound()) {this.mSoundManager = new SoundManager();}if(this.mEngineOptions.needsMusic()) {this.mMusicManager = new MusicManager();}if(this.mEngineOptions.hasLoadingScreen()) {this.initLoadingScreen();}this.mUpdateThread.start();}

?

其中,在代码的后部分:

if(this.mEngineOptions.hasLoadingScreen()) {this.initLoadingScreen();}

初始化下载Screen的操作:

?
private void initLoadingScreen() {final ITextureSource loadingScreenTextureSource = this.mEngineOptions.getLoadingScreenTextureSource();final Texture loadingScreenTexture = TextureFactory.createForTextureSourceSize(loadingScreenTextureSource);final TextureRegion loadingScreenTextureRegion = TextureRegionFactory.createFromSource(loadingScreenTexture, loadingScreenTextureSource, 0, 0);this.setScene(new SplashScene(this.getCamera(), loadingScreenTextureRegion));}
?

至此Engine初始化了Scene,并后续对Scene进行更新操作。

?

2.Engine主要做的操作:

??? SoundManager

??? MusicManager

??? BufferObjectManager

??? TouchController

??? FontManager

完成基础服务的初始化和注册操作。

?

?

?

?

读书人网 >移动开发

热点推荐