0

To scroll a SKNode (called scroller) within a SKScene (called menuScene), I'm doing the following, which works perfectly but I'm not sure if it's the correct way to achieve this.

Within the NSViewController class, I'm overriding the scrollWheel event to call the scene's own scrollWheel event:

override func scrollWheel(with event: NSEvent) {
    skView?.scene?.scrollWheel(with: event)
    super.scrollWheel(with: event)
}

Then, within menuScene, the function is simply:

override func scrollWheel(with event: NSEvent) {
    scroller.position.x = scroller.position.x + (event.deltaX*3)
}

This works perfectly, but is there a better way to achieve the same goal?

Mateus
  • 357
  • 1
  • 4
  • 14
  • Does this answer your question? [Detect scroll wheel movement and direction](https://stackoverflow.com/questions/20857969/detect-scroll-wheel-movement-and-direction) – Willeke Jan 26 '23 at 22:14
  • 1
    Asking "is there a better way" is of topic on StackOverflow. If there is no problem you can try CodeReview. – burnsi Jan 28 '23 at 21:06
  • 1
    If you are going to post this on code review, please read [How do I ask a good question?](https://codereview.stackexchange.com/help/how-to-ask) and [A guide to Code Review for Stack Overflow users](https://codereview.meta.stackexchange.com/questions/5777/a-guide-to-code-review-for-stack-overflow-users/5778#5778). – pacmaninbw Jan 28 '23 at 22:34

0 Answers0