1 / 23

Twist, Touch & Travel

Touch, Twist, and Travel Harnessing the iPhone's Unique Features. Twist, Touch & Travel. Glenda Adams Maverick Software www.mavericksoftwaregames.com. Your Mission: Stand out among 22,000 games. Feel like an iPhone app! Take advantage of the hardware Unique control schemes

lamya
Télécharger la présentation

Twist, Touch & Travel

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Touch, Twist, and Travel Harnessing the iPhone's Unique Features Twist, Touch & Travel Glenda Adams Maverick Software www.mavericksoftwaregames.com

  2. Your Mission:Stand out among 22,000 games • Feel like an iPhone app! • Take advantage of the hardware • Unique control schemes • Don’t just port!

  3. iPhone Hardware • Accelerometer • Multi-touch display • Location awareness • Compass (3GS only)

  4. Accelerometer • Detect device orientation • Game input (steer, swing, balance) • Alternate input (shake, flip)

  5. Accelerometer Interface • Provides X,Y,Z axis values • Updates via delegate callback, you set the frequency (up to 100 Hz) • Hardware is very sensitive, you must filter the data • Provide your own calibration

  6. Accelerometer Setup: - (void) setupAccelerometer { UIAccelerometer* accel = [UIAccelerometersharedAccelerometer]; accel.updateInterval = 1.0f / kFrequency; accel.delegate = self; } Delegate callback: (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration { // Get axis values UIAccelerationValuex, y, z; x = acceleration.x; y = acceleration.y; z = acceleration.z; }

  7. Simple low-pass filter to track gravity vector static BOOL init = NO; static UIAccelerationValuexValue = 0.0, yValue = 0.0, zValue = 0.0; if(!init) { // Get the initial value gravityX = acceleration.x; gravityY = acceleration.y; init = YES; } else { // Modify the intial value with the current one gravityX = (acceleration.x * 0.1) + (gravityX * 0.9); gravityY = (acceleration.y * 0.1) + (gravityY * 0.9); } ** Not accurate enough for a game controller! **

  8. Accelerometer Tips • For tilt controls, calibrate a “home” position at game start, pause/resume, start of a level, etc. • Delegate callbacks are not guaranteed exact timing. • View based orientation support: - (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation - (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation

  9. Multi-touch display • Direct manipulation • Support multiple simultaneous touches • Gestures

  10. Single touch sequence Touch Began Touch Moved Touch Ended

  11. Multi-touch sequence Touch1 Moved Touch2 Began Touch1 Began Touch2 Ended Touch1 Ended Touch2 Moved

  12. UIResponder Touch-related Methods - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event; - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent*)event; - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event; - (void)touchesCancelled:(NSSet *)touches withEvent: (UIEvent*)event; UITouch properties UITouchPhase phase; NSUIntegertapCount; NSTimeInterval timestamp; UIView* view; UIWindow* window; Finding a touch location UITouch* touch = [touches anyObject]; CGPoint where = [touch locationInView:myView];

  13. Touch tips • No API for gesture support • Size of touch area is 44x44, design UI accordingly • UITouch objects live across calls to TouchesBegan, Moved, etc. • Make sure to handle TouchesCancelled! • Handle multiple touches for complex multi-button virtual controls

  14. Location Awareness • Accessed via the Core Location framework • User can opt-out • All devices, not just GPS enabled. • GPS, <40 m • Wifi, <100 m • Cell Towers, 1km-3km

  15. Data from Core Location • Latitude • Longitude • Altitude • Accuracy

  16. Properties: BOOL locationServicesEnabled; CLLocationAccuracydesiredAccuracy; CLLocation * location; Methods: - (void) startUpdatingLocation; - (void) stopUpdatingLocation; Delegate Methods: - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocationfromLocation:(CLLocation *)oldLocation - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error

  17. Core Location tips • Limit time between startUpdatingLocation and stopUpdatingLocation • Handle loss/denial of location services • GPS drains battery fast!

  18. Compass • Currently only on iPhone 3GS • Same x,y,z axis as accelerometer • Magnetic north vs True north • Part of Core Location framework

  19. Compass specific Core Location Properties: BOOL headingAvailable; CLLocationDegreesheadingFilter; CLHeading properties CLLocationDirectionmagneticHeading; CLLocationDirectiontrueHeading; CLLocationDirectionheadingAccuracy; CLHeadingComponentValuex,y,z; Methods: - (void) startUpdatingHeading; - (void) stopUpdatingHeading; Delegate Methods: - (void) locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading

  20. Compass tips • Interference • Recalibration • True north only available if location is known

  21. Recap • Use hardware features to make your game feel natural on the iPhone • Look at Apple sample code • Think Different

  22. Touch, Twist, and Travel Harnessing the iPhone's Unique Features Twist, Touch & Travel Q&A Glenda Adams Maverick Software glenda@mavericksoftwaregames.com

More Related