我需要在Swift的另一个游戏场景中切换一个游戏场景中的图像

时间:2016-06-06 20:06:09

标签: ios image sprite-kit

我的播放器定义为SKSpriteNode,图片是GameScene中的Player1st.png

在StoreScene中我需要将Gamescene中Player的值从Player1st.png更改为Player2nd.png在我的Buy1函数中

http://i.stack.imgur.com/PKQbF.png

http://i.stack.imgur.com/s9vrn.png

1 个答案:

答案 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()
}