SpriteKit动画第一次不起作用

时间:2017-08-02 16:16:04

标签: swift animation sprite-kit

我正在制作一个有动画的游戏,并且第一次加载应用时动画无效。但是,一旦我退出并再次打开应用程序,它就能完美运行。第一次发生了什么?

    override func didMove(to view: SKView) {
    /* Setup your scene here */
    background.position = CGPoint(x:0, y:0)
    addChild(background)

    TextureAtlas = SKTextureAtlas(named:"trumphappy")

    for i in 1...TextureAtlas.textureNames.count{
        var Name = "trumphappy\(i).png"
        TextureArray.append(SKTexture(imageNamed: Name))

    }
    HappyTrump = SKSpriteNode(imageNamed:"trumphappy1.png")
    HappyTrump.size = CGSize(width: 90, height: 150)
    HappyTrump.position = CGPoint(x: 5, y: 40)
    self.HappyTrump.zPosition = 1.0
    self.addChild(HappyTrump)


}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

    /* Called when a touch begins */
    for touch in touches {
        let location = touch.location(in: self)

        HappyTrump.run(SKAction.repeatForever(SKAction.animate(with: TextureArray, timePerFrame: 0.1)))
    }

0 个答案:

没有答案