Multiple players with same sprites

0 favourites
  • 11 posts
From the Asset Store
Be quick and choose the right answer for the shown equation.
  • I'm looking to create a game similar to Super Smash Bros, where four players fight in an arena setting. The issue I'm wrestling with at the moment, however, is how to streamline the addition of new characters for up to four players.

    Ideally, there's a character select screen with a number of characters available and four players (using gamepads) can select whichever one they like (even the same one multiple times). The problem I'm having with this is I don't know how to create four copies of the player sprite that can each be controlled and animated separately by each controller.

    I could do this by copying the basic control/animation functions four times for every single character, but that seems insanely time consuming and terribly inefficient (I'll have to repeat the process each time I add another player). Is there a better way?

    The way it works in my head is that the number of the controls would be relative to which number player sprite is moving. I can set this for the controller movements by giving each of the four player sprites a "Controller" variable numbered 0-3 and then making a function referencing the "Player.Controller" variable (so one event works for all four controllers), however, I don't know how to make it figure out which player to move.

    As it stands, it seems like I can only pick a single object to create the action from, rather than making it use "Player(Controller.Player)" or something to that effect (so Player0 is moved when controller 0 is pressed, Player1 is moved when controller 1 is pressed, etc).

    Sorry if I didn't explain my issue well, I'm still pretty new to Construct. Can anyone understand my problem and maybe help me find a solution? It would be greatly appreciated, especially since I don't want to get too deep into working on other aspects of this game if I find out that local multiplayer isn't feasible. D:

  • EDIT: My topic name might be a bit misleading...I actually worked out half of the problem while typing that's some clarification:

    I've created four Player sprites (Player0, Player1, Player2, Player4) on a blank layout, made them global, and I create them as needed on the start of a stage. Each one has a "Controller" variable with the same number as in their names. I want to use a single block of actions for all four player characters by matching the gamepad number with the "Controller" variable from the corresponding Player sprite.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can spawn 4 instances of the same Object (player sprite) which have instance variable: playerNumber which you make sure is distinct for each player.

    You can then assign control to the instance of an Object that has playerNumber x.

  • Sorry, if they need to be 4 different sprites then that wont work. When you say controller? Is this 4 people with control pads on the same computer or over a network?

  • One thing that will really help you down the road is to create one player as a container object and add all of their health/score/UI info to the container as well. It will simplify things greatly down the road for you.

    Then each player will have different different animations based on which player they are actually playing eg: if you choose the red guy, you'd play the red guy set of animations. All animations would be stored in one player object.

    Then as you guessed, assign each player a variable that would equal which player they were on the keyboard/gamepad etc.

    Only the buttons associated with the particular player would trigger the appropriate player in the game.

    now if you want to get a bit fancy and save yourself programming duplicate version of the same code over and over you can use a function to do all the work for you.

    create a function and call it "punch" lets say.

    When you Call the function, you would tell it which player send the command,

    eg: call function "punch" (1) *<--player's controller name

    This number will be used as a parameter for the function to tell construct which player should initiate the punch animation

    On function "punch" (parameter)

    if function.param(0) = 1 then

    -> player 1 play animation punch

    if function.param(0) = 2 then

    -> player 2 play animation punch


    its kinda complicated, so lemme know if you have any questions

    use justifun to notify me that there's a reply

  • aceofpack

    Four controllers on one computer.


    Alright, I think Functions were exactly what I was looking for. I'm still not 100% sure how to use them properly, though. Here's a (hopefully) clearer version of what I have set up:

    I have four blank player sprites (named Player0, Player1, Player2, Player3) placed on a layer by themselves. Each one has a "Controller" variable to match their number (0-3).

    When a stage starts, it spawns as many of these player sprites as needed (Player0 for one player, Player0 and Player1 for two players, etc) and pins the selected character animation sprite to each (this might be another issue entirely, but I'm also not sure how to handle two players choosing the same character sprite).

    Now, I have events created for controls and animations, all referencing Player0. What I'd like to do, as opposed to copying these events for each player, is to have a single set that is smart enough to pick up on which controller is sending inputs and move the matching player sprite. I'll also have to set this up for animations and a dozen other things, but I think if I understand how to set it up for controllers, the knowledge will apply elsewhere.

    I'm going to play around with Functions a bit and see if I can get the desired result, but I thought I'd at least take a moment to clarify and thank you both for being so helpful. :D

  • Alright, I took a swing at functions...I'm not sure if I'm following your example correctly, but I don't know if this is going to save me all that much as far as copying events goes. Here's an example of what I've done so far:

    Is there a nicer way to clean this up? Otherwise it doesn't seem much more efficient than what I was doing already.

  • It would be great if you could use a string in Simulate Platform pressing " " ...

    You can make your Player0, Player1, Player2 and Player3 into a family "Players".


    left arrow is down - > Function: Call "Move" (Left)


    right arrow is down - > Function: Call "Move" (Right)


    Function: On "Move" -> Players: Set Facing to function.param(0)

                        -> Players: Set Movement to function.param(0)

    Only thing left is way to pick players, but it depends on your code.

    edit: you could use same function to controll everything - I change code above a little

  • Oh, okay. I think I'm starting to understand the usefulness of functions now. Passing Left/Right/etc to a Move function really cleans things up.

    As for referencing all players...Families are only available in the paid version, correct? I might have to invest. I think that's exactly what I'm looking for.

  • Hey Noisetank, check your inbox, we might be able to help each other

  • Unfortunately yes.

    It can be done without families quite easily. It just be more events to code.

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