all,
i thought this would be trivial so i threw this simple code against a couple of online converters, both crashed and burned on trying to convert this to swift 3.1
i pilfered this code somewhere, i forgot but it seems likely to work, i just want a simple SKTexture fadein/fadeout transition on a spritenode, is this too much to ask for? maybe.
-(void) fadeTexture:(SKTexture *)newTexture ontoSpriteNode:(SKSpriteNode *)referenceSpriteNode withDuration:(CFTimeInterval)duration {
SKSpriteNode * fadeInSprite = [self fadeInSpriteWithTexture:newTexture referenceSpriteNode:referenceSpriteNode];
[[referenceSpriteNode parent] addChild:fadeInSprite];
[fadeInSprite runAction:[SKAction sequence:@[
[SKAction fadeAlphaTo:1 duration:duration],
[SKAction runBlock:^{
[fadeInSprite removeFromParent];
[referenceSpriteNode setTexture:newTexture];
}]
]]];
}one site returned
/
Unexpected : :
Expected :
',', ';'
*/another site returned something reasonable but got lost in the "optional, opaque, escaping block wilderness"
// Converted with Swiftify v1.0.6402 - https://objectivec2swift.com/
func fade(_ newTexture: SKTexture, ontoSpriteNode referenceSpriteNode: SKSpriteNode, withDuration duration: CFTimeInterval) {
let fadeInSprite: SKSpriteNode? = self.fadeInSprite(with: newTexture, referenceSpriteNode: referenceSpriteNode)
referenceSpriteNode.parent?.addChild(fadeInSprite!)
fadeInSprite?.runAction(SKAction.sequence([SKAction.fadeAlpha(to: 1, duration: duration as? TimeInterval ?? TimeInterval()), SKAction.run({0:@escaping ()]))
}