A new question about character selection (Solved)

Get help using Construct 2

Post » Tue May 22, 2012 6:18 am

There have been a lot of questions about character selection screens, but nothing that I can find about actually implementing multiple character choices in a game...

Here is a copy of the capx I am working with, and you can see that in the "Menu" group, the player selects a character, but each character has 4 or 5 different animations, and aside from creating each of the four characters as their own sprite with four copies of all of the events

For example:
-mob collides with playerbox
+player set animation to "ouch"

would have to tell all four character sprites to animate "ouch", wouldn't it?


How can I actually go about implementing multiple characters?

Thanks so much :)nihakue2012-05-22 16:18:24
B
5
Posts: 18
Reputation: 461

Post » Tue May 22, 2012 11:15 am

Probably the best way to do it is this:
You should already have an object "player" which is an invisible rectangle, and the "player_image" animations are stuck on top of that. If you don't have this, do it now, as it will save you a collision headache in the future.
Once you have done this, simply add and rename all of the animations in the player_image so you have something like this:

1_run
1_attack
1_walk
1_jump

Then you can just add the corresponding other character's animations in the same format.

2_run
2_attack
2_walk
2_jump

3_run
3_attack
3_walk
3_jump

etc.
Then, you should have a global variable called 'character' or something which will always be the number your character is at the moment.
Then, in your animations, instead of doing

set animation to: "run"

you can just

set animation to: character & "_run"

And that should work nicely.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Tue May 22, 2012 11:31 am

And what if the characters have different animations, so the hitboxes would be different?
B
15
S
2
G
3
Posts: 45
Reputation: 2,638

Post » Tue May 22, 2012 12:11 pm

You can always resize the invisible rectangle. Seriously, however, it is extremely important to have the invisible rectangle, unless you fancy yourself getting stuck in walls...
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Tue May 22, 2012 4:18 pm

[QUOTE=sqiddster] Probably the best way to do it is this:
[/QUOTE]

Oh my gosh, I was so close. Hahaha. If you look at the capx, I'm already doing the exact same thing in the menu events, it just never clicked that I could do that for animations. :) Thanks sqiddster. Also, as per the platform tutorial I am already using invisible player rectangles.

Once again, I love you C2 forums. :)

Edit: They should put this post in the sticky. I searched for ages, and it's such a simple/powerful demonstration of using variables in expressions. May be useful to other people jsut starting out in programming.nihakue2012-05-22 16:21:04
B
5
Posts: 18
Reputation: 461

Post » Tue May 22, 2012 5:26 pm

I am running into some trouble with the method described. I think it's a pretty simple syntax mistake on my part, but I have two players, and each one is a different instance of the "player" sprite, with their respective "player_images" instance pinned on top. The problem I have is picking the proper player_images when an instance of "player" is picked. I gave them both an instance variable, "player" which is either 1 or 2, but when player 1 runs into a mob, both player_images still flash.

Is there a simple way to give a particular instance of an object a preference for the player_images with the player instance variable which is the same as its own?

Here's the capx.

http://dl.dropbox.com/u/11790413/Final_Project.capx

Edit: Wait, I think I figured it out. lmao

This is what i did in pseudocode
- is condition
+ is action

-Player on collision with mob
-Player_Images.player = Player.player
    +actions go here

Seems to work ok. :)
nihakue2012-05-22 17:31:25
B
5
Posts: 18
Reputation: 461

Post » Tue May 22, 2012 5:56 pm

Glad I helped :D
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400


Return to How do I....?

Who is online

Users browsing this forum: austinblackbelt, Matthew de, Skebab, spcsmrf and 6 guests