我真的陷入了屏幕定位逻辑。
这是我的代码:
@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滑块480x854上尝试我的LWP时,一切正常,但仅限于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以处理两种模式 - 纵向和横向?
提前致谢!
答案 0 :(得分:1)
我对游戏有类似的问题,我在清单文件中的每个活动中解决了这一行的问题:
<activity
....
android:configChanges="orientation"
... />
并使用方法:
@Override
public void onResumeGame() {
super.onResumeGame();
}
@Override
public void onPauseGame() {
super.onPauseGame();
}
希望能解决您的问题,最好的问候。