Hi, I'm developing a 2 player TVOS Game using Spritekit.
I have managed to detect a Game Controller by using the below method. However, it does not allow me to distinguish whether a press is coming from player 1 or 2?
I tried using self.gameController.playerIndex to detect player Index. It returns -1 for both Apple TV Remote and 3rd Party SteelSeries Game Controller.
Am I doing it the right way ? is there any other way of doing this ?
-(void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event{
NSLog(@"press come from game controller player Index: %ld with Vendor Name %@",(long)self.gameController.playerIndex, self.gameController.vendorName);
}-(void)controllerStateChanged
{
if ([[GCController controllers] count] > 0)
{
NSLog(@"controller connected");
self.controllerConnected = YES;
self.gameController = [GCController controllers][0];
if (self.gameController.extendedGamepad == nil)
{
self.controllerType = 1;
NSLog(@"controller type 1 connected");
} else
{
self.controllerType = 2;
NSLog(@"controller type 2 connected");
}
} else
{
self.controllerConnected = NO;
NSLog(@"no controller connected");
}
NSLog(@"number of controller connected is %ld",[[GCController controllers] count]);
}
-(void)setupGameController
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerStateChanged) name:GCControllerDidConnectNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerStateChanged) name:GCControllerDidDisconnectNotification object:nil];
[GCController startWirelessControllerDiscoveryWithCompletionHandler:^{
[self controllerStateChanged];
}];
}