I'm having an issue using the very basis of CocosSharp - rendering with Xamarin.Forms. Having CocosSharp in version 1.7.1 and Xamarin 2.3.2.127. ViewCreated event is not called at all for my CocosSharpView (either created from code, or from xaml). What is more, direct casting to CCGameView throws compilation error:
Error CS0039: Cannot convert type 'CocosSharp.CocosSharpView' to 'CocosSharp.CCGameView' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion
Furthermore, I replaced direct element cast to casting in a CocosSharpView ViewCreated event:
private void HandleViewCreated(object sender, EventArgs e)
{
var gameView = sender as CCGameView;
if (gameView == null) return;
(...)
}
However, the event is never called, the view is never rendered. My xaml file looks as follows:
<?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>
and my code behind:
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;
(...)
}
}
Anyone encountered the same issue? (And managed to resolve it, if so - then how?)
EDIT: The solution was quite straightforward indeed... It's stupid to say this, but apparently I did not enable hardware acceleration (use of host GPU) in my emulator, hance the rendering did not occur at all... When enabled everything seems to work properly. Sorry for the confusion, however it could prove helpful if anyone encounters similar issue.