BASIC

Author Topic: SpriteZ - 2d particle engine (Updated: June 15,2012)  (Read 17012 times)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1618
  • Particle Hawk
    • View Profile
Re: SpriteZ - a 2d particle system
« Reply #15 on: 2010-Jan-03 »
Thanks, i appreciate the thumbs up.
Have fun with it!  :good:
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline dman10001

  • Mc. Print
  • *
  • Posts: 5
    • View Profile
Re: SpriteZ - a 2d particle system
« Reply #16 on: 2010-Apr-07 »
Hi, I would like to know how I can make explosions using SpriteZ.

what are the values and what do I use?


Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1618
  • Particle Hawk
    • View Profile
Re: SpriteZ - a 2d particle system
« Reply #17 on: 2010-Apr-08 »
Put this in your header:

Code: Text [Select]
 
numparts = 100 //partcle count max
lifetime= 1500 //1.5 seconds absolute lifetime per particle
 SpriteZ = Emitter_Create_System( "media/Fire2.PNG" , numparts ,lifetime, FALSE)
        Emitter_ColorAndAlpha( SpriteZ , RGB(255,128,0 ) , 1.0 )
        Emitter_RadiusScalars( SpriteZ , 1.0 , 0.1 )
        Emitter_Rotation_Velo( SpriteZ, 12 ) //twist 12 degrees per frame
        Emitter_Nozzle_Spread( SpriteZ, 360 )
 
That will make your sprite emitter: Shrink, rotate, Spread 360, colored yellow, and bright alpha.
Dont forget to put a sprite for the emitter in the app_directory/media/Fire2.PNG/   
Anything 32x32 size would be good.



Now you need to have some kind of velocity in the loop, and you need to show it each loop:

Code: Text [Select]
        MOUSESTATE MX,MY,MB1,MB2
        Velocity=0.05 // 0.1=low velocity 1.0=very strong velocity
        Emitter_Velocities_XY( SpriteZ , Velocity, Velocity )
        Emitter_Pause_Emitter( SpriteZ , 1-MB1 )
        Emitter_Show_Emission( SpriteZ , MX, MY )
 

The left mouse button should trigger an explosion, it will create particle as long as you are holding it.

There are many options, and really the only way to make it exactly how you need it, you must do some experimenting.
If you need the particles to do something else specific, just ask.


PS. You need to create your own timer, to explode for a specific amount of time. The lifetime timer for Spritez is only for the lifetime of the particles which are rendered....not for how long the emitter is running for, for this you need to make your own custom timer...use the pause feature to turn it on an off for best looking results.

PPS. increase program performance with a second custom timer, using a timer with the above code: the timer should stop calling the Emitter_Show_Emission, 1.5 seconds(to match particle 'lifetime' set in header)  after releasing the mouse button. The just an example, i didnt provide this in the API. As you are the programmer, you must control exactly when and where the emitter is used of course.


Here is a screenshot of the above emitter:


[attachment deleted by admin]
« Last Edit: 2010-Apr-08 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline dman10001

  • Mc. Print
  • *
  • Posts: 5
    • View Profile
Re: SpriteZ - a 2d particle system
« Reply #18 on: 2010-Apr-08 »
Hi, Thanks very much. It worked perfect. Just one thing the game slows down when its called
I tried to adjust a timer, but the particles don't last long enough.


Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1618
  • Particle Hawk
    • View Profile
Re: SpriteZ - a 2d particle system
« Reply #19 on: 2010-Apr-09 »
1. what size image are you using? (i recommend 32x32 or smaller, and triangle mode will increase perf)
2. how many particles? (i recommend very small amount <100 )

Tip 1: You must make sure you initialize ALL emitters one time! Init in the header only, before all loops.
So in other words, for each style of explosion(Bombs, Smoke, Fire, etc), you must initialize them all, before your main rendering loops.

Tip 2: Using more than 1 Emitter_Show_Emission, per render loop will significantly reduce performance, if you need  multiple explosions, just change the explosion position...the particles previously emitted will continue to live thier lifetime on the path they were already on.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

MrTAToad

  • Guest
Re: SpriteZ - a 2d particle system
« Reply #20 on: 2012-Apr-10 »
Wondering if it would be possible to update this to use extended types and what not...

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1618
  • Particle Hawk
    • View Profile
Re: SpriteZ - a 2d particle system
« Reply #21 on: 2012-Jun-14 »
Good question toad.  :x
To be honest, i really dont know where to begin with a conversion.
If i had started in types in the first place...that would have been so much easier.

If anyone feels like optimizing the code, be my guest.. if it works the same way i intended, ill update the download with it.   :whistle:
As i understand it, there is plenty of room for improvement of the original code, without trying to convert dimensions to type.

Edit: i will also accredit you in the header for your work on optimizations.

Has anyone published anything using this api?
As of yet(as far as i know), no programs exist using it yet.
It has been a long time since i began the project, im so curious to see the code in action.
I would LOVE to see SpriteZ in action!
« Last Edit: 2012-Jun-14 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1618
  • Particle Hawk
    • View Profile
New stuff in the api...download is in the top message.
Many options are updated for easier to use.
A new option is in, FRICTION
And 4 working samples....this has been lacking i know.

Im going to continue to make a few more samples(theyll be separate from the main download, and in thier own messages in this thread(below)).
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3354
  • Integrated Brain
    • View Profile
 :nw: :nw: :nw:

Hemlos this new API it´s awesome... perhaps I include in my game whit your permission, becuase the effects are awesoming, the gravity effect it´s like water... I don´t know if in Mobile devices de Fps drops down a lot, but this code it´s absolutetly very advacen, at least for me... this maths are very interesting...

Thanks a lot, and a PERFECT JOB!!!

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1618
  • Particle Hawk
    • View Profile
The math...is a monster.
Of course you may use the API.
Let me know when you finish your program, i would love to see it.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline kaotiklabs

  • Dr. Type
  • ****
  • Posts: 313
  • Spain is diferent
    • View Profile
great news :)
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1618
  • Particle Hawk
    • View Profile
Demo for Friction here..
No source, executable only...too many changes to engine, must wait.
Basically what i did was increase emitter_friction() in the sample_gravity.gbap source...and remove emitter_gravity().


[attachment deleted by admin]
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1618
  • Particle Hawk
    • View Profile
What do you guys think about this..

optional function to limit the distance a particle goes, as opposed to using a lifetime?
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4168
    • View Profile
    • Portfolio
To me, the idea means an extended controller to it, to the point it could do a lot more then the original purpose! :good:

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1618
  • Particle Hawk
    • View Profile
Something is brewing in SpriteZ land.
I am working on an experimental project, PointsGL, PGL sound ok?
Operation inject SpriteZ with steroids... multiply speed by 10.

Preliminary 3d rendering test:
60ms fixed particle movement rate
150,000 particles
screen resolution: 1280x720

On my junky video card...60fps!


Note: this is not the same way spritez renders...it is 3d.
Give this bin a whirl, test this bin.
Let me know the fps you get, and does it looks good or not, please.
http://www.glbasic.com/forum/index.php?action=dlattach;topic=3550.0;attach=5088



[attachment deleted by admin]
« Last Edit: 2012-Jun-20 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)