gpt4 book ai didi

ios - 当我的游戏在 sprite kit 中暂停时如何返回主场景

转载 作者:搜寻专家 更新时间:2023-11-01 05:37:26 27 4
gpt4 key购买 nike

当我暂停我的游戏时,我有一个暂停场景。

我放了 3 个按钮:

  • RateApp 按钮

  • BackToMain 按钮。

  • 继续游戏按钮。

会发生什么:

  • RateApp 按钮正常工作。

  • ResumeGame 按钮正常工作。

不工作:

  • BackToMain 按钮。

为什么?

因为我的游戏仍然暂停。

暂停游戏功能

func pauseGame() {
isPause = true
self.view?.paused = true
pointsLabel.hidden = true
BooCharacter.hidden = true
PauseButton.hidden = true
if #available(iOS 9, *) {
RecordButton.hidden = true
}

PauseScreen = SKSpriteNode()
PauseScreen.name = "PauseScreen"
PauseScreen.position = CGPointMake(self.size.width/2, self.size.height/2)
PauseScreen.color = UIColor.blackColor()
PauseScreen.alpha = 0.9
PauseScreen.size = CGSizeMake(1242,2208)
addChild(PauseScreen)


PauseLable.text = "Pause"
PauseLable.fontSize = 75
PauseLable.fontName = "Futura-Medium"
PauseLable.fontColor = UIColor(red:0.98, green:0.82, blue:0.32, alpha:1.0)
PauseLable.position = CGPoint(x: self.size.width/2, y: self.size.height/2 + 170)
addChild(PauseLable)


ContinueButton.name = "CountinueButton"
ContinueButton.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
ContinueButton.size = CGSizeMake(100, 100)
addChild(ContinueButton)

HomeButton.position = CGPoint(x: self.size.width/2 - 50, y: self.size.height/2 - 200)
HomeButton.size = CGSizeMake(70 , 70)
HomeButton.name = "HomeButton"
HomeButton.runAction(SKAction.moveToY(90, duration: 0.6))
HomeButton.removeFromParent()
addChild(HomeButton)


RateButton.position = CGPoint(x: self.size.width/2 + 50, y: self.size.height/2 - 200)
RateButton.size = CGSizeMake(70 , 70)
RateButton.name = "RateButton"
RateButton.runAction(SKAction.moveToY(90, duration: 0.6))
RateButton.removeFromParent()
addChild(RateButton)


}

更新:

    let scene = GameScene(fileNamed:"GameScene")
var HomeButton : UIButton!
var RateButton : UIButton!



override func viewDidLoad() {
super.viewDidLoad()

if (scene != nil) {
// Configure the view.
let skView = self.view as! SKView
//skView.showsFPS = true
//skView.showsNodeCount = true

/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
//skView.showsPhysics = true

NSNotificationCenter.defaultCenter().addObserver(self, selector: "goBack", name: "goBackClick", object: nil);

/* Set the scale mode to scale to fit the window */
scene!.scaleMode = .AspectFill

skView.presentScene(scene)
}
}

override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()

HomeButton.frame = CGRectMake(self.view!.frame.size.width/2 - 50, self.view!.frame.size.height/2 - 200, 70, 70)
HomeButton.setImage(UIImage(named: "HomeButtonPause.png"), forState: UIControlState.Normal)
HomeButton.addTarget(self, action: "pressedHomeButton", forControlEvents: .TouchUpInside)

RateButton.frame = CGRectMake(self.view!.frame.size.width/2 + 50, self.view!.frame.size.height/2 - 200, 70, 70)
RateButton.setImage(UIImage(named: "RateButtonPause.png"), forState: UIControlState.Normal)
RateButton.addTarget(self, action: "pressedRateButton", forControlEvents: .TouchUpInside)

self.view.addSubview(HomeButton)
self.view.addSubview(RateButton)
}

func pressedHomeButton(sender: UIButton!) {
//Back to main screen
SKTAudio.sharedInstance().playSoundEffect("Click Button Sound.mp3");
NSNotificationCenter.defaultCenter().removeObserver(self, name: "goBackClick", object: nil)
self.dismissViewControllerAnimated(true, completion: {
});

}

func pressedRateButton(sender: UIButton!) {
//Rate App
SKTAudio.sharedInstance().playSoundEffect("Click Button Sound.mp3");
UIApplication.sharedApplication().openURL(NSURL(string: "https://itunes.apple.com/us/app/boo-adventure/id1030047247?ls=1&mt=8")!) //add your link here
print("Rate App!")

}

我试图为我的 2 个按钮(主页按钮、评分按钮)创建 2 个 subview 我为它们创建了 UIButtons,但 Xcode 返回错误!

PauseGame 函数已更新!

   func pauseGame() {
isPause = true
GameViewController().ContinueGame()
pointsLabel.hidden = true
BooCharacter.hidden = true
PauseButton.hidden = true
if #available(iOS 9, *) {
RecordButton.hidden = true
}

PauseScreen = SKSpriteNode()
PauseScreen.name = "PauseScreen"
PauseScreen.position = CGPointMake(self.size.width/2, self.size.height/2)
PauseScreen.color = UIColor.blackColor()
PauseScreen.alpha = 0.9
PauseScreen.size = CGSizeMake(1242,2208)
addChild(PauseScreen)


PauseLable.text = "Pause"
PauseLable.fontSize = 75
PauseLable.fontName = "Futura-Medium"
PauseLable.fontColor = UIColor(red:0.98, green:0.82, blue:0.32, alpha:1.0)
PauseLable.position = CGPoint(x: self.size.width/2, y: self.size.height/2 + 170)
addChild(PauseLable)


ContinueButton.name = "CountinueButton"
ContinueButton.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
ContinueButton.size = CGSizeMake(100, 100)
addChild(ContinueButton)

GameViewController().viewWillLayoutSubviews()

}

最佳答案

试试这个让你回到 GameScene 的开始

func goToGameScene(){
let gameScene:GameScene = GameScene(size: self.view!.bounds.size) // create your new scene
let transition = SKTransition.fadeWithDuration(1.0) // create type of transition (you can check in documentation for more transtions)
gameScene.scaleMode = SKSceneScaleMode.Fill
self.view!.presentScene(gameScene, transition: transition)
}

如果这不起作用,请告诉我。

关于ios - 当我的游戏在 sprite kit 中暂停时如何返回主场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35225829/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com