I'm building a simple game and I want a "Square" to shoot from the left and side to the middle of the screen, where my "MainSquare" is. I'm using an NSTimer
and making this square shoot from the left to the center every second. Even though this NSTimer
has a purpose, running my "LeftShot" function, it's still coming up with the famous and annoying
"initialisation of variable 'timer' was never used".
Help? :(
in my did move to view:
var Timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("LeftShot"), userInfo: nil, repeats: true)
the function the timer runs every second:
func LeftShot(){
let EnemySquareLeft = SKSpriteNode(imageNamed: "Square2")
EnemySquareLeft.size = CGSize(width: 30, height: 30)
EnemySquareLeft.position = CGPoint(x: frame.width / 2 - 231, y: frame.height / 2)
let action = SKAction.moveTo(MainSquare.position, duration: 1)
EnemySquareLeft.runAction(SKAction.repeatActionForever(action))
self.addChild(EnemySquareLeft)
}