← View other scripts
script

Very Simple Particle Effects

Create a very simple particle effect that you can call from just one script!
· 2 min read · 900 views

Particle Systems can be complicated, but if you want a nice, simple effect that you can call and customise from just one script, here's the solution

1
Import the Sprite
Make a simple sprite, called sParticles, the sprite can have as many frames as you'd like but each frame will be a particle. Make each possible particle white or greyscale - in my example below, I'd used 9 frames with a 6x6 sprite as follows:

image
2
Create the Object
Next, create an object called oParticles and assign it the sprite above, with the following code:

CREATE

/// @description Set-Up
image_speed = 0
image_index = irandom(image_number)
direction = random(360)
alarm[0] = 30+random(20)
friction = 0.1
image_alpha = 0.8+random(0.2)
fade = false

STEP

/// @description Fade
if fade = true then image_alpha -= 0.05
if image_alpha < 0 then instance_destroy()

ALARM 0

/// @description Time-Out
fade = true

3
Create the Script
Finally, create a script called particles as follows:

/// @function particles(x,y,amount,speed,colour,scatter)
/// @param {real} x
/// @param {real} y
/// @param {real} amount
/// @param {real} speed
/// @param {real} colour
/// @param {real} scatter
function particles(_xx,_yy,_amount,_speed,_colour,_scatter){
repeat(_amount) {
with(instance_create_depth(_xx-(_scatter/2)+random(_scatter*2),_yy-(_scatter/2)+random(_scatter*2),depth-1,oParticles)) {
image_blend = _colour
speed = _speed-0.5+random(1)
}}}


4
Using the Script

And that's it! Now, whenever you want a nice, simple particle effect, just call:

  particles(<X>,<Y>,<AMOUNT>,<SPEED>,<COLOUR>,<SCATTER_AMOUNT>)

and it'll look like this:

image

Easy! Enjoy!