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.
Asked
Active
Viewed 3,316 times
3
-
after flip should be same sprite? You can use an action with xScale to -1 it will flip the image – iamandrewluca Jul 27 '15 at 13:21
-
Here you can find how to do the flip http://www.raywenderlich.com/76718/card-game-mechanics-sprite-kit-swift – iamandrewluca Jul 27 '15 at 13:31
-
No I want to change my sprite during flip like flip tutorial of Ray Wenderlich. I try this late afternoon and I make you a feedback. Thank – gabrielpf Jul 27 '15 at 13:58
-
Thank, perfect work. I do my method in answer for next people. – gabrielpf Jul 27 '15 at 17:34
2 Answers
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