我创建了一个小游戏(只是xaml,而不是xna),这个游戏有4个xaml页面:MainPage,ChoseLevelPage,PlayingPage和ScorePage 我第一次玩,游戏运行平稳从MainPage - > ChoseLevelPage - > PlayingPage导航) 当级别完成时,它从PlayingPage - > scorePage - > MainPage导航清除WP8中的页面内存
但是第二次我选择了一个级别并播放(MainPage - > ChoseLevelPage - > PlayingPage),动作选择级别(来自ChoseLevelPage - > PlayingPage)需要这么长时间,并且PlayingPage中的游戏也很滞后,有时会使我的应用崩溃012 Playing DiaElement(Level级别的回放歌曲),DispatcherTimer(级别下降时间)以及StoryBoard在每2秒后重复(每次级别转换)
在OnNavigatedFrom事件中,我将mediaelement和storyboard设置为停止,但我只是不知道他们是否从内存中清除了(还有我在PlayingPage中使用的其他资源)?
void dispatcherTimer1_Tick(object sender, EventArgs e)
{
if (time > 0) // this variable cout the time left, decreased by 1 second
{
time --;
}
else // when "time" =0, stop the level and navigate to ScorePage
{
dispatcherTimer1.Stop(); // stop the dispatcher
NavigationService.Navigate(new Uri("/Pages/ScorePage.xaml", UriKind.Relative));
}
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
myStoryboard.Stop(); // stop the story board
meSong.Stop(); // stop the mediaelement
App.MyModel.PlayingSong = null; // set source of the medialement to null
base.OnNavigatedFrom(e);
}