Cocossharp and xamarin.forms navigation
I have 2 pages. On the first page, when I click on one of the items in the list, it should go to the 2nd page, and here on the 2nd page the snow particles appear.
After that, when I click the back button as usual, it goes to the first page, and again when I click any list item, it moves to the second page, the snow particles disappear, It just shows a black screen.
Here are the codes:
For rendering snow, I have two classes
The first
public class SnowScene : CCScene
{
CCParticleSnow snow;
public SnowScene(CCGameView gameView) : base(gameView)
{
var layer = new CCLayer();
layer.Color=new CCColor3B(new CCColor4B(20,30,50,10));
snow = new CCParticleSnow(new CCPoint(490, 20));
snow.Position = new CCPoint(490 / 2, 800 + 1);
snow.StartColor = new CCColor4F(CCColor4B.White);
snow.EndColor = new CCColor4F(CCColor4B.Red);
snow.StartSize = 15f;
snow.StartSizeVar = 2f;
snow.EndSize = 8f;
snow.EndSizeVar = 1f;
snow.Speed = 5f;
snow.Gravity = new CCPoint(0.5f, -2);
snow.EmissionRate = 3.5f;
snow.Life = 50f;
layer.AddChild(snow);
this.AddLayer(layer);
}
}
Second
public class SnowyBackground : ContentView
{
SnowScene overallScene;
public SnowyBackground()
{
var sharpView = new CocosSharpView
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
sharpView.ViewCreated += (sender, e) =>
{
var ccGView = sender as CCGameView;
if (ccGView != null)
{
ccGView.DesignResolution = new CCSizeI(490, 800);
overallScene = new SnowScene(ccGView);
ccGView.RunWithScene(overallScene);
}
};
Content = sharpView;
}
}
And in Xaml on the second page Now when I click the list item on the first page (page 1) like below: Event handler for the Listview item on the first page -
async void Handle_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
{
try
{
await Navigation.PushModalAsync(new Page2(),false);
}
catch(Exception ex)
{ }
}
2nd page -
<?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:local="clr-namespace:Particle"
x:Class="Particle.ParticlePage">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<local:SnowyBackgroundView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.RowSpan="2" />
</Grid>
It goes to page 2 and it successfully shows the rendering of the snow. But when I repeat the same steps ... I mean if I click the back button on page 2 then it goes to page 1 and here when I click on the lictview item again it goes to the second page but it doesn't show the rendering of snow, just a black screen.
No one has answered this question yet
Check out similar questions: