Hi all, I'm new to swift and I've just gotten started by making a simple pong-like game using SpriteKit. I'm trying to use the scroll wheel input to spin an object, however, nothing seems to make this work. From my googling and AI advice the way I've been doing it should, as shown in the snippet below, however debugging suggests the scrollWheel function isn't even being called.
#if os(OSX)
extension GameScene {
override func scrollWheel(with event: NSEvent ) {
print("Scroll detected: \(event.scrollingDeltaY)")
let scrollDelta = event.scrollingDeltaY
self.rotatePaddle(value: scrollDelta)
}
}
#endif
I have changed the build targets in Xcode to Mac os, not the designed-for-ipad version of it, and the app does launch and draw sprites correctly as well as detect other mouse or trackpad inputs like mouseDown and rightMouseDown, so it only seems to be this one specific input not working. I've also tried hardware debugging like restarting Xcode and my Mac, but no luck there either. Maybe I've missed something or am doing it completely wrong, so any help would be much appreciated. Thanks heaps
Hello @Trellace,
Unlike mouseDown/mouseUp/mouseDragged, SKView does not forward scrollWheel events to its current scene.
There are many ways that you could get the desired behavior. If you want to manage all of the functionality in your scene, then you might want to subclass SKView and forward the scrollWheel events to the scene, for example:
final class MySKView: SKView {
override func scrollWheel(with event: NSEvent) {
scene?.scrollWheel(with: event)
}
}
Best regards,
Greg