I'm trying to draw simple line from the point I started to tap and hold to the point I move my finger to. So it's always a simple line with starting and ending point. I tried different tutorials, but it draws nothing and I do not get any errors.
This is my code within GameScene.swift
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
if let touch = touches.first {
self.tapDown = true
self.firstPoint = touch.locationInView(self.view)
}
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.tapDown = false
self.firstPoint = CGPoint.zero
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = touches.first where self.tapDown {
let currentPoint = touch.locationInView(self.view)
let context = UIGraphicsGetCurrentContext()
CGContextSetStrokeColorWithColor(context, UIColor.redColor().CGColor)
let lines = [CGPointMake(self.firstPoint.x,self.firstPoint.y),CGPointMake(currentPoint.x,currentPoint.y)]
CGContextAddLines(context,lines,4)
CGContextStrokePath(context)
}
}
In ViewController.swift after viewDidLoad I put this:
UIGraphicsBeginImageContext(skView.frame.size)
Whats wrong here?