Repositório desenvolvido por:
- Afonso Lucas
- Eduardo Torres
- Felipe Rodrigues
- Gabriel Messias
- João Vitor
- Matheus Bispo
Tutoria de Marcos Morais, desenvolvido na Apple Developer Academy UCB.
É uma framework, desenvolvida pela Apple, cujo o objetivo é facilitar a implatação de controles (Joystick, Gamepad, etc) em aplicações(incluindo Games) feitos em swift ou objective-c.
- MicroGamepad:
- Gamepad:
- ExtendedGamepad:
Para o funcionamento da framework não se esqueça de importar:
import GameController
GCController.startWirelessControllerDiscovery { COMPLETION }
É importante saber se os controles estão conectados no device, para conseguir essa informação em tempo de execução precisamos configurar observers.
SUA_VARIAVEL_OBSERVER = NotificationCenter.default.addObserver(forName: NSNotification.Name.GCControllerDidConnect, object: nil, queue: .main) { (notification) in
if GCController.controllers().count > 0 {
CODIGO DE CONFIGURAÇÃO DO CONTROLE
}
}
OUTRA_VARIAVEL_OBSERVER = NotificationCenter.default.addObserver(forName: NSNotification.Name.GCControllerDidDisconnect, object: nil, queue: .main) { (notification) in
CODIGO DE SEGURANÇA CASO PERCA A CONEXÃO COM O CONTROLE
}
var controles = GCController.controllers()
if let extendedGamepad = connectedController.extendedGamepad {..}
if let gamepad = connectedController.gamepad {..}
if let microGamepad = connectedController.microGamepad {..}
Para cada botão do controle é preciso configurar uma ação, para isso usamos um handler.
gamepad.buttonA.pressedChangedHandler = {(button, value, pressed) in
AÇÃO DO BOTÃO
}
É importante sempre remover os observers no fim de uma aplicação.
NotificationCenter.default.removeObserver(SUA_VARIAVEL_OBSERVER)
NotificationCenter.default.removeObserver(OUTRA_VARIAVEL_OBSERVER)
Segue no repositório um exemplo de implatação de controles micro, standart e extended Gamepad, tanto no iOS quanto no tvOS.
- Apple Game Controller Framework Reference — @ Apple Doc
- Sobre Game Controllers — @ Apple Doc
- Usando o GameController na AppleTV
- Controlling Game Input For AppleTV, WWDC 2016
- How to Support External Game Controllers with Swift 2 and Sprite Kit for the New Apple TV
- Designing for Game Controllers WWDC 2014
- iOS 7 Game Controller Tutorial, em Objective-C, Rey
- Integrating with Game Controllers, WWDC 2013
- GCMotion