【问题标题】:MonoGame Mobile Cross Platform Project Works Fine on iOS but throws errors on Android?MonoGame 移动跨平台项目在 iOS 上运行良好但在 Android 上抛出错误?
【发布时间】:2016-07-03 19:15:23
【问题描述】:

我最近一直在 MonoGame for 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();
    }

}

【问题讨论】:

  • Game1.active = this
  • 下一行为 game1 创建对象是否正确?

标签: c# android ios xamarin monogame


【解决方案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();
    }
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-11
  • 1970-01-01
  • 1970-01-01
  • 2020-07-02
相关资源
最近更新 更多