gpt4 book ai didi

ios - 如何为 skView 创建 socket ?

转载 作者:行者123 更新时间:2023-11-30 13:55:48 25 4
gpt4 key购买 nike

我遇到了与这里相同的问题:SpriteKit GameScene function won't add SKSpriteNode after being called by button .

我不明白答案。如何为 skView 创建 socket ?

非常感谢您给我带来的任何澄清!

这是我的代码:

在我的 GameScene.swift

   override func didMoveToView(view: SKView) {
loadMyView()
}

func loadMyView(){
currentScore = 0
loadSpecialView()
}

func loadSpecialView(){
Person = SKSpriteNode(imageNamed: "Person")
Person.size = CGSize(width:40, height: 7)
Person.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2 + 120)
Person.zRotation = 3.14/2
Person.zPosition = 2.0


self.addChild(Person)
}

当玩家死亡时,我的 GameviewController.swift 中会出现一个重新启动按钮,其中包含以下代码:

var currentGame: GameScene!

override func viewDidLoad() {
super.viewDidLoad()
currentGame = GameScene()

if let scene = GameScene(fileNamed:"GameScene") {
// 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

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

scene.viewController = self
skView.presentScene(scene)

}
}

@IBAction func restartGame(sender: UIButton) {
outBuy.hidden = true
outRestart.hidden = true
currentGame.loadMyView()

}

当我启动模拟器时,一切正常,并且添加了人员。当我按重新启动时,该人没有出现。发生了什么?

最佳答案

我找到了解决办法!最后 !

我将 currentGame = GameScene() 更改为 currentGame=scene 并将其移至 skView.presentScene(scene) 上方

关于ios - 如何为 skView 创建 socket ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33639347/

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