designing for game controllers - apple inc.€¦ · designing for game controllers session 611 jj...

123
© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. #WWDC14 Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games

Upload: others

Post on 10-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

#WWDC14

Designing for Game Controllers

Session 611 JJ Cwik Software Engineer

Graphics and Games

Page 2: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Game Controllers

Page 3: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

MFi Specification

For third-party controller vendors

Defines hardware requirements

Gives confidence controllers work for all games which support controllers

Page 4: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Game Controller Framework

Add controller support to your game

iOS and OS X

Simple API • Detect controllers

• Read inputs

One API for all controllers

Page 5: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Form-Fitting Standard Controller

Form-fitting • Encases device

• Touch, motion

Standard control layout • D-pad

• Buttons—A, B, X, Y

• Shoulder buttons—L, R

Page 6: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Form-Fitting Extended Controller

Form-fitting • Encases device

• Touch, motion

Extended control layout • D-pad

• Buttons—A, B, X, Y

• Shoulder buttons—L1, R1

• Thumbsticks

• Triggers—L2, R2

YX B

A

R2

R1L1

L2

Page 7: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Form-Fitting Extended Controller

Form-fitting • Encases device

• Touch, motion

Extended control layout • D-pad

• Buttons—A, B, X, Y

• Shoulder buttons—L1, R1

• Thumbsticks

• Triggers—L2, R2

YX B

A

R2

R1L1

L2L2 R2

Page 8: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Standalone Extended Controller

Standalone • Not attached to device

• Input only from controller

Extended control layout • D-pad

• Buttons—A, B, X, Y

• Shoulder buttons—L1, R1

• Thumbsticks

• Triggers—L2, R2

YX B

A

R2

R1

L2

L1

Page 9: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Standalone Extended Controller

Standalone • Not attached to device

• Input only from controller

Extended control layout • D-pad

• Buttons—A, B, X, Y

• Shoulder buttons—L1, R1

• Thumbsticks

• Triggers—L2, R2

YX B

A

R2

R1

L2

L1

Page 10: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Agenda

Overview

Finding controllers

Reading controller input

What’s new

Design guidance

Page 11: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Finding Controllers

Page 12: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

GCController

Main class

Same class for all controllers

Provides • Finding controllers

• Reading input

• Controller information

YX B

A

YX B

A

Page 13: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Finding Controllers

@interface GCController : NSObject + (NSArray *)controllers; ...

!

Currently-connected controllers

Array of GCController instances (empty if none)

Updated when controllers connect and disconnect

Page 14: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Finding Controllers

-application:didFinishLaunchingWithOptions: -setupControllers:

Page 15: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Finding Controllers

-application:didFinishLaunchingWithOptions: -setupControllers:

[GCController controllers]

Page 16: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Finding Controllers

-application:didFinishLaunchingWithOptions: -setupControllers:

[GCController controllers]Connect/ Disconnect

Page 17: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Finding Controllers

-application:didFinishLaunchingWithOptions: -setupControllers:

[GCController controllers]Wireless Discovery

Connect/ Disconnect

Page 18: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

-(BOOL)application:(UIApplication*)app didFinishLaunchingWithOptions:(NSDictionary*)dict { if ([GCController class]) { NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; !

[center addObserver:self selector:@selector(setupControllers:) name:GCControllerDidConnectNotification object:nil]; [center addObserver:self selector:@selector(setupControllers:) name:GCControllerDidDisconnectNotification object:nil]; !

[GCController startWirelessControllerDiscoveryWithCompletionHandler:^{...}]; }}

Finding Controllers

Page 19: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

-(BOOL)application:(UIApplication*)app didFinishLaunchingWithOptions:(NSDictionary*)dict { if ([GCController class]) { NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; !

[center addObserver:self selector:@selector(setupControllers:) name:GCControllerDidConnectNotification object:nil]; [center addObserver:self selector:@selector(setupControllers:) name:GCControllerDidDisconnectNotification object:nil]; !

[GCController startWirelessControllerDiscoveryWithCompletionHandler:^{...}]; }}

Finding Controllers

Page 20: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

