-
Notifications
You must be signed in to change notification settings - Fork 14
iOS – Enable iCade controller support
iOS did not support usual game controllers before iOS 13. There's a semi-standard available for using normal Bluetooth controllers on iOS that are supported by 8Bitdo and iPega devices: the iCade mode. Basically, controllers in iCade mode pretend to be a Bluetooth keyboard and send key events. The iOS controller implementation can handle these events, but you need some more changes in your ios project. That's why iCade support is not enabled by default.
To enable iCade controller support, add the following line in your IOSLauncher
:
GdxGame game = new GdxGame() {
@Override
public void create() {
UIViewController uiViewController = ((IOSApplication) Gdx.app).getUIViewController();
IosControllerManager.enableICade(uiViewController, Selector.register("keyPress:"));
super.create();
}
}
return new IOSApplication(game, config);
This will call some iOS methods that will send all iCade key events to your game's view controller's keyPress
selector. The normal libGDX backend's view controller does not have such a selector. From 1.9.10 on, you can add it by defining a new MyUIViewController
class:
public class MyUIViewController extends IOSGraphics.IOSUIViewController {
protected MyUIViewController(IOSApplication app, IOSGraphics graphics) {
super(app, graphics);
}
@Callback
@BindSelector("keyPress:")
@TypeEncoding("v@:@:@")
public static void keyPress(UIViewController self, Selector sel, UIKeyCommand sender) {
IosControllerManager.keyPress(sender);
}
}
and inject it in your IOSLauncher
's createApplication()
method:
IOSApplication app = new IOSApplication(game, config) {
@Override
protected IOSGraphics.IOSUIViewController createUIViewController(IOSGraphics graphics) {
return new MyUIViewController(this, graphics);
}
};
return app;
Prior to 1.9.10, that's not possible.
That's a lot of effort, but you'll have a unique selling point for your game (that you are not allowed to list on the App Store). On the other hand, this feature might become less and less important in the future after iOS 13 and up have got a serious native game controller support.