Object created event

Discussion and feedback on Construct 2

Post » Tue Jul 19, 2011 8:01 pm

I was wondering if there was an event for when objects are created during run time, like when I spawn a monster for example, if not could one be created or is there a specific way I'm supposed to get this info.

What I'm trying to do is but a health bar and unit info (name/lvl/etc) above the units sprite, so I need a way to get dynamically created content and create/attach specific objects to them.
B
11
S
6
G
1
Posts: 6
Reputation: 1,479

Post » Tue Jul 19, 2011 8:26 pm

when you create something it's automatically picked, so just do those actions immediately after it's created

if this won't work for some reason
make a function called CreateObject with the function object
and make the function both create the object, and do whatever it needs to do to them
Spriter Dev
B
88
S
21
G
12
Posts: 3,240
Reputation: 16,486

Post » Tue Jul 19, 2011 9:01 pm

Unfortunately there isn't a function object yet in C2 Lucid.
Nevertheless the first part of your answer is correct, creating an object gives it focus.

So CrAzD, when creating your "monster", you can modify its instance variables. Those will act as the unit info. Create a variable name, level, etc...
You can then access those as monster.name, monster.health, etc...

Your level bar will be another sprite I guess. Then after having created your monster sprite, you'll create your bar sprite.

Ashley said that C2 tries to pair objects by default. So the bar Sprite will depend of the monster sprite. (unless I'm still missing the point on this feature)

Creating the monster and the bar are actions done during the same event (whatever the event is: startup of layout, mouse click, ...)
Once you use the action system.create (object) said object has the focus, and you can set it as you like.Kyatric2011-07-19 21:02:35
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Tue Jul 19, 2011 9:08 pm

There's no function object in C2 yet, lucid :) The other way you said works, though. Any actions following a create or spawn action apply to the object that was created or spawned only. So there's no need for a "on created" event, really.

(Edit: ninja'd!)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,610

Post » Tue Jul 19, 2011 9:19 pm

oh. oops
I just clicked through the new posts thing, didn't bother to double check the forum
Spriter Dev
B
88
S
21
G
12
Posts: 3,240
Reputation: 16,486

Post » Tue Jul 19, 2011 10:25 pm

Ahh that makes sense and makes things a lot easier. I'll get to work and see how it works out, thanks for the info(s) lucid, Kyatric and Ashley xD!
B
11
S
6
G
1
Posts: 6
Reputation: 1,479


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 8 guests