I have 2 pages, In first page when I click one of the item in listview, it should navigate to 2nd page and here in 2nd page snow particles are appeared.
After that, when I click back button, as usual it goes to first page and again when I click any of the listview items it navigates to 2nd page snow particles disappear,It just show a black screen.
Here are the codes:
For snow rendering I have two classes
First one
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 one
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 in Second page Now When I click an Item of listview in first page(page1) like below: Event handler for Listview item click in 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 navigates to page 2 and it successfully shows snow rendering. But when I repeat same steps... I mean If I click back button in page 2,then it goes to page1 and here when again I click lictview item,it goes to second page, but it doesnot show snow rendering, just a black screen.