0

While using swift playgrounds on macOS i am trying to detect a mouse click however it is not working. Here is my code...

func mouseDown(theEvent : NSEvent) {
print("left mouse")
}

i can't use override func because it will give me an error and I'm not sure if the fact that this is not in a class that inherits NSViewController. If I must use an NSViewController could you tell me how to update the values of variables in another class. Could someone please help?

Tim2799
  • 71
  • 1
  • 1
  • 10
  • To do mouse down event detection, you have to have a view on which you'd be clicking. And Swift playgrounds normally execute once and stop - they do not wait around for user actions or events. You have to specially set up playgrounds for that. Have you done this? If not, and you don't know how to, you might want to consider testing your code in a regular project? – Fahim Mar 22 '17 at 23:32
  • http://stackoverflow.com/questions/31931403/getting-mouse-coordinates-in-swift/31932049#31932049 – Leo Dabus Mar 23 '17 at 00:34
  • The mouse down function ended up working when i made a class that extended to SKScene. – Tim2799 Mar 25 '17 at 21:34
  • Ok now i can get the location of the mouse however when i click on an SKNode it doesn't register as a touch. Why is that – Tim2799 Mar 26 '17 at 20:42

0 Answers0