How do I spawn an object ONCE on mouse button down

Just started using Construct 2? Post your questions here

Post » Mon Aug 31, 2015 1:46 pm

Hi all

Loving my first day in Construct 2.

I have a spaceship thrusting around a star field using physics, and I want to show the afterburner sprite when the mouse is down.

I tried spawning it on an image point on the spaceship graphic, but of course, this spawns on every frame the mouse button is down, quickly spawning hundreds of afterburners :)

How would I approach this so that the afterburner graphic is visible when mouse is down and invisible when mouse is up, and still follow the spaceship around? I was going to resort to a separate sprite (one spaceship with thrust and one without), but wondered if it could be done in events by instantiating the object

Thanks in advance
Posts: 1
Reputation: 152

Post » Mon Aug 31, 2015 3:02 pm

Is your afterburner object a sprite? If so, just do something like

-->Is mouse down, afterburner opacity<100-------set opacity to Self.Opacity+300*dt
-->Else, afterburner opacity >0-------set opacity to Self.Opacity-300*dt

That will make it fade in and out where 300 is the speed. If your object is a particle object, just set the firing rate to something when the mouse is down and 0 when it isn't. I wouldn't recommend creating and destroying your afterburner object every time you click, though.
Posts: 962
Reputation: 18,026

Post » Wed Sep 02, 2015 2:11 pm

Add the System Condition "Trigger once while true" to the end of the event where you spawn the particle system. It must be the last condition in the event.

Mouse is down && Trigger once while true -> visible

Mouse is down (inverted) && trigger once while true -> invisible

Alternatively use the onMouse pressed and released events, they only trigger once.
Posts: 48
Reputation: 910

Post » Wed Sep 02, 2015 6:26 pm

I did this before actually

On Start of Layout Pin the Burner to the ship.
Preset the burner invisable.

On Left Mouse button down >> Set Burner Visable
Invert On Left Mouse button down >> Set burner Invisable.
Posts: 116
Reputation: 2,797

Post » Fri Sep 04, 2015 5:56 am

Yes leaving it invisible and simply turning it visible while Mouse is down will be the easiest. And you can set it to play a animation while visible for more flare. Dont worry about spawning then destroying the sprite. That actually makes more load on your game then simply toggling the visibility.
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
Posts: 113
Reputation: 1,295

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 4 guests