Jump to content
  • Advertisement
Sign in to follow this  
AgentChaos

XNA 2D Particles :)

This topic is 2525 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone sorry if I have mistakes with my English.. smile.gif
Im using XNA 3.1 and Im working on school project...so I decide to do 2D particle system!
I want to do something like this:

http://www.youtube.c...h?v=CyAZ2Y7nOTw
http://www.youtube.c...h?v=eSWm_VImgFQ
http://www.youtube.c...h?v=F5xwSLdG9n0

In the comments of the third video you can see that he wrote this:
"[font="arial, sans-serif"] i? used fixed function, and the movement of the particles is done using newtons laws,[/font]
[font="arial, sans-serif"] the cursor is an attractor and also the particles fall to the bottom of the[/font]
[font="arial, sans-serif"] screen with gravity. Its all done using a verlet integration technique."[/font]
[font="arial, sans-serif"]
[/font]
[font="arial, sans-serif"]So i read about verlet integration and found:[/font]
[font="arial, sans-serif"]http://www.gamasutra...cobson_01.shtml[/font]
http://www.gamedev.n...e-physics-r2714

Please some one can help me to write the code?

this what I do for now: (the texture of each particle is 1X1 white picture for now)



class Particle
{
public Vector2 pos, oldpos, a; // pos-current position , oldpos-old position , a-Acceleration
public Color color;

public Particle(Vector2 _pos, Vector2 _oldpos, Vector2 _a, Color _color)
{
pos = _pos;
oldpos = _oldpos;
a = _a;
color = _color;
}
}
[/quote]




int WindowWidth = 800;
int WindowHeight = 800;

int MaxParticles;
Vector2 Gravity = new Vector2(0,-0.98f);
float TimeStep;


private void UpdateParticles()
{
Vector2 temp;
for (int i = 0; i < MaxParticles; i++)
{
temp = particles.pos;
particles.pos += particles.pos - particles.oldpos + particles.a * TimeStep * TimeStep;
particles.oldpos = temp;
}
}


private void DrawParticles()
{
spriteBatch.Begin();
for (int i = 0; i < MaxParticles; i++)
{
spriteBatch.Draw(particleTex, particles.pos, particles.color);
}
spriteBatch.End();
}

[/quote]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!