Thanks for posting this PK8! It's a pretty cool script.
Of course, now I have several ideas about how it can be improved upon, but it would probably require a major rewrite. I think I'll just add it to my list of things I'd like to do when I have time.
I think this script is fantastic, looks great and has a lot of uses.
There's one thing I was wondering, however. Is it possible to slow the particles down?
I'm wanting to have things like special switches which have a very slow stream of particles coming from them, just enough to make them stand out a bit, to show that they're important objects. Is this possible?
Cheers.
It's possible to change the particle's speed? I think it works too fast :S
Thanks
Yes, but unfortunately in this script's current state you cannot configure the speed when calling particle_effect. Instead you will have to edit the effect inside the script.
For example, to change the blue star particles I would find the following section under 'case effect':
when 'blue'
sprite='star_blue'
add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
The format for the add_particles method is as follows:
add_particles(object, x, y, sprite, acceleration[x,y], gravity[x,y], opacity[base,loss], lock type, blending)
The values (object, x, y, sprite, and lock type) are all passed to the add_particles method based on the values you specified when calling particle_effect. So leave them alone. What you want to change are the values for acceleration and possibly gravity and opacity. First let's look at the current equation for x acceleration:
1.00*(-15+rand(30))/10
The 1.00 basically makes sure the result of the equation is a floating point.
As for rand(30), it will return an integer between 0 and 29 (I suspect the author meant to return an integer between 0 and 30)
Anyway, by subtracting 15 from the number and dividing it by 10 you end up with a range of -1.5 to 1.4. This value is then applied to the particle's X coordinate during every frame update. If you multiply this number by your frames per second (60) then you will see that the particle is potentially moving up to 90 pixels per second along the X axis.
How you choose to slow this down is entirely up to you. If you want to maintain a randomness of direction then make sure the result here can return both positive and negative results (causing the particle to randomly move forward or backwards, or in the case of Y acceleration, up or down). If you want a large variance in speed between the particles then make sure your random function allows for a large spread of numbers. Here are some examples of what you could set the acceleration to:
- [.05, .05] - Will always move the same diagonal (down-right?) at about 3 pixels per second
- [1.00*(-15+rand(31))/100], 1.00*(-15+rand(31))/100] - Almost the same configuration as before except it's 10 times slower (and I fixed the random range to [-15..+15])
- [1.00*(-1+rand(2))/20, 1.00*(-1+rand(2))/20] - Can move any direction, but only at 3 pixels per second (could also remain stationary too).
- [1.0*(rand(10) + 1)/10, 0] - Will only move forward on the X axis at anywhere from 6 - 60 pixels per second.
Now, on to the gravity setting. These values are subtracted from acceleration during each frame update. Some of the effects like fire, smoke, and sparks have a value here applied. Go ahead and play around with it if you want. My only recommendation is to keep the values for gravity small or your particles will fly away too fast.
I suppose I should also make a quick comment about opacity here. The way this script is written, the life of the particle is determined by it's opacity. The loss value is subtracted from the particle's opacity each frame update. Once a particle has faded to an opacity of 0 then it is disposed of. So if you want the particles to move slow and float around for a long time then set the opacity high (255 max) and the loss low. This behavior is one of the things I'd like to change in the script since I don't think the life of the particle should be tied to it's opacity level but rather a time value. (I plan on allowing the properties of a particle to fluctuate, for opacity this would be a ghosting in and out effect that can't be done in the current script)
Anyway, I hope these instructions help you get what you want. I actually enjoyed reading into this script to see what it does and how, so thanks for piquing my interest enough to investigate
