There is an issue on last line. How can I fix that? Issue says ''Cannot convert value of type 'String' to expected argument type 'SKNode'. '' Here is my code :
import SpriteKit
let BallCategoryName = "ball"
class GameScene: SKScene {
    let ball = childNodeWithName(BallCategoryName) as! SKSpriteNode
You are using self before the object initialisation.
Infact writing this
let ball = childNodeWithName(BallCategoryName) as! SKSpriteNode
is equals to writing this
let ball = self.childNodeWithName(BallCategoryName) as! SKSpriteNode
But during the properties initialisation the current instance of GameScene does not exists yet! So there's no self yet.
And this is a good thing because if the compiled had allowed this code, it would have crashed at runtime since there is no ball node in you Scene yet (again because there is no Scene yet).
I suggest you to
ballCategoryNameballCategoryName into a stored propertyclass GameScene: SKScene {
    let ballCategoryName: String = "ball"
    var ball: SKSpriteNode? {
        return childNodeWithName(ballCategoryName) as? SKSpriteNode
    }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With