...work with many objects having same behaviour?

Get help using Construct 2

Post » Sun Mar 04, 2012 5:00 pm

With this example you guys shall understand my doubt:

Consider i have a platform with enemies. So, i have the main char and about 10 monters. I'll have some events to lower monster's hp, increase strenght, change abnorminal conditions, move it, etc etc. How to add this same behaviour to all monsters?

To who is a programmer, what i want to know is how to have some inheritance here. I want to have a "Monster" object which will have all standard behaviour, but for each instante created, i want to change it's image, hp, etc etc...Cassianno2012-03-04 17:01:55
English is not my native language. Sorry for any mistakes and feel free to correct me if needed.
B
14
S
5
G
3
Posts: 110
Reputation: 3,225

Post » Sun Mar 04, 2012 5:27 pm

This is nothing more or less than a picking issue. You can pick either one instance of you sprite, or the sprite as is; ie. all instances at once.

If you have an event, that has not picked one of your monsters and then you refer to the monster sprite, the changes will apply to all instances.

Pick a single instance by UID or IID or by an event like "on collision with" and the changes will only apply to this instance.Weishaupt2012-03-04 17:32:14
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Sun Mar 04, 2012 5:33 pm

No it's not Weis (unless i understood wrong): my point is having many different objects (sprites) but all of them having the same behaviour.

The picking all/random etc, doesn't help the poblem of having X events for every object type i have... you see?


Edit;

By the way, i just tought in some workaround... will try soon.Cassianno2012-03-04 17:34:42
English is not my native language. Sorry for any mistakes and feel free to correct me if needed.
B
14
S
5
G
3
Posts: 110
Reputation: 3,225

Post » Sun Mar 04, 2012 5:44 pm

[quote]No it's not Weis (unless i understood wrong): my point is having many different objects (sprites) but all of them having the same behaviour.[/quote]

sound's like a job for a family behaviors.

In meantime you could use variables to store some values and then apply them when needed to your behaviors - can take some events tohugh.
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Sun Mar 04, 2012 5:48 pm

shinkan, thanks for pointing out some directions... i'll read about families.

As i'm still testing the tool, i don't have this option enabled :P
English is not my native language. Sorry for any mistakes and feel free to correct me if needed.
B
14
S
5
G
3
Posts: 110
Reputation: 3,225

Post » Sun Mar 04, 2012 5:51 pm

So, what is the difference between your sprites if they all have the same behaviour?
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Sun Mar 04, 2012 5:58 pm

[QUOTE=Weishaupt] So, what is the difference between your sprites if they all have the same behaviour?[/QUOTE]

Basically, the atributes...

Imagine my example: the "Monster" object have events for losing hp, destroy the object when hp <= 0, walk, run, flee, attack, etc.
All those elements should be the same for all monsters, considering it's speed, size, hp, strenght, image/animations, etc etc. You see?


The "solution" so far that i tought is to have a monster object, with all monsters i have on single frames and an array containing it's default attributes, indexed by monsters image frame.

So on frame 1 have a turtle? on arrayMonstersInfo[1] i have turtle's data;
On frame 2 a dragon? arrayMonstersInfo[2] contains dragon's data, etc etc.

The problem here would be only the animations =/
English is not my native language. Sorry for any mistakes and feel free to correct me if needed.
B
14
S
5
G
3
Posts: 110
Reputation: 3,225

Post » Sun Mar 04, 2012 6:02 pm

to me, they are still all the same sprite, just with different values on their instance variables and different animations...
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Sun Mar 04, 2012 6:06 pm

I still don't see weis... hehe maybe i need a bit more practice with the tool.

Anyway, i think families are what i'm looking for: http://www.scirra.com/tutorials/46/introduction-to-families-for-construct-classic

What i couldn't find was a manual entrey for C2's families :X
English is not my native language. Sorry for any mistakes and feel free to correct me if needed.
B
14
S
5
G
3
Posts: 110
Reputation: 3,225

Post » Sun Mar 04, 2012 6:07 pm

Families are very new to c2
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Next

Return to How do I....?

Who is online

Users browsing this forum: spacedoubt and 2 guests