1
我真的卡在屏幕方向邏輯上。Andengine LWP屏幕方向問題
這裏是我的代碼:
@Override
public EngineOptions onCreateEngineOptions() {
this.cameraWidth = getResources().getDisplayMetrics().widthPixels;
this.cameraHeight = getResources().getDisplayMetrics().heightPixels;
this.camera = CameraFactory.createPixelPerfectCamera(this, this.cameraWidth/2.0F, this.cameraHeight/2.0F);
this.camera.setResizeOnSurfaceSizeChanged(true);
this.dpi = getResources().getDisplayMetrics().densityDpi;
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();
if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
screenOrientation = ScreenOrientation.LANDSCAPE_SENSOR;
} else {
screenOrientation = ScreenOrientation.PORTRAIT_SENSOR;
}
EngineOptions engineOptions = new EngineOptions(true,screenOrientation, new FillResolutionPolicy(), this.camera);
engineOptions.getAudioOptions().setNeedsSound(true);
return engineOptions;
}
@Override
public void onSurfaceChanged(final GLState pGLState, final int pWidth, final int pHeight) {
super.onSurfaceChanged(pGLState, pWidth, pHeight);
Log.i(TAG, "onSurfaceChanged " + "w: " + this.camera.getSurfaceWidth() + " h: " + this.camera.getSurfaceHeight());
this.cameraWidth = this.camera.getSurfaceWidth();
this.cameraHeight = this.camera.getSurfaceHeight();
this.camera.setCenter(this.cameraWidth/2.0F, this.cameraHeight/2.0F);
}
當我嘗試AVD 3.7英寸FWVGA滑塊我的LWP爲480x854一切工作正常,但只有在LWP預覽模式。例如 - 從Landscape LWP預覽模式中,按下按鈕「設置壁紙」,我將變換後的LWP顯示到另一半的桌面上。
此外,我已經注意到,當我們從Previos模式返回到桌面時,onCreateEngineOptions方法不會被調用。
此外,每次我在我的LWP中正確接收onSurfaceChanged事件。此外,我已經配置並可以處理屏幕方向更改事件...但如何將其應用於我的邏輯?
public BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent myIntent) {
if (myIntent.getAction().equals(BROADCAST_CONFIGURATION_CHANGED)) {
Log.d(TAG, "received->" + BROADCAST_CONFIGURATION_CHANGED);
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
Log.i(TAG, "LANDSCAPE_SENSOR");
} else {
Log.i(TAG, "PORTRAIT_SENSOR");
}
}
}
}
如何正確設置LWP以處理兩種模式 - 縱向和橫向?
在此先感謝!
感謝您的回答!我已經有了
alexanoid