我想在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。
有什么想法吗?
答案 0 :(得分:0)
事实证明,我必须引用OpenTK-1.0 dll
而不是OpenTK。
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v7.0\OpenTK-1.0.dll