Share

Tags

License

This blog post is licensed Creative Common Attribution Required v4.0.

Custom Particle Effect

1
GeorgeZaharia's avatar
GeorgeZaharia
  • 28 Jun, 2018
  • 969 words
  • ~4-6 mins
  • 2,085 visits
  • 0 favourites

A few hrs ago, there was a forum question regarding, How do we spin a individual particle within the particle object itself ?

Short answer? We don't. Currently there is no official option implemented yet as far as i seen inside Construct.

However there are features regarding their individual trajectory and future angle of motion but not individual rotation.

For that we need to create a Custom Particle Effect using 2-3 event conditions and 6 7 actions.

What would this allow different then the Particle Effect?

Well outside the fact you will be able to rotate each particle individually, you will also be able to control each particle that is created as you want.

Is it more memory intensive then the default one?

Depends on how much customization you will add on top of the tutorial progress and how "Spamy" your creation rate is.

If you don't want to read the tutorial just scroll to bottom of the page and get the prebuilt file by clicking the download link.

If you want to learn how to make this yourself, and have time for some practice continue reading.

What do we need:

First we create 2 Sprite objects

.

I named them simply "Spawner" and "Object", i resized the Spawner to 10 px by 10 px and drawn a little arrow so i know which way is pointing, and made the Object the size of 20px by 20px so it has a bit more clarity and sharpness to the images and also be able to be big enough to resize it if we need to.

We will want to place the Spawner inside the layout where can be visible, and the Object outside the layout, and you will see the reason for that in the next few lines.

On the Sprite called Object i added the Bullet behavior and deselected the "Set Angle" parameter.

And also added Destroy Outside Layout Behavior.

The bullet speed is default value which is 400.

I also edited the Sprite "Object" animation and created 6 frames with different colors, and set the animation speed to 0 so it will not randomly jump from 0 to 5 frame when spawned.

Because the Object has the behavior Destroy Outside Layout, on start of layout it will be destroyed automatically, so we don't have to destroy it ourselves in a condition like "On start of layout"

For the Sprite "Object" we go to its variables and add one instance variable and call it Spin (make sure is a integer-"number holder" and not a string-"text holder" or "boolean").

Now moving to the Event Sheet.

The 1st Condition would be a "EveryTick" but i preferred to add a "Every X seconds" Condition and set its value to "0.05 Seconds".

The first action on that condition we want is

Spawner -> Spawn "Object" on image point 0 0.

Then followed by

Object Set angle of motion to Spawner Angle + random(30,-30) - What this does is sets the angle of motion for the newly created Object to the Spawner current angle between a spray-cone of 60 degrees.

And to give the particles a bit of color we add

Object set frame to choose(0,1,2,3,4,5) - we can also use floor(random(5)) - but i prefer choose(a,b,.,.,.) as is easier for the runtime to do the "Quick Maths".

We will also want some size variation for example for each individual particle to do that we call the scale function.

Object set scale to random(0.2,0.5) - What this does is, for each object created it will basically reduce its overall size to a number between 20% and 50% of its current default size.

Now in order to hit the problem of the main Question "How do we rotate a individual particle" we need to add the following action.

Object set Variable Spin to 1 - now here if you don't want all the particles to spin upon creation you can add set variable spin to choose(0,1).

And we are done with the 1st logic block.

Now we add a new Line Condition And Check for each Sprite Object if its Spin variable is set to 1 or not.

And we Begin by going to system expression and say

Parent Condition:

For Each > Object

>>new sub-event :

Object>If variable Spin = 1

Now on the action side on the sub-event line we call the object at tell it to spin, so the action there would be

Object Rotate 10 degrees clockwise.

At this point everything should work if we run a preview.

However i added 1 more neat features in case you want to make the Particle Creator to always move towards some direction, you don't need to add this next condition if you don't want to.

For this we need to add a mouse object

to our project and create a new condition:

Condition everytick > action: Spawner set angle to Angle(self.x,self.y,mouse.x,mouse.y) - we can also use Set angle to position : Mouse.X Mouse.Y

Now if we Start the Preview The Spawner Should rotate and point toward your mouse position while creating a nice spray cone of Objects with different colors, spinning around and flying away.

Additional to this we can play more with the Object particles and add the fade behavior to them and make them fade away or fade in and fade out or add a Sine Behavior but that in another Blog Entry.

If you followed the tutorial example the right way your event sheet logic blocks should look like bellow

And this Completes another quick simple tutorial example on how to create a Custom Particle Effect Fully Controllable.

For more examples like this comment bellow, and let me know what you want to see, next, or have difficulty with.

"Give me the fileeee!" - download.

Subscribe

Get emailed when there are new posts!

  • 0 Comments

Want to leave a comment? Login or Register an account!