-(BOOL)application:(UIApplication*)app didFinishLaunchingWithOptions:(NSDictionary*)dict { if ([GCController class]) { NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; !

[center addObserver:self selector:@selector(setupControllers:) name:GCControllerDidConnectNotification object:nil]; [center addObserver:self selector:@selector(setupControllers:) name:GCControllerDidDisconnectNotification object:nil]; !

[GCController startWirelessControllerDiscoveryWithCompletionHandler:^{...}]; }}

Finding Controllers

Page 21: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

-(BOOL)application:(UIApplication*)app didFinishLaunchingWithOptions:(NSDictionary*)dict { if ([GCController class]) { NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; !

[center addObserver:self selector:@selector(setupControllers:) name:GCControllerDidConnectNotification object:nil]; [center addObserver:self selector:@selector(setupControllers:) name:GCControllerDidDisconnectNotification object:nil]; !

[GCController startWirelessControllerDiscoveryWithCompletionHandler:^{...}]; }}

Finding Controllers

Page 22: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Finding Controllers

- (void)setupControllers:(NSNotification *)notification { // Get array of connected controllers self.controllerArray = [GCController controllers]; !

if ([self.controllerArray count] > 0) // Found controllers ... }

Page 23: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Finding Controllers

- (void)setupControllers:(NSNotification *)notification { // Get array of connected controllers self.controllerArray = [GCController controllers]; !

if ([self.controllerArray count] > 0) // Found controllers ... }

Page 24: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Finding Controllers

- (void)setupControllers:(NSNotification *)notification { // Get array of connected controllers self.controllerArray = [GCController controllers]; !

if ([self.controllerArray count] > 0) // Found controllers ... }

Page 25: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Finding Controllers

- (void)setupControllers:(NSNotification *)notification { // Get array of connected controllers self.controllerArray = [GCController controllers]; !

if ([self.controllerArray count] > 0) // Found controllers ... }

Page 26: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceGraceful connecting and disconnecting

When connected • Move to controller-based input

• Remove onscreen virtual controls (including pause button)

• Set playerIndex to illuminate player indicator LEDs

When disconnecting • Pause gameplay

• Return to regular controls

Page 27: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceTreat connected controller as intent to use

Page 28: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

YX B

A

Design GuidanceTreat connected controller as intent to use

Page 29: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceTreat connected controller as intent to use

YES NO

Game controller detected. Do you want to use it?

YX B

A

Page 30: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceTreat connected controller as intent to use

Page 31: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceTreat connected controller as intent to use

YX B

A

Page 32: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Reading Controller Input

Page 33: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceFirst design for touch

Multi-touch and motion Game controllers

Page 34: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Profiles

YX B

A

YX B

A

Page 35: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Profiles

myController.gamepad

myController.extendedGamepad

myController.gamepad

YX B

A

YX B

A

Page 36: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Gamepad Profile

Property Name Type

buttonA buttonBbuttonXbuttonY

GCControllerButtonInput

leftShoulder rightShoulder

GCControllerButtonInput

dpad GCControllerDirectionPad

leftThumbstick rightThumbstick

GCControllerDirectionPad

leftTrigger rightTrigger

GCControllerButtonInput

Face Buttons

Page 37: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Gamepad Profile

Property Name Type

buttonA buttonBbuttonXbuttonY

GCControllerButtonInput

leftShoulder rightShoulder

GCControllerButtonInput

dpad GCControllerDirectionPad

leftThumbstick rightThumbstick

GCControllerDirectionPad

leftTrigger rightTrigger

GCControllerButtonInput

Left Shoulder Right Shoulder

Page 38: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

D-Pad

Gamepad Profile

Property Name Type

buttonA buttonBbuttonXbuttonY

GCControllerButtonInput

leftShoulder rightShoulder

GCControllerButtonInput

dpad GCControllerDirectionPad

leftThumbstick rightThumbstick

GCControllerDirectionPad

leftTrigger rightTrigger

GCControllerButtonInput

Page 39: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

ExtendedGamepad Profile

Property Name Type

buttonA buttonBbuttonXbuttonY

GCControllerButtonInput

leftShoulder rightShoulder

GCControllerButtonInput

dpad GCControllerDirectionPad

YX B

A

Page 40: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

ExtendedGamepad Profile

Property Name Type

buttonA buttonBbuttonXbuttonY

GCControllerButtonInput

leftShoulder rightShoulder

GCControllerButtonInput

dpad GCControllerDirectionPad

leftThumbstick rightThumbstick

GCControllerDirectionPad

YX B

A

Left Thumbstick Right Thumbstick

Page 41: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

L2 R2

Left Trigger Right Trigger

ExtendedGamepad Profile

Property Name Type

buttonA buttonBbuttonXbuttonY

GCControllerButtonInput

leftShoulder rightShoulder

GCControllerButtonInput

dpad GCControllerDirectionPad

leftThumbstick rightThumbstick

GCControllerDirectionPad

leftTrigger rightTrigger

GCControllerButtonInput

R2

R1L1

L2

Page 42: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

ExtendedGamepad Profile

Property Name Type

buttonA buttonBbuttonXbuttonY

GCControllerButtonInput

leftShoulder rightShoulder

GCControllerButtonInput

dpad GCControllerDirectionPad

leftThumbstick rightThumbstick

GCControllerDirectionPad

leftTrigger rightTrigger

GCControllerButtonInput

R2

R1L1

L2

Page 43: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

ExtendedGamepad Profile

Property Name Type

buttonA buttonBbuttonXbuttonY

GCControllerButtonInput

leftShoulder rightShoulder

GCControllerButtonInput

dpad GCControllerDirectionPad

leftThumbstick rightThumbstick

GCControllerDirectionPad

leftTrigger rightTrigger

GCControllerButtonInput

R2

R1L1

L2

Page 44: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

GCControllerButtonInput

Classic button state BOOL pressed; // digital

Buttons are also pressure-sensitive float value; // analog, 0.0 to 1.0

Page 45: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

GCControllerButtonInput

Classic button state BOOL pressed; // digital

Buttons are also pressure-sensitive float value; // analog, 0.0 to 1.0

Page 46: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceObserve button conventions

A button—Primary action

B button—Secondary action

What are your game’s primary and secondary actions? • In-game (jump? shoot?)

• UI (accept, cancel)

YX B

A

Page 47: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceObserve button conventions

A button—Primary action

B button—Secondary action

What are your game’s primary and secondary actions? • In-game (jump? shoot?)

• UI (accept, cancel)

YX B

A

YX B

A

Page 48: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

GCControllerDirectionPad

Treated as four buttons GCControllerButtonInput *up, *down, *left, *right;

Or as two axes GCControllerAxisInput *xAxis, *yAxis;

Page 49: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

GCControllerAxisInput

Measures movement along an axis float value; // -1.0 to +1.0, neutral is 0.0

Minimum range is unit circle

Automatic calibration

Automatic dead-zone handling

+1.0

-1.0

-1.0 +1.0

Page 50: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceGroup logically-similar actions

YX B

A

Page 51: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceGroup logically-similar actions

YX B

A

Page 52: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceGroup logically-similar actions

YX B

A

Page 53: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceGroup logically-similar actions

YX B

A

Page 54: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

YX B

A

Design GuidanceGroup logically-similar actions

X BA

Page 55: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

YX B

A

Design GuidanceGroup logically-similar actions

Page 56: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

YX B

A

Design GuidanceGroup logically-similar actions

Page 57: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

YX B

A

Design GuidanceGroup logically-similar actions

Page 58: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

YX B

A

YB

A

Design GuidanceGroup logically-similar actions

Page 59: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceGroup logically-similar actions

YX B

A

Page 60: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceGroup logically-similar actions

YX B

A

Page 61: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceGroup logically-similar actions

YX B

A

Page 62: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Reading Input—Polling

-(void)readControls {

// Weapons if (myController.gamepad.buttonA.pressed)

[self fireLasers]; if (myController.gamepad.buttonB.pressed)

[self fireMissilesAtRate:myController.gamepad.buttonB.value]; !

// Thrust [self applyThrust:myController.gamepad.dpad.yAxis.value]; !

// Camera if (myController.extendedGamepad) {

// this is an Extended controller GCControllerDirectionPad *r = myController.extendedGamepad.rightThumbstick; [self freeLookX:r.xAxis.value Y:r.yAxis.value];

...

Page 63: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Reading Input—Polling

-(void)readControls {

// Weapons if (myController.gamepad.buttonA.pressed)

[self fireLasers]; if (myController.gamepad.buttonB.pressed)

[self fireMissilesAtRate:myController.gamepad.buttonB.value]; !

// Thrust [self applyThrust:myController.gamepad.dpad.yAxis.value]; !

// Camera if (myController.extendedGamepad) {

// this is an Extended controller GCControllerDirectionPad *r = myController.extendedGamepad.rightThumbstick; [self freeLookX:r.xAxis.value Y:r.yAxis.value];

...

Page 64: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Reading Input—Polling

-(void)readControls {

// Weapons if (myController.gamepad.buttonA.pressed)

[self fireLasers]; if (myController.gamepad.buttonB.pressed)

[self fireMissilesAtRate:myController.gamepad.buttonB.value]; !

// Thrust [self applyThrust:myController.gamepad.dpad.yAxis.value]; !

// Camera if (myController.extendedGamepad) {

// this is an Extended controller GCControllerDirectionPad *r = myController.extendedGamepad.rightThumbstick; [self freeLookX:r.xAxis.value Y:r.yAxis.value];

...

Page 65: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Reading Input—Polling

-(void)readControls {

// Weapons if (myController.gamepad.buttonA.pressed)

[self fireLasers]; if (myController.gamepad.buttonB.pressed)

[self fireMissilesAtRate:myController.gamepad.buttonB.value]; !

// Thrust [self applyThrust:myController.gamepad.dpad.yAxis.value]; !

// Camera if (myController.extendedGamepad) {

// this is an Extended controller GCControllerDirectionPad *r = myController.extendedGamepad.rightThumbstick; [self freeLookX:r.xAxis.value Y:r.yAxis.value];

...

Page 66: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Reading Input—Polling

-(void)readControls {

// Weapons if (myController.gamepad.buttonA.pressed)

[self fireLasers]; if (myController.gamepad.buttonB.pressed)

[self fireMissilesAtRate:myController.gamepad.buttonB.value]; !

// Thrust [self applyThrust:myController.gamepad.dpad.yAxis.value]; !

// Camera if (myController.extendedGamepad) {

// this is an Extended controller GCControllerDirectionPad *r = myController.extendedGamepad.rightThumbstick; [self freeLookX:r.xAxis.value Y:r.yAxis.value];

...

Page 67: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Reading Input—Polling

-(void)readControls {

// Weapons if (myController.gamepad.buttonA.pressed)

[self fireLasers]; if (myController.gamepad.buttonB.pressed)

[self fireMissilesAtRate:myController.gamepad.buttonB.value]; !

// Thrust [self applyThrust:myController.gamepad.dpad.yAxis.value]; !

// Camera if (myController.extendedGamepad) {

// this is an Extended controller GCControllerDirectionPad *r = myController.extendedGamepad.rightThumbstick; [self freeLookX:r.xAxis.value Y:r.yAxis.value];

...

Page 68: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Reading Input—Polling

-(void)readControls {

// Weapons if (myController.gamepad.buttonA.pressed)

[self fireLasers]; if (myController.gamepad.buttonB.pressed)

[self fireMissilesAtRate:myController.gamepad.buttonB.value]; !

// Thrust [self applyThrust:myController.gamepad.dpad.yAxis.value]; !

// Camera if (myController.extendedGamepad) {

// this is an Extended controller GCControllerDirectionPad *r = myController.extendedGamepad.rightThumbstick; [self freeLookX:r.xAxis.value Y:r.yAxis.value];

...

Page 69: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Reading Input—Events

Be notified when inputs change • Buttons

• Axes

• D-pad/thumbsticks

• Profiles

Register block as change handler

Page 70: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Reading Input—Events

Value changed handlers • For analog changes myController.gamepad.buttonY.valueChangedHandler

!

Pressed changed handlers • For digital changes myController.gamepad.buttonY.pressedChangedHandler

Page 71: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Reading Input—Events

Value changed handlers • For analog changes myController.gamepad.buttonY.valueChangedHandler

!

Pressed changed handlers • For digital changes myController.gamepad.buttonY.pressedChangedHandler

Page 72: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

myController.gamepad.buttonY.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed)

{ if (pressed)

// button pressed [self chargeSpeedBurst];

else // button released [self doSpeedBurst];

};

Reading Inputs—Events

Page 73: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

myController.gamepad.buttonY.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed)

{ if (pressed)

// button pressed [self chargeSpeedBurst];

else // button released [self doSpeedBurst];

};

Reading Inputs—Events

Page 74: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

myController.gamepad.buttonY.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed)

{ if (pressed)

// button pressed [self chargeSpeedBurst];

else // button released [self doSpeedBurst];

};

Reading Inputs—Events

Page 75: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

myController.gamepad.buttonY.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed)

{ if (pressed)

// button pressed [self chargeSpeedBurst];

else // button released [self doSpeedBurst];

};

Reading Inputs—Events

Page 76: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceUse pressure-sensitivity with discernment

Don’t use “value” if merely pressing an input is what’s needed • Use “pressed” instead

Take advantage of pressure-sensitivity • D-pad—360 degree movement

• Face Buttons—Pass and shoot with varying speed in sports games

Tell player when using pressure-sensitivity

Page 77: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceBe a good teacher

YX B

A

Page 78: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceBe a good teacher

Page 79: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceBe a good teacher

Page 80: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Agenda

Overview

Finding controllers

Reading controller input

What’s new

Design guidance

Page 81: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

What’s New

Page 82: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Forwarding

Use iPhone as wireless controller for another device

Works over Bluetooth or Wi-Fi

Both devices signed in to same iCloud account

Page 83: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Forwarding

Use iPhone as wireless controller for another device

Works over Bluetooth or Wi-Fi

Both devices signed in to same iCloud account

Page 84: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Forwarding

Page 85: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Forwarding

Page 86: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Forwarding

Page 87: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Forwarding

Page 88: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Forwarding

Controlling Leo’s Fortune

Page 89: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Forwarding

iPhone discovered automatically in [GCController startWirelessControllerDiscoveryWithCompletionHandler:^{...}]

Appears as wireless controller to your game

Page 90: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Motion Forwarding

Accelerometer and gyroscope data automatically forwarded

New profile @interface GCController : NSObject GCMotion *motion; ...

Page 91: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Motion ForwardingGCMotion

@interface GCMotion : NSObject GCAcceleration gravity; GCAcceleration userAcceleration; GCQuaternion attitude; GCRotationRate rotationRate; ...

+Y

+X+Z

Page 92: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Motion ForwardingGCAcceleration gravity

Vector which gravity is applying to device

Units are in G’s

Flat on table with screen up—(0, 0, -1)

!

typedef struct { double x, y, z; } GCAcceleration;

+Y

+X+Z

Page 93: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Motion ForwardingGCAcceleration userAcceleration

Inertial acceleration seen by device

Excludes gravity

Units are in G’s

At rest: (0, 0, 0)

+Y

+X+Z

Page 94: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Motion ForwardingGCQuaternion attitude

3D orientation of device • Yaw

• Pitch

• Roll

!

typedef struct { double x, y, z, w; } GCQuaternion;

+Y

+X+Z

Page 95: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Motion ForwardingGCRotationRate rotationRate

Rate at which device is spinning

Units are in radians/second

!

typedef struct { double x, y, z; } GCRotationRate;

+Y

+X+Z

Page 96: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Motion Forwarding

GCMotion *motionProfile = self.myController.motion; if (motionProfile) { // use controller’s motion profile } else { // use motion from device }

Page 97: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Motion Forwarding

GCMotion *motionProfile = self.myController.motion; if (motionProfile) { // use controller’s motion profile } else { // use motion from device }

Page 98: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Motion Forwarding

GCMotion *motionProfile = self.myController.motion; if (motionProfile) { // use controller’s motion profile } else { // use motion from device }

Page 99: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Motion Forwarding

GCMotion *motionProfile = self.myController.motion; if (motionProfile) { // use controller’s motion profile } else { // use motion from device }

Page 100: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Motion Forwarding

GCMotion *motionProfile = self.myController.motion; if (motionProfile) { // use controller’s motion profile } else { // use motion from device }

Page 101: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

+Y

+X+Z

Motion Forwarding

Motion axes move with device

Motion data will be jittery • Apply filter to smooth data

Page 102: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Motion Forwarding

Motion axes move with device

Motion data will be jittery • Apply filter to smooth data

+Y +X

+Z

Page 103: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Idle Timer

Prevents screen from turning off

iOS 8—Handled automatically

iOS 7—Handle yourself [[UIApplication sharedApplication] setIdleTimerDisabled:(BOOL)];

• Be careful

Motion apps should also manage their idle timer

Page 104: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Additional Guidance

Page 105: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Pause Button

Every controller has pause button

Treat as toggle

Handling required if support game controllers !

myController.controllerPausedHandler = ^(GCController *controller) { // Pause button pressed [self togglePauseResumeState]; };

Page 106: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Pause Button

Every controller has pause button

Treat as toggle

Handling required if support game controllers !

myController.controllerPausedHandler = ^(GCController *controller) { // Pause button pressed [self togglePauseResumeState]; };

Page 107: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Player Indicator LEDs

YX B

A

{

}

Always set for each controller your game uses if (self.myController.playerIndex == GCControllerPlayerIndexUnset) !

self.myController.playerIndex = 0; // Zero-based index

Page 108: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Player Indicator LEDs

YX B

A

{

}

Always set for each controller your game uses if (self.myController.playerIndex == GCControllerPlayerIndexUnset) !

self.myController.playerIndex = 0; // Zero-based index

Page 109: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceMultiple-controller games

Keep track of array of controllers • Set playerIndex for all controllers used

Consider which controller(s) can navigate menus

Determine whether game can proceed after a controller disconnects

Page 110: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceMultiple-controller games

- (void)setupControllers:(NSNotification *)notification { ... for (GCController *c in self.myControllers) { if (c.playerIndex == GCControllerPlayerIndexUnset) { [self launchControllerPicker]; break; } } ... }

Page 111: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceMultiple-controller games

- (void)setupControllers:(NSNotification *)notification { ... for (GCController *c in self.myControllers) { if (c.playerIndex == GCControllerPlayerIndexUnset) { [self launchControllerPicker]; break; } } ... }

Page 112: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceMultiple-controller games

- (void)setupControllers:(NSNotification *)notification { ... for (GCController *c in self.myControllers) { if (c.playerIndex == GCControllerPlayerIndexUnset) { [self launchControllerPicker]; break; } } ... }

Page 113: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceMultiple-controller games

- (void)setupControllers:(NSNotification *)notification { ... for (GCController *c in self.myControllers) { if (c.playerIndex == GCControllerPlayerIndexUnset) { [self launchControllerPicker]; break; } } ... }

Page 114: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceRespond to game controller inputs early

Players instinctively press buttons upon game launch

Responding early tells players your game supports controllers • Splash screens

• Introductory cinematics

• Main menu—at the latest

Page 115: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceRespond to game controller inputs early

Page 116: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceRespond to game controller inputs early

Page 117: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceRespond to game controller inputs early

Page 118: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Design GuidanceMechanize UI for controllers

Support standalone controllers • Screen (touch) may not be

easily reachable

• Game input from controller only

YX B

A

Page 119: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Summary

Overview

Finding controllers

Reading controller input

What’s new

Design guidance

Page 120: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

More Information

Allan SchafferGraphics and Game Technologies Evangelist [email protected]

Filip Iliescu Graphics and Game Technologies Evangelist [email protected]

Apple Developer Forums http://devforums.apple.com

Page 121: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Related Sessions

• What's New in SpriteKit Pacific Heights Wednesday 2:00PM

• Best Practices for Building SpriteKit Games Pacific Heights Wednesday 3:15PM

• What's New in SceneKit Pacific Heights Thursday 10:15AM

• Building a Game with SceneKit Pacific Heights Thursday 11:30AM

• Graphics and Games Location Sunday 0:00PM

• Core OS Location Sunday 0:00PM

• Special Events Location Sunday 0:00PM

Page 122: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For

Labs

• Game Controllers Lab Graphics and Games Lab B Friday 11:30AM

• Services Location Sunday 0:00PM

• Tools Location Sunday 0:00PM

• Media Location Sunday 0:00PM

• Graphics and Games Location Sunday 0:00PM

• Core OS Location Sunday 0:00PM

• Special Events Location Sunday 0:00PM

Page 123: Designing for Game Controllers - Apple Inc.€¦ · Designing for Game Controllers Session 611 JJ Cwik Software Engineer Graphics and Games. Game Controllers. MFi Specification For