《一夫一妻》手机跨平台项目在iOS上运行良好,但在Android上出现错误
本文关键字:运行 Android 错误 但在 iOS 一夫一妻 手机 项目 跨平台 | 更新日期: 2023-09-27 17:54:32
我最近一直在为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();
}
}
好的,我可以通过用下面的代码替换它来修复它
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();
}
}