Monogame Android - 如何将表面格式更改为Rgba8888的游戏视图

时间:2017-04-10 10:09:40

标签: xamarin.android monogame

我想在xamarin android中更改游戏视图的表面格式,以便在Android布局中获得对单一游戏背景的透明效果,但在转换为AndroidGameView时出现异常:

这是我的活动代码:

 public class Activity1 : Microsoft.Xna.Framework.AndroidGameActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            this.SetContentView(TestFBX.Resource.Layout.layout1);
            var gameWindowLayout = FindViewById<RelativeLayout>(TestFBX.Resource.Id.gameWindow);

            var game1 = new Game1();
            var game1View = game1.Services.GetService<View>();

            //Exception thrown here:
            game1View.JavaCast<OpenTK.Platform.Android.AndroidGameView>().SurfaceFormat = Android.Graphics.Format.Rgba8888;

            gameWindowLayout.AddView(game1View);
            game1.Run(GameRunBehavior.Asynchronous);                   
        }
    }

以下是例外:

System.InvalidCastException: Unable to convert instance of type 'Microsoft.Xna.Framework.MonoGameAndroidGameView' to type 'OpenTK.Platform.Android.AndroidGameView'.

我使用的是Monogame 3.5。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

事实证明,我必须引用OpenTK-1.0 dll而不是OpenTK。

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v7.0\OpenTK-1.0.dll