【问题标题】:Andengine LWP screen orientation issueAndengine LWP 屏幕方向问题
【发布时间】:2012-12-18 17:23:33
【问题描述】:

我真的被屏幕方向逻辑困住了。

这是我的代码:

@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 预览模式下。例如,当我从横向 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 以处理纵向和横向两种模式?

提前致谢!

【问题讨论】:

    标签: java android andengine live-wallpaper


    【解决方案1】:

    我有类似的游戏问题,我在清单文件中的每个活动中修复了这一行的问题:

      <activity
            ....
            android:configChanges="orientation"
            ... />
    

    并使用方法:

            @Override
    public void onResumeGame() {
    super.onResumeGame();
    
    }
    
    @Override
    public void onPauseGame() {
    super.onPauseGame();
    
    }
    

    希望能解决您的问题,最好的问候。

    【讨论】:

    • 感谢您的回答!我已经有了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多