Create object on two different instances

Get help using Construct 2

Post » Tue Jun 16, 2015 10:42 pm

Hi there,

I'm making a top-down game and I'd like to have a little smoke particle effect for when the player starts running.

I can achieve that with these events:

Image

As seen on this gif:

Image

Now, the problem - in my game I have more than one player character. They're the same object and I've been using "pick" to pick the right instances.

Using this same piece of code, if I have 2 players, if one player is already running the smoke will never appear on the player that has just started running:

Image

This seems really simple but I could not get it to work. I've tried having a boolean variable on the player character and setting it to "true" whenever he's running, and if it was true, it would create the smoke sprite once - but it didn't work.

Anyone know how to deal with this?

edit: I forgot to mention that I have also tried using a "For each":
Image

But then this happens when both players are walking:
Image
B
124
S
43
G
41
Posts: 849
Reputation: 28,235

Post » Tue Jun 16, 2015 11:39 pm

Instead of using trigger once, cant you just add the smoke effect to the key press? Think that should solve it and you get rid of the checks every tick etc.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Tue Jun 16, 2015 11:44 pm

nimos100 wrote:Instead of using trigger once, cant you just add the smoke effect to the key press? Think that should solve it and you get rid of the checks every tick etc.


I thought of that but my entire key press events are after a loop... I have the same keypress events for all the players since they're the same object:

Image

So I would have to make more keypress events just for this, that would suck ):
B
124
S
43
G
41
Posts: 849
Reputation: 28,235

Post » Tue Jun 16, 2015 11:48 pm

Depends I would personally have made the key press on top level, just because they are "triggers" but that's just my way of doing it. But you can still do it if you add it to a function, then you can reuse your code if needed as well.

Function Create_Smoke
---- Pick sprPlayer.UID = Function.Param(0)
(Create smoke)

You then just pass the sprPlayer.UID to it and if you find out you would like enemies or whatever to create smoke as well you can just extend the function

Function Create_Smoke
---- Pick sprPlayer.UID = Function.Param(0)
(Create smoke)

---- Pick sprEnemy.UID = Function.Param(0)
(Create smoke)

From you code that should work as far as I can see.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Tue Jun 16, 2015 11:54 pm

Or you can add additional keys to your code without having to change anything. Just add "On key press" separately of the ones you are already using as these will only trigger once automatically.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Tue Jun 16, 2015 11:54 pm

@nimos100

Thanks for the help!

@7soul helped me out and did this:

Image

Now it works as intended. Spawning the object instead of creating it was the right way to go.
B
124
S
43
G
41
Posts: 849
Reputation: 28,235


Return to How do I....?

Who is online

Users browsing this forum: ST314 and 27 guests