I am experimenting with how my game behaves in iOS 14 beta 6 with the new game controller customization feature. I'm on an iPhone 6s using a Horipad Ultimate controller and I have my controller customized as follows:
A Button (selected X)
R1 Button (selected A)
All other buttons are unselected (i.e. default, mapped to themselves)
In code, I log when a button is pressed:
Also, for each of these buttons I print what their current sfSymbolsName value is:
When I run my game, I see the following results:
But my question is, what's the proper way to figure out how a button is mapped so that I can display the correct button icon on screen?
In the scenario above, let's say my game expects to use the A button on the controller to have the character jump. In my code, I would check "[extendedGamepad buttonA].isPressed" and if it's true, assume the A button is pressed and do my jumping action. As the controls are mapped in my above example, pressing the physical A button on the controller would not cause a jump, nor would pressing the physical X button, but pressing the physical R1 button would cause a jump.
But I want to indicate to the user which button they should press to jump. On the one hand, I could assume the user knows how they remapped buttons and just always say "Press a.circle to jump". That seems a little unfriendly. The game should be able to tell that pressing R1 will actually cause the jump, so I should be able to say "Press r1.rectangle.roundedbottom to jump". The player sees the R1 symbol on the screen and knows to press the physical R1 button on their controller, and because of the mapping, when my code checks if the A button is pressed, it returns true.
But how do I determine that from the values I'm presented with? In code, the A button's sfSymbolsName tells me x.circle, which is not what I want. I'd have to scan through all the buttons in the extended gamepad object and find that the R1 button's sfSymbolsName returns a.circle, which could tell me that it's mapped to the A button. But then nothing actually returns the name I want, r1.rectangle.roundedbottom, so I have to have my own mapping to know that the R1 button uses that symbol name.
Is this the right way to do this? Is there another way I'm missing to have my game be able to show the symbol on screen that matches the physical button that's mapped for that control?
I looked at the other values on the button object, localizedName and aliases, and neither seem to help. localizedName returns the same as sfSymbolsName, and aliases returns names for the current button (in my scenario above, [buttonA aliases] returns "Button A", not the X button or the R1 button).
Thanks for any help you can provide!
A Button (selected X)
R1 Button (selected A)
All other buttons are unselected (i.e. default, mapped to themselves)
In code, I log when a button is pressed:
Code Block if ([extendedGamepad buttonA].isPressed) { NSLog(@"Button A pressed"); } if ([extendedGamepad buttonX].isPressed) { NSLog(@"Button X pressed"); } if ([extendedGamepad rightShoulder].isPressed) { NSLog(@"Button R1 pressed"); }
Also, for each of these buttons I print what their current sfSymbolsName value is:
Code Block NSLog(@"Button A symbol %@", [[extendedGamepad buttonA] sfSymbolsName]); NSLog(@"Button X symbol %@", [[extendedGamepad buttonX] sfSymbolsName]); NSLog(@"Button R1 symbol %@", [[extendedGamepad rightShoulder] sfSymbolsName]);
When I run my game, I see the following results:
Press physical button A on attached game controller: Game prints "Button X pressed"
Press physical button X on attached game controller: Game prints "Button X pressed"
Press physical button R1 on attached game controller: Game prints "Button A pressed"
"Button A symbol x.circle"
"Button X symbol x.circle"
"Button R1 symbol a.circle"
But my question is, what's the proper way to figure out how a button is mapped so that I can display the correct button icon on screen?
In the scenario above, let's say my game expects to use the A button on the controller to have the character jump. In my code, I would check "[extendedGamepad buttonA].isPressed" and if it's true, assume the A button is pressed and do my jumping action. As the controls are mapped in my above example, pressing the physical A button on the controller would not cause a jump, nor would pressing the physical X button, but pressing the physical R1 button would cause a jump.
But I want to indicate to the user which button they should press to jump. On the one hand, I could assume the user knows how they remapped buttons and just always say "Press a.circle to jump". That seems a little unfriendly. The game should be able to tell that pressing R1 will actually cause the jump, so I should be able to say "Press r1.rectangle.roundedbottom to jump". The player sees the R1 symbol on the screen and knows to press the physical R1 button on their controller, and because of the mapping, when my code checks if the A button is pressed, it returns true.
But how do I determine that from the values I'm presented with? In code, the A button's sfSymbolsName tells me x.circle, which is not what I want. I'd have to scan through all the buttons in the extended gamepad object and find that the R1 button's sfSymbolsName returns a.circle, which could tell me that it's mapped to the A button. But then nothing actually returns the name I want, r1.rectangle.roundedbottom, so I have to have my own mapping to know that the R1 button uses that symbol name.
Is this the right way to do this? Is there another way I'm missing to have my game be able to show the symbol on screen that matches the physical button that's mapped for that control?
I looked at the other values on the button object, localizedName and aliases, and neither seem to help. localizedName returns the same as sfSymbolsName, and aliases returns names for the current button (in my scenario above, [buttonA aliases] returns "Button A", not the X button or the R1 button).
Thanks for any help you can provide!