0

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.

mat.b
  • 1
  • 1
  • Cannot reproduce. HandleViewCreated is called. Did you install nuget for ALL platforms? The common mistake people do is installing packages ONLY to portable library – Yuri S Nov 22 '16 at 21:10
  • Also I don't see your code for GameScene. It should be derived like that public class GameScene : CCScene and have a constructor public GameScene(CCGameView gameView) : base(gameView) – Yuri S Nov 22 '16 at 21:16
  • I do have the GameScene constructor, I skipped it however since the part where it is being invoked, and actually assigned is never called; and I actually do have both CocosSharp & CocosSharp.Forms installed for both project (PCL & (...).Droid) – mat.b Nov 23 '16 at 07:23
  • sorry, I cannot reproduce the error – Yuri S Nov 23 '16 at 14:39
  • Does it work for you? – Yuri S Nov 24 '16 at 23:23

0 Answers0