Rather than do this:
I would like to grab the texture in the call to create the SKSprite. I know I'm supposed to use closures, yet I am unable to figure out the proper syntax.
Am looking for something like:
Have tried as many variants as I can think of but never get to the point where I can compile.
If the closure is something that I must predefine, then there's no point in trying this.
Code Block let skTexture = SKTexture(imageNamed: "slot") let mySlot = SKSpriteNode(texture: skTexture, color: .clear, size: slotSize)
I would like to grab the texture in the call to create the SKSprite. I know I'm supposed to use closures, yet I am unable to figure out the proper syntax.
Am looking for something like:
Code Block let mSlot = SKSpriteNode( {texture: SKTexture(imageNamed: "slot") -> (SKTexture)} color: SKColor.clear, size: mySlotSize)
Have tried as many variants as I can think of but never get to the point where I can compile.
If the closure is something that I must predefine, then there's no point in trying this.
It is not alwaysa great idea to try to cram everything in a single line…
Anyway, texture parameter is a SKTexture, not a func nor a closure.
But there is a simple way to achieve your goal:
Anyway, texture parameter is a SKTexture, not a func nor a closure.
But there is a simple way to achieve your goal:
Code Block let mySlot = SKSpriteNode(texture: SKTexture(imageNamed: "slot"), color: .clear, size: slotSize)