Why am I getting the error "Can't find location in scope"?

Viewed 71

I'm getting an error 'Cannot find "location" in scope on line 45. Any ideas how to fix it?

I have fixed these cannot find in scope errors before, but this one is really stumping me here.

class GameScene: SKScene {

    var Mainball = SKSpriteNode(imageNamed: "Ball")

    override func didMove(to view: SKView) {
        
        Mainball.size = CGSize(width: 100, height: 100)
        Mainball.position = CGPoint(x:frame.width / 80, y:frame.height / 80)
        self.addChild(Mainball)
        
    }
    func touchDown(atPoint pos : CGPoint) {
        
    }
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

        
        for t in touches { self.touchDown(atPoint: t.location(in: self))
           
        }
       
       
        let smallball = SKSpriteNode(imageNamed: "Ball")
        
        smallball.position = Mainball.position
        smallball.size = CGSize(width: 30, height: 30)
        smallball.physicsBody = SKPhysicsBody(circleOfRadius: smallball.size.width / 2)
        smallball.physicsBody?.affectedByGravity = true
        self.addChild(smallball)
        
        
        var dx = CGFloat(location.x - Mainball.position.x)
    }
    
    override func update(_ currentTime: TimeInterval) {
        // Called before each frame is rendered
    }
}
0 Answers
Related