I have a question about controlling player character(s). Currently Iâ€™m creating couch co-op game. Game supports 1 - 4 players. Iâ€™m trying to figure out how to make controls to function with all the player characters.
Currently my game setup is this: each players character is created from the same object (sprite). Object is called hitbox. This sprite has an instance variable called ID. On creation, first player will get ID nb 0, second player 1 and so on. ID is zero-based because gamepad idâ€™s are also zero-based. Key bindings are stored in an array. Then, when gamepad id (in this case, 0) is used, hitbox with the same ID is picked and action is fired (move left, move right, jump etc). I hope screenshot below will help to understand the basic concept.
https://www.dropbox.com/s/0n750btrpkbl7 ... 1.png?dl=0
This method isnâ€™t very effective because it requires that I copy-paste exactly same events for every characters. 4 times in my case. Not very convenient. So I want to make a system where controls events are set once (like in screenshot but without that PLAYER1 value) and then based on the gamepad id, matching hitbox is picked and movement/action is fired.
For example, I press A button on any controller, then C2 could tell me that button A is pressed from xyz gamepad. Letâ€™s take a look at event 117 (in screenshot) for example. â€œGamepad PLAYER1 right analog stickâ€¦â€, where PLAYER1 is replaced with correct gamepad id.
So, is there a way in C2 to determine which gamepad is used?