CCScene transition fails.

Hi!
I am using CocosSharp for Non-Game application.
I want to switch CCScenes. But, This code crashes.
Am I wrong about using CocosSharpView?

XAML:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="5*" />
        <RowDefinition Height="1*" />
    </Grid.RowDefinitions>
    <cf:CocosSharpView x:Name="CocosView" Grid.Row="0" />
    <Button Text="Transition" Clicked="ClickedTransitionButton" Grid.Row="1" />
</Grid>

C#:

public partial class MainPage : ContentPage
{
    private CCGameView gameView;

    public MainPage()
    {
        InitializeComponent();

        this.CocosView.ViewCreated += (sender, e) =>
        {
            gameView = sender as CCGameView;
            var scene = new CCScene(gameView);
            var layer = new CCLayerColor(CCColor4B.Blue);
            scene.AddLayer(layer);

            var background = new CCSprite("background.png", null);
            background.Position = new CCPoint(layer.ContentSize.Center.X, layer.ContentSize.Center.Y);
            layer.AddChild(background);

            gameView.RunWithScene(scene);
        };
    }

    private void ClickedTransitionButton(object o, EventArgs e)
    {
        CCTransitionJumpZoom newScene = new CCTransitionJumpZoom(3.0f, new NewScene(gameView));
        gameView.Director.ReplaceScene(newScene);
    }
}
public class NewScene : CCScene
{
    public NewScene(CCGameView gameView) : base(gameView)
    {
        CCLayer layer = new CCLayerColor(CCColor4B.Orange);
        this.AddLayer(layer);

        var human = new CCSprite("human.png", null);  // <--- Freeze!
        human.Position = new CCPoint(layer.ContentSize.Center.X, layer.ContentSize.Center.Y);
        layer.AddChild(human);
    }
}

Note:

  • CocosSharp Version 1.7.1
  • Not PCL, .NET Standard 2.0

Regards,

Sign In or Register to comment.