Objects with the same actions, how to not repeat

Get help using Construct 2

Post » Thu Jun 14, 2012 9:48 pm

Hello Everyone,

I am making a some style of fighting game, where at the initial screen you can select one of the 3 characters.

Then in the second screen I have a problem with the events, which basically consist that I am repeting every time the same actions.

For example:

If the character 1 is selected I have this:

Keyboard D is down---> sprite1: Simulate platform pressing right

Sprite1 have all the animations for the character selected.
But, the problem is if the user selected another character I will need to repeat the same code changing only the object:

Keyboard D is down --> sprite2: Simulate platform pressing right

This is because, the sprite2 have all the animations for that character.

So I am wondering if exist a way to reduce the events, and put the same in less events, and not repeating all this.

Because -for example - if I have 40 characters I will need to repeat again 40 times the same event, due the 40 sprite objetcs are different.

Any solution?

Thanks for your help
Best Regards,
Image
Image
B
26
S
2
G
1
Posts: 71
Reputation: 2,662

Post » Thu Jun 14, 2012 10:59 pm

put all your character objects under a family "Player" for example,

and then create all actions and events on this family, all character objects will inherit the events
ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028

Post » Fri Jun 15, 2012 12:30 am

hmm as i remember you can do all these with some tricks like make 1 sprite with all these animations like this :

player1_attack,
player2_attack,
player3_attack,
player1_moveleft,
.
.
.
.
and put a global variable that will help you to choose between 1,2,3...
B
48
S
15
G
6
Posts: 795
Reputation: 12,035

Post » Fri Jun 15, 2012 3:00 am

EDIT: Sorry, didn't see the previous post. Consider this just further explanation!

If you have the paid version, families sound like the way to go. If not,
you could have one character sprite with 3 times the animations, and swap the animations based on both the character number and the activity the character is performing. So the run animation for character 1 might be: run_1, while the run animation for character 2 might be run_2, and for character 3 it would be run_3. The idle animations would be idle_1, idle_2, idle_3, etc. Easy to implement since you'd just append the character number on to the end of the animation each time you switch animations.

kittiewan2012-06-15 03:03:28
B
29
S
11
G
12
Posts: 281
Reputation: 11,878

Post » Fri Jun 15, 2012 2:56 pm

Hello,

I just bought the Standard Edition, so yes, I have access to the families.
I was looking this, but I cannot figure how to inherit the actions and all stuff.
I'm referring specifically to what vtrix mentioned:

"put all your character objects under a family "Player" for example,
and then create all actions and events on this family, all character objects will inherit the events "

I don't know how to do it, can someone give me an example of this?

Thanks in advance.
Image
Image
B
26
S
2
G
1
Posts: 71
Reputation: 2,662

Post » Fri Jun 15, 2012 3:18 pm

On the right, in the "Projects" window, scroll down until you get to the "Families" folder. Right click it and select "Add family". Now you just add the objects you want in that family, and you choose the new family object when making the events in the event sheet.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452


Return to How do I....?

Who is online

Users browsing this forum: DiabloOvermind, emoticon, MrWhizm, Skebab, Yahoo [Bot] and 14 guests