3

I want create a Flip effect in swift with SKSpriteNode like this effect. I try this solution but before horizontal rotation we can see a vertical rotation. I just want a horizontal rotation like in example with HTML/CSS.

Community
  • 1
  • 1
gabrielpf
  • 312
  • 2
  • 12

2 Answers2

3

Solution for do flip with SKSpriteNode :

    func flipTile(node : RectSprite){

        let flip = SKAction.scaleXTo(-1, duration: 0.4)

        node.setScale(1.0)

        var changeColor = SKAction.runBlock( { node.texture = SKTexture(imageNamed: "blue")})
        var action = SKAction.sequence([flip, changeColor] )

        node.runAction(action)

}
gabrielpf
  • 312
  • 2
  • 12
0

The above code helped me create this function below in Swift 3. Note the minor syntax differences but still quite similar.

Could probably set the actions again as let variables and run them in [ ] too, but this was succinct enough for me.

func flipCard (node: SKNode, label: SKLabelNode)
        {
            label.isHidden = true

            node.run(SKAction.sequence(
                [SKAction.scaleX(to: 0, duration: 0.2),
                 SKAction.scale(to: 1, duration: 0.0),
                 SKAction.setTexture(SKTexture(imageNamed: "Redcard-blank")),
                 SKAction.fadeOut(withDuration: 2),
                 SKAction.fadeIn(withDuration: 2),
                 SKAction.fadeOut(withDuration: 2),
                 ]
            ))
            label.isHidden = false
        }
sf2k
  • 592
  • 2
  • 6
  • 25