VC1内部:
@implementation HomeScreen
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)goToGame:(id)sender {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"GameScreen"];
[self presentViewController:vc animated:YES completion:nil];
} //This moves me to my VC2
VC2内部:
@implementation ViewController
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(presentMyViewController) name:@"presentMyViewController" object:nil];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
-(void)presentMyViewController
{
[self performSegueWithIdentifier:@"Segue" sender:nil];
}
连接到VC2的SKScene内部:
@implementation
{
int _lives;
BOOL _gameOver;
}
- (void)update:(NSTimeInterval)currentTime
{
if (_lives == 0 && !_gameOver) {
_gameOver = YES;
NSLog(@"You Lose!");
[self presentVC3];
}
-(void)presentVC3
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"presentMyViewController" object:nil];
}// This moves me to my VC3
VC3内部:
@implementation ViewController3
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)goToHomeScreen:(id)sender {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"HomeScreen"];
[self presentViewController:vc animated:YES completion:nil];
} // This move me back to VC1
VC1是一个UIViewController,VC2是一个ViewController,它呈现一个SKScene,这是我的实际游戏,而VC3是一个UIViewController。
所以只是重申一下。当我从VC移动到VC时,它们彼此重叠,增加了内存和CPU,降低了游戏的FPS(每秒帧数),直到最终崩溃。我被告知我需要解雇我的VC或从内存中释放它们来解决这个问题,如果这是正确的解决方案那么我该如何去做呢?如果您有正确的解决方案,请提供一些代码以提供帮助。任何帮助表示赞赏!
答案 0 :(得分:0)
我不太使用SK,但是SKView是一个UIView子类,你可以将场景放入其中。也许您正在寻找的设计使用单个视图控制器,只需切换它的SKView(或它的SKView场景)。
您正在使用的当前VC ...逻辑堆栈vcs,因此您将有一个艰难的时间(不可能)一次只保留一个。如果必须更改vcs,那么执行此操作的方法是在窗口的根视图控制器级别。