A conceptual question...

For questions about using Classic.

Post » Mon Feb 23, 2009 11:02 pm

Hello everyone!
This is my first real question here in Construct forum, and while it's not a "How do I" question, I'm not sure if this is a good one. :P

Right now, I'm really enjoying Construct! It's so easy to understand! I'm already starting some personal projects on it, and so far everything ran smoothly.

However, I'm puzzled by how Construct checks its events. I'm no programming expert - only dealt with Actionscript 2.0 and a bit of LUA (for scripting and interface implementing). And I did something on Construct I didn't think would be correct, but in fact it worked perfectly! I'm sorry if this question sounds stupid, but I'm still learning the ropes here :)

Here's my doubt:


I've decided to test the particles on Construct, so I've created a BulletParticle at the X,Y of the GoodBullet (event 5). To make the particle follow the bullet, I've decided to simply attach the X,Y of the particle to the bullet, on the Always event (1).
This way, I expected to see probably just the first bullet with a trail, as it was placed offscreen... But I wasn't expecting for all the bullets to already come out with a particle attached!!! :D .

I noticed that once the bullets are out of the scenario, the particles go to 0,0 (because the bullet is dead, I get it). But I can't understand how Construct can check what bullet each particle should follow, as it's on a "Always" event, and it's not related to the whole "creating bullet" event.

If I were to create something like this on Flash, for example, I'd have to create instances for each of the bullet and particle, so that my particles knew which bullet they should follow. I know Construct is meant to be easy, but this is just too much! :lol:

Can anyone explain this to me?
Thanks in advance!

edit: Here's the CAP file: [url:1rgqrfx3]http://www.gammabeam.net/streetdefender_01.cap[/url:1rgqrfx3]
B
107
S
40
G
10
Posts: 456
Reputation: 13,202

Post » Mon Feb 23, 2009 11:36 pm

This is called object pairing. I think you'll find it useful!

When you run an action, it repeats the action once for each instance. For example:

+ Every 1000 ms
-> Sprite: spawn bullet

This will repeat the 'spawn' action once for each Sprite instance that exists, so if you have 5 sprites, 5 bullets spawn. (If the conditions involved 'Sprite' at all, then the action only applies to those which met the event, but when they aren't in the event, the action applies to all of them)

Similarly, when you say 'Set X', it repeats it for each instance. However, the value of 'GoodBullet.X' is not constant for the repetitions of the 'Set X' action. As it switches between instances of 'BulletParticle' running 'Set X', it also switches between instances of 'GoodBullet', kind of rotating round all the objects pairing them up. This means objects naturally just pair up together, which, more often than not, is useful.

By the way, you might benefit from putting 'GoodBullet' and 'BulletParticle' in a container.

Hope that helps :)
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Mon Feb 23, 2009 11:37 pm

A quick one before I head off to bed..

You can assign the particle to the bullet object through containers (there's a tutorial on the forum somewhere). That way, when a bullet is spawned or destroyed, the particle is too.

In events you'd have something like -

> ForEach BULLET
+ PARTICLE.x = BULLET.x
+ PARTICLE.y = BULLET.y

and so on..

> means it's an EVENT
and + means it's an ACTION

that was a quick sample and I'm sure someone will give a better one soon enough ;)

edit> seems Ashley beat me to it ;)
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Mon Feb 23, 2009 11:38 pm

Yeah I was wondering if they were both being destroyed because they were outside layout.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Tue Feb 24, 2009 12:23 am

Thanks for the explanation guys!
I think I get it... I'll try to search a bit further on this "pairing" feature, it sure seems useful!
I was starting to check on the containers, Ill study that too.

And now, just a question that came from your explanations... If I wanted to use a same sprite object, but I didn't want the second one to pair with the event (ex. Left and Right flippers of a pinball machine): How can I discriminate one sprite from the other? Do I have to duplicate the object and rename the copied one?

Also, if this is the kind of thing that's somewhere in the tutorials, please be rude and tell me to go look myself! I don't wanna be wasting nobodies' time :oops: :lol:
B
107
S
40
G
10
Posts: 456
Reputation: 13,202

Post » Tue Feb 24, 2009 2:27 am

Just use some kind of condition to pick one. You could have a private value set to "left" and "right" for each one, then have:

+ Shift pressed
+ Flipper value 'type' = "left"
: Do something with flipper

That'll only affect the one.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Tue Feb 24, 2009 11:06 am

Ah, so that's what the private variables are about!
Thanks! I expect to upload a version of the game soon! :D
B
107
S
40
G
10
Posts: 456
Reputation: 13,202

Post » Tue Feb 24, 2009 3:02 pm

[quote="gammabeam":insieiwi]Ah, so that's what the private variables are about![/quote:insieiwi]

They're about a whole lot more than just that. You can store whatever value you want, for whatever purpose you want.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests