我最近在MonoGame上为Android和iOS开发过一款游戏,它在iOS模拟器中运行良好,但是当我想在我的Android设备上运行它时,我得到了这3个错误
/Users/edward/Library/Mobile Documents/com~apple~CloudDocs/apps/Xamarin/Android/Radiant/Android/Activity1.cs(10,10): Error CS0272: The property or indexer `Microsoft.Xna.Framework.Game.Activity' cannot be used in this context because the set accessor is inaccessible (CS0272) (Radiant.Droid)
/Users/edward/Library/Mobile Documents/com~apple~CloudDocs/apps/Xamarin/Android/Radiant/Android/Activity1.cs(4,4): Error CS1502: The best overloaded method match for `Android.App.Activity.SetContentView(Android.Views.View)' has some invalid arguments (CS1502) (Radiant.Droid)
/Users/edward/Library/Mobile Documents/com~apple~CloudDocs/apps/Xamarin/Android/Radiant/Android/Activity1.cs(21,21): Error CS1503: Argument `#1' cannot convert `Microsoft.Xna.Framework.GameWindow' expression to type `Android.Views.View' (CS1503) (Radiant.Droid)
编辑:相关代码就在这里
public class Activity1 : AndroidGameActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Create our OpenGL view, and display it
Game1.Activity = this;
var g = new Game1();
SetContentView(g.Window);
g.Run();
}
}
答案 0 :(得分:1)
好的,我可以通过用此代码替换它来修复它
public class Activity1 : AndroidGameActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var g = new Game1();
SetContentView((View)g.Services.GetService(typeof(View)));
g.Run();
}
}