Skip to content

Game Integration (Central)

Rob Reuss edited this page Oct 7, 2017 · 2 revisions

GCController Replacement

VirtualGameController is designed to be a drop-in replacement for the Apple framework GameController (although both frameworks should be included because some GameController header references are required):

import GameController

becomes...

import GameController
import VirtualGameController

A framework file specific to your targetted platform must be used, and framework files are provided for each platform.

The interface for the controller class VgcController is the same as that of GCController, and for the most part an existing game can be transitioned by doing a global search that replaces "GCC" with "VgcC". There are some exceptions where GameController structures are used and these can be left as GC references:

GCControllerButtonValueChangedHandler
GCControllerDirectionPadValueChangedHandler
GCControllerElement
GCMicroGamepad
GCGamepad
GCExtendedGamepad
GCMotion

If you wish to test integration of the framework, it is proven to work with the Apple DemoBots sample project. One limitation is that when using the Apple TV version, you must use the Remote to start the game because of issues related to how DemoBots implements this functionality (see the last paragraph on that page).

For in-depth instructions on using DemoBots as a test, see the Wiki article, which also provide helpful hints on integrating VirtualGameController with your existing project.

Central versus Bridge

There are two types of Central app integrations and which result in dramatically different: Central and Bridge.

A Central is exactly what you expect in terms of game integration: your Central is your game and there should only be one implemented at a time.

A Bridge combines the behavior of a Central and a Peripheral; it is a Peripheral in relation to your Central, and it is a Central in relation to your Peripheral(s). Another name for it would be a controller forwarder, because it's primary function is to forward/relay values sent by one or more Peripherals to the Central. The Peripheral could be a MFi hardware controller, an iCade hardware controller, an Apple Watch or a software-based virtual controller (assuming the Bridge is deployed on an iPhone paired to the watch). If the bridge is implemented on a device with device motion support (an iOS device) the Bridge can extend the capabilities of a Peripheral to include motion support. For example, a MFi or iCade controller can appear to the Central to implement the motion profile.

Extended Functionality

There are a few features supported by a Central that exceed the capabilities of the Apple GameController framework:

Other

There is a method provided on instances of VgcController called controller.vibrateDevice that will vibrate an iPhone, and if a watch app is integrated with that phone, the vibrate request will be forwarded to the watch as well, resulting in haptic feedback (wrist click).