Switching between 2 separate Characters/Players

Get help using Construct 2

Post » Sat Feb 01, 2014 8:38 am

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 :)

B
5
Posts: 16
Reputation: 261

Post » Sat Feb 01, 2014 8:43 am

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", ...
B
17
S
8
G
4
Posts: 461
Reputation: 6,137

Post » Sat Feb 01, 2014 8:52 am

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.Paradox2014-02-01 09:02:53
B
226
S
60
G
33
Posts: 902
Reputation: 39,989

Post » Sat Feb 01, 2014 9:43 am

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.. ?
B
5
Posts: 16
Reputation: 261

Post » Sat Feb 01, 2014 7:21 pm

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.
Image
B
242
S
29
G
13
Posts: 1,787
Reputation: 18,685

Post » Sat Feb 01, 2014 7:22 pm

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.Paradox2014-02-01 20:39:41
B
226
S
60
G
33
Posts: 902
Reputation: 39,989


Return to How do I....?

Who is online

Users browsing this forum: ivanski1983, marcoscodas and 12 guests