SKScenes的问题。 我有两个SKScenes。两者都有一些静态节点。它们与不同的ViewControllers相关联。当我执行从Scene1到Scene2的转换(反过来)时,初始场景似乎被删除(.Dispose()方法被调用,它似乎根据调试输出重绘)。但是在经过2-3次转换后,FPS逐渐从30降到10或更低(!)。似乎场景仍在记忆中。我该怎么做才能妥善处理场景?
public override void ViewWillLayoutSubviews ()
{
base.ViewWillLayoutSubviews ();
var skView = (SKView)View;
if (skView.Scene == null) {
Console.WriteLine ("Scene is to be created");
skView.ShowsFPS = true;
skView.ShowsNodeCount = true;
// Create and configure the scene.
var scene = new MatchmakingView (skView.Bounds.Size);
scene.ScaleMode = SKSceneScaleMode.AspectFill;
// Present the scene.
skView.PresentScene (scene);
scene.OnToWaiting += _OnToWaiting;
scene.OnToMain += _OnToMain;
}
}
public override void ViewDidDisappear (bool animated)
{
base.ViewDidDisappear (animated);
var skView = (SKView)View;
var scene = (MatchmakingView)skView.Scene;
scene.OnToWaiting -= _OnToWaiting;
scene.OnToMain -= _OnToMain;
skView.RemoveFromSuperview ();
scene.Dispose ();
skView.Dispose ();
Console.WriteLine ("MMa removed");
}