我的播放器定义为SKSpriteNode,图片是GameScene中的Player1st.png
在StoreScene中我需要将Gamescene中Player的值从Player1st.png更改为Player2nd.png在我的Buy1函数中
答案 0 :(得分:0)
为什么不发布代码而不是图像?
<强>更新强> 在Player.swift上创建一个Player类:
class Player: SKSpriteNode {
//some properties
var maxLife: Int = 0
init (image: String) {
let texture = SKTexture(imageNamed: image)
super.init(texture: texture, color: nil, size: texture.size())
//other setting position score etc
}
class func Level1() -> Player {
let player = Player(image: "Player1st.png")
player.maxLife = 10
return player
}
class func Level2() -> Player {
let player = Player(image: "Player2st.png")
player.maxLife = 20
return player
}
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
StoreScene:
var player = Player.Level1()
func Buy1() {
player = nil
player = Player.Level2()
}