Top Banner
23

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

Jan 21, 2016

Download

Documents

Blake Norton
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .
Page 2: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Twist, Touch & TravelTouch, Twist, and Travel

Harnessing the iPhone's Unique Features

Glenda AdamsMaverick Software

www.mavericksoftwaregames.com

Page 3: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

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!

Page 4: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

iPhone Hardware

Accelerometer

Multi-touch display

Location awareness

Compass (3GS only)

Page 5: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Accelerometer

Detect device orientation

Game input (steer, swing, balance)

Alternate input (shake, flip)

Page 6: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

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

Page 7: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Accelerometer Setup:

- (void) setupAccelerometer

{

UIAccelerometer* accel = [UIAccelerometer sharedAccelerometer];

accel.updateInterval = 1.0f / kFrequency;

accel.delegate = self;

}

Delegate callback:(void)accelerometer:(UIAccelerometer*)accelerometer

didAccelerate:(UIAcceleration*)acceleration

{

// Get axis values

UIAccelerationValue x, y, z;

x = acceleration.x;

y = acceleration.y;

z = acceleration.z;

}

Page 8: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Simple low-pass filter to track gravity vector

static BOOL init = NO;static UIAccelerationValue xValue = 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! **

Page 9: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

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

Page 10: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Multi-touch display

Direct manipulation

Support multiple simultaneous touches

Gestures

Page 11: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Single touch sequence

Touch Began Touch Moved Touch Ended

Page 12: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Multi-touch sequence

Touch1 Began Touch1 Moved Touch2 Began

Touch2 Moved Touch2 Ended Touch1 Ended

Page 13: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

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;NSUInteger tapCount;NSTimeInterval timestamp;UIView* view;UIWindow* window;

Finding a touch location

UITouch* touch = [touches anyObject];CGPoint where = [touch locationInView:myView];

Page 14: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

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

Page 15: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

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

Page 16: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Data from Core Location

Latitude

Longitude

Altitude

Accuracy

Page 17: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Properties:BOOL locationServicesEnabled;

CLLocationAccuracy desiredAccuracy;

CLLocation * location;

Methods:- (void) startUpdatingLocation;

- (void) stopUpdatingLocation;

Delegate Methods:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error

Page 18: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Core Location tips Limit time between

startUpdatingLocation and stopUpdatingLocation

Handle loss/denial of location services

GPS drains battery fast!

Page 19: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Compass

Currently only on iPhone 3GS

Same x,y,z axis as accelerometer

Magnetic north vs True north

Part of Core Location framework

Page 20: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Compass specific Core Location Properties:BOOL headingAvailable;

CLLocationDegrees headingFilter;

CLHeading propertiesCLLocationDirection magneticHeading;

CLLocationDirection trueHeading;

CLLocationDirection headingAccuracy;

CLHeadingComponentValue x,y,z;

Methods:- (void) startUpdatingHeading;

- (void) stopUpdatingHeading;

Delegate Methods:

- (void) locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading

Page 21: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Compass tips Interference

Recalibration

True north only available if location is known

Page 22: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Recap

Use hardware features to make your game feel natural on the iPhone

Look at Apple sample code

Think Different

Page 23: Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software .

Twist, Touch & TravelTouch, Twist, and Travel

Harnessing the iPhone's Unique Features

Glenda AdamsMaverick Software

[email protected]

Q&A