andEngine结构:
双线程:业务线程、渲染线程,使用ReentrantLock实现两个线程的交替执行。
渲染线程:使用GLSurfaceView提供的渲染功能,内置渲染绘图线程。
第一步:RenderSurfaceView为继承于GLSurfaceView的GL渲染视图,BaseGameActivity作为继承于Activity的活动,通过setContentView(RenderSurfaceView)将视图加入活动中。
BaseGameActivity中主要方法:
@Override
protected void onCreate(final Bundle pSavedInstanceState) {
if(BuildConfig.DEBUG) {
Debug.d(this.getClass().getSimpleName() + ".onCreate" + " @(Thread: '" + Thread.currentThread().getName() + "')");
}
super.onCreate(pSavedInstanceState);
//先处于暂停状态
this.mGamePaused = true;
//通过EngineOption定义,创建Engine
this.mEngine = this.onCreateEngine(this.onCreateEngineOptions());
//应用EngineOption定义到Activity
this.applyEngineOptions();
//添加RenderSurfaceView到Activity
this.onSetContentView();
}
protected void onSetContentView() {
this.mRenderSurfaceView = new RenderSurfaceView(this);
this.mRenderSurfaceView.setRenderer(this.mEngine, this);
this.setContentView(this.mRenderSurfaceView, BaseGameActivity.createSurfaceViewLayoutParams());
}
第二步:将渲染器EngineRenderer的加入RenderSurfaceView中,BaseGameActivity实现IRendererListener接口监听EngineRenderer。
EngineRenderer中的主要方法:
@Override
public void onSurfaceCreated(final GL10 pGL, final EGLConfig pEGLConfig) {
synchronized(GLState.class) {
final