Shake it all about
For Sir Lamorak’s Quest I’ve just implemented the settings page. I have a UIKit view containing slider controls etc slide up over the game view, pausing the game and allowing you to set the volume etc.
Rather than waste space on the game screen I decided today that I wanted to shake the phone during game play and have the settings appear. I knew that there was a new feature in OS 3.0 that would allow me to capture a shake with the SDK doing all the hard work.
I checked out the documentation and found that the following method could be used capture the gesture.
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.type == UIEventTypeMotion && event.subtype == UIEventSubtypeMotionShake) {
}
}
I quickly implemented this in my EAGLView class as this method is part of UIResponder and I therefore thought that it would be called inside a UIView class.
After much shaking of the device I was getting nothing. The method was not even firing. I went back to the docs and could not see what the problem was. I went to google and after a few minutes found the problem.
It would appear that the method above is only called from UIWindow, not UIView. Bit of a pain, but was soon sorted by creating my own class that inherited from UIWindow and adding just the class above to it. I then associated that class with the window in my IB file and bingo, shaking the phone now shows me my settings display. I’ve put some screen shots below of the game with and without the settings screen :o)


The graphics are still just place holders and I’m going to be theming the UIKit elements to fit in with the overall look of the game.
As it took me a while to figure out what the problem was I thought I would share. Hope it helps.
Mike




cybergreg on September 13th, 2009
Looks great Mike – can’t wait for the next tutorial
Greg