Switching between 2 separate Characters/Players

0 favourites
  • 6 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • Hello all,

    I am making a platform game with multiple characters.

    The user chooses the character in the first layout and then that character is used as the player in the next layout (Gameplay).

    Now, I've way too many events for the character sprite in the gameplay and I'd have to repeat each of those for the other character sprites.

    Layout 1: Character Selection.

    Click on a sprite which represent the character and load the next layout. (I've a variable set here "Character" which sets its value to 1, 2 or 3 according to which character the user chooses)

    Layout 2: Gameplay

    Here, if I have a different sprite for every character (each one having its own set of animations) I will have like 30 repeated events.

    What I'd like to have is, in this gameplay layout, I set this condition:

    On start of layout,

    If character=1, use Sprite1 as the character sprite (not sure how to implement this)

    If character=2, use Sprite2 as the character sprite

    Is there a way to achieve this, without repeating 60 events ?

    After doing a search here, I found I could use Object Family as a solution. I tried it, but I am not getting it to work right.

    I put those 2 sprites in a family "Players" and set a new instance variable "name" to it. Then I assigned 1 and 2 as values to "name" for sprite 1 and sprite2 respectively, thinking I might be able to use that to refer the members.

    But Now what ?

    I mean, there's still no way I could choose b/w the 2 members of that family and add that in those 30 events/actions.

    Please help :)

  • Well, you are not that far, don't be afraid.

    If both players are in a family and only one is on the layout when you play, then you just have to replace every use of the "Character 1" object by the family itself. You can do a right click->replace object for this.

    The "slow" part will be the behaviors you put on the character 1. For a complete "familization", you would need to have those behaviors on the family, not on player 1.

    If both players play the same, and only the animation set changes, this would be the solution.

    Another solution, dirty but working, is without families. Instead, you have a single sprite for both players, and rename all the animations with a prefix, like playerName. This would meant "Player1__Attack", "Player2__Attack", ...

  • Families should work, but it may be even easier for you to use one sprite with multiple animations inside it. All your character animations.

    Which animation is playing is determined by which character was chosen. It sets the animation to that character, and all the events still work because they all look at the same sprite. It just has a different animation playing.

    If you have something that changes the sprite's animation, it would check what sprite was chosen before setting which other animation to switch to. Walk1 or Walk2 which can be set like

    [Set Animation to "Walk" & CurrentCharacter]

    which would assemble the name of the animation with that chosen variable as part of the name.

    oops, Guizmus beat me to it.

  • Thanks a lot Guizmus and Paradox . The Object Family solution was nice, but the sprite animation thing was super easy, worked like a charm. I just had to add my variable to the animation name at all instances.

    I hope, there's nothing to worry about the performance of the game due to this.. ?

  • Nah. Only difference is the images for both players will be loaded at the start since they're in the same object, which isn't a big deal either.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I do it all the time. I don't think there's much difference between separate sprite animations and animations under one name.

    It used to be the only way before we had families in Constuct2.

    Heh, ninja'd again.

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