# XNA 2D Particles :)

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

## Recommended Posts

Hi everyone sorry if I have mistakes with my English..
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:

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"]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 on other sites
Do you have any specific questions?
Try to write it yourself, and if you get stuck on something then ask a question about it.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633766
• Total Posts
3013732
×