Passing input from multiple players to functions

0 favourites
  • 7 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • I am trying to create a local multiplayer game in which 2 players can provide input via keyboard/gamepads

    The game will eventually be fairly complex and the players will interact with various other sprites and can take a number of different states. The players will be made up of several sprites (using a container). To keep things organised I would like to change the player state based on keyboard input and then have the state changes call functions which trigger actions. These actions may impact certain sprites the players are made up of as well as the sprites the players are interacting with.

    In the simple CAPX below the layout with one player works fine, but the layout with two players is resulting in one player state overriding the other. Any suggestions appreciated.

  • I am not running the beta but latest stable, so I cant look.

    If a state is overriding another, it would not be illogical to say that one of the inputs is addressing the wrong player object.

  • See my event sheet below. I'm trying to support 2 or more players (using gamepads).


    Have uploaded an updated CAPX fie for anyone using r192.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I am using r190.

    But I think I see an issue there.

    event 4, that foreach, will accept the input given on that controller for the player it currently "for eaches"

    Separate it in individual events.

    ie, actually use:


    Gamepad Player.0 etc


    call move down (player 0)


    Gamepad Player.1 etc


    call move down (player 1)


    Something like those.

    You will end up with lots of single events, one for each controller action.

  • I was hoping to avoid creating separate events for each player's controller actions as there will be a large number of inputs (button combinations etc..). Is there any way I can dynamically support 1 to 4 players without having to create separate events for each controller?

  • I have made several games with controllers, even a few with more controllers ... but I always had to make separate events.

    You could have some groups with player actions/functions/controls disabled, and have an event for each controller which activates them.

    if gamepad.0 A is pressed activate group X

    if gamepad.1 A is pressed activate group Y


    if gamepad.0 A is pressed, set players to 1

    if gamepad.1 A is pressed, set players to 2

    and use the players value as a trigger for the loops for actions/functions etc.

  • You might use the Gamepad ID to pick the correct player.UID.

    For instance, if your player objects UIDs are 4 and 5, controlled by Gamepads 0 and 1, you could just pass the Gamepad ID whenever any button is pressed to the function and pick the instance Gamepad ID + 4 (4 for Gamepad 0 and 5 for Gamepad 1).

    Can't check it now, cause I have only one gamepad at work, but I believe it should work...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)