This document describes how to add virtual keys to your game.
After integrating the SDK, you can load a configuration file to generate custom virtual keys dynamically.
TCRVKey.framework: The virtual key extension library.
API | Description |
---|---|
TCRVKeyGamepad initWithFrame:(CGRect)frame session:(TcrSession *)session; | Creates a virtual key view. |
TCRVKeyGamepad showKeyGamepad:(NSString *)cfg; | Loads the virtual key layout and generates virtual keys. |
TCRVKeyGamepad needConnected() | Queries whether the current key layout needs to be notified to the cloud. |
- (void)initControlViews {
self.gamepad = [[TCRVKeyGamepad alloc] initWithFrame:self.view.bounds session:self.session];
[self.view addSubview:self.gamepad];
[self.gamepad showKeyGamepad:[self readJsonFromFile:@"tcg_default_ps4"]];
}
Three types of keys are supported: mouse and arrow keys, keyboard, and controller.
-
Mouse buttons: Left button, middle button, right button, scroll-up, and scroll-down
-
Arrow keys: Up, down, left and right/W, A, S, and D Four common keys W, A, S, and D form arrow keys just like a D-pad on a controller. If the up direction is pressed, a message of the
W
key will be triggered. If a diagonal direction is pressed, its two adjacent keys will be triggered. Messages of the up, down, left, and right arrow keys are triggered in the same way.
- 78 commonly used keys on a physical keyboard
-
Left and right sticks
-
D-pad
-
General pressable buttons: A, B, X, Y, △, ☐, ×, ○, Select, Start, LB, RB, L3, and R3
-
Triggers: LT and RT (If a trigger is pressed, its message will be sent multiple times in a row instantly, and the message strength decreases gradually over time.)
A key layout file generation tool is provided here. The key layout configuration generated by this tool can be used by the SDK.
Note: You only need to save and import the generated configuration file for your game to use it with no need of caring about the content and generation rules in the file.