Xamarin.Forms でレンダリングする CocosSharp の基本を使用して問題が発生しています。バージョン 1.7.1 の CocosSharp と Xamarin 2.3.2.127 を使用します。ViewCreated イベントは、CocosSharpView (コードから作成されたもの、または xaml から作成されたもの) に対してまったく呼び出されません。さらに、CCGameView への直接キャストはコンパイル エラーをスローします。
Error CS0039: Cannot convert type 'CocosSharp.CocosSharpView' to 'CocosSharp.CCGameView' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion
さらに、要素の直接キャストを CocosSharpView のViewCreatedイベントでのキャストに置き換えました。
private void HandleViewCreated(object sender, EventArgs e)
{
var gameView = sender as CCGameView;
if (gameView == null) return;
(...)
}
ただし、イベントが呼び出されることはなく、ビューがレンダリングされることもありません。私のxamlファイルは次のようになります:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:cf="clr-namespace:CocosSharp;assembly=CocosSharp.Forms"
x:Class="LocationTeacher.MainPage">
<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<cf:CocosSharpView x:Name="CocosView"
Grid.Row="0"
ResolutionPolicy="ShowAll"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
BackgroundColor="Transparent" />
<StackLayout Grid.Row="1">
<Button Text="Move Circle Left" />
<Button Text="Move Circle Right" />
</StackLayout>
</Grid>
</ContentPage>
と私のコードビハインド:
public partial class MainPage : ContentPage
{
private GameScene gameScene;
public MainPage()
{
InitializeComponent();
CocosView.ViewCreated += HandleViewCreated;
}
private void HandleViewCreated(object sender, EventArgs e)
{
var gameView = sender as CCGameView;
if (gameView == null) return;
(...)
}
}
誰も同じ問題に遭遇しましたか? (もしそうなら、どうにかしてそれを解決することができましたか?)
編集:解決策は確かに非常に簡単でした...これを言うのはばかげていますが、エミュレーターでハードウェアアクセラレーション (ホスト GPU の使用) を有効にしなかったようです。レンダリングがまったく行われませんでした...有効にすると、すべてが適切に動作するようにします。混乱して申し訳ありませんが、誰かが同様の問題に遭遇した場合に役立つ可能性があります.