Thursday 26 April 2012

Mouse Scroll Wheel in Cocos2d

Today, I felt a bit dim.  For ages, I'd had a nice little slider on the game which was used to zoom the map in and out.  On the iPad version, I use a gesture handler to zoom in and out with a pinch.  I couldn't quite work out how to do the same thing on the Mac.

I was thinking I'd have to do some tricky gesture handling, or worse still, just use the ugly slider.

After peering into the CCEventDispatcher header, however, I discovered the delegate method ccScrollWheel. Derrr...  How better to handle scrolling than using the scroll wheel!  Five minutes later and the map is now zooming nicely using the scroll wheel.  Nice and neat!  Just read the deltaX and deltaY properties to see which direction the scroll was in.

It just goes to show how rewarding it can be to look at the header files now and then...

No comments:

Post a Comment