1
我正在嘗試使用addSubview爲我的遊戲實現一個暫停菜單。但是,當我觸摸暫停按鈕時,視圖將在前一場景中顯示子視圖 - DTStartMenu場景,而不是實際的遊戲場景。 這裏是ViewController.m代碼:SpriteKit添加子視圖
-(void)viewDidLayoutSubviews{
[super viewDidLoad];
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [DTStartMenu sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
代碼在StartMenu.m
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
SKView * skView = (SKView *)self.view;
SKScene *gameScene = [DTGame sceneWithSize:skView.bounds.size];
gameScene.scaleMode = SKSceneScaleModeAspectFill;
// [self.view presentScene:gameScene transition:[SKTransition fadeWithDuration:1]];
[self.view presentScene:gameScene];
}
中的代碼DTGame.m
-(void) didMoveToView:(SKView *)view {
skview = (SKView*)self.view;
}
-(void)pauseGame{
CGRect rect = CGRectMake(90, 40, 300, 200);
pauseMenu = [[DTPauseMenu alloc] initWithFrame:rect];
[skview addSubview:pauseMenu];
}
有道理。工作。謝謝 ! – mihnea2kx