我试图让所有控制器知道这个功能,但我不知道如何将一个功能作为一个全局。
import AVFoundation
import Foundation
import SpriteKit
import GameKit
import UIKit
class GameScene: SKScene {
var SoundMute = SKSpriteNode()
override func didMoveToView(view: SKView) {
}
func CheckMusicMute() {
if InGameMusicOnOff == true {
SoundMute.texture = SKTexture(imageNamed: "SilverCircle.png")!
}
if InGameMusicOnOff == false {
SoundMute.texture = SKTexture(imageNamed: "RedCircle.png")!
}
}
}
答案 0 :(得分:0)
您可以使用您需要的方法创建自定义类,如下所示:
class MyScene: SKScene {
func CheckMusicMute() {
if InGameMusicOnOff == true {
SoundMute.texture = SKTexture(imageNamed: "SilverCircle.png")!
}
if InGameMusicOnOff == false {
SoundMute.texture = SKTexture(imageNamed: "RedCircle.png")!
}
}
}
然后让GameScene
延长MyScene
:
class GameScene: MyScene