SFML community forums

Bindings - other languages => DotNet => Topic started by: Mad on August 27, 2013, 01:57:31 pm

Title: c# example for particle system?
Post by: Mad on August 27, 2013, 01:57:31 pm
Hello!

I've found a lot of c++ examples for particle systems, but c++ is really not my passion.  ???

So can someone give me an example class for a particle system in C# ?

Thanks!!!  :)
Title: Re: c# example for particle system?
Post by: eXpl0it3r on August 27, 2013, 02:18:38 pm
C++ and C# are not that far apart, if you have a good example of a C++ version, it should be relatively easy to port it to C#.
Otherwise, I'm convinced you'll find a lot of examples by googling for example "particle system c#"
Title: Re: c# example for particle system?
Post by: Mister on August 27, 2013, 04:26:18 pm
I'd have to agree with eXpl0it3r.

But you could also take a stab at porting Mercury from XNA to SFML  :D
http://mpe.codeplex.com/
Title: Re: c# example for particle system?
Post by: Mister on August 27, 2013, 07:50:53 pm
But you could also take a stab at porting Mercury from XNA to SFML  :D
http://mpe.codeplex.com/

Hell yeah, that's what I'm looking for.  :)
but a port to c# might be a little bit to much work  :P ..... but those effects look great.

Well its already in C#  ;)
It'd have to be ported to SFML.

I have a project that I am going to start working on as soon as I get my head wrapped around SFML more and I was actually thinking about porting a lot of different things over to C#/SFML; one of those being a Particle System. I had my eyes set on DPSF  (http://www.xnaparticles.com/index.php) (I've used it before when I was using XNA)... But! DPSF isn't open source :(. So I will probably soon be looking into Mercury (since its already C#).

Anything and everything that I port over to C#/SFML will be open for all to use -- I just need to learn more about SFML and then I can start converting different things over.  8)

I know you need a solution now but I'm not sure what else to do.  :-\
Title: Re: c# example for particle system?
Post by: Mad on August 27, 2013, 07:57:38 pm
Quote from: Mister

Well its already in C#  ;)
It'd have to be ported to SFML.

yes, I saw it and that's why I removed my post  ::)

Quote from: Mister
Anything and everything that I port over to C#/SFML will be open for all to use -- I just need to learn more about SFML and then I can start converting different things over.  8)

lerning SFML it's also my part at the moment.
but less time as usal  :P

Quote from: Mister
I know you need a solution now but I'm not sure what else to do.  :-\

Nooo! Not now, but in a few weeks it would be ok.  8)
Title: Re: c# example for particle system?
Post by: Mister on August 27, 2013, 08:07:06 pm
Quote from: Mad
yes, I saw it and that's why I removed my post  ::)
Haha, I thought it was weird that your post disappeared!

Quote from: Mad
lerning SFML it's also my part at the moment.
but less time as usal  :P
Yeah I'm a full time software engineer so I have little time to play too  :'(

Quote from: Mad
Nooo! Not now, but in a few weeks it would be ok.  8)
I can't/won't make any promises but I can see if getting a particle system working for SFML .Net could the first adventure I take.

I was just taking a look at Mercury and it seems pretty robust -- they even have a particle editor! That would definitely be a cool thing to carry over... This will be an interesting task...  ;D
Title: Re: c# example for particle system?
Post by: Mad on August 28, 2013, 10:53:52 am
Quote from: Mad
lerning SFML it's also my part at the moment.
but less time as usal  :P
Yeah I'm a full time software engineer so I have little time to play too  :'(

Me too! You are wellcome!  ;D

Quote from: Mister
I was just taking a look at Mercury and it seems pretty robust -- they even have a particle editor! That would definitely be a cool thing to carry over... This will be an interesting task...  ;D

no need to convert the editor, because gui development is no fun at all in my opinion....  :o
But I agree, the mercury editor is still a little buggy....  :-\

Quote from: Mister
Edit:
Alright so while I wait for other things to transpire -- I decided to start a port of Mercury to SFML. You can check it out here:
https://sourceforge.net/projects/mpesfml/

Cool. But no download yet?  ;)

Quote from: Mister
It's going to be a pain because I want to strip out the 3D portion and just leave the 2D portion there.

I have a short look in the source code, seems there are only 4 classes for the main parts (particle.cs, ParticleEffect.cs, ParticleEffectManager.cs and SpriteBatchRenderer.cs)
all other stuff is only 'nice to have'  ;)
Title: Re: c# example for particle system?
Post by: Mister on August 28, 2013, 01:06:54 pm
Alright so it turns out the idea of porting Mercury over to SFML is completely out-of-scope. I am going to be looking into alternatives.
Title: Re: c# example for particle system?
Post by: Mad on August 28, 2013, 04:29:16 pm
Alright so it turns out the idea of porting Mercury over to SFML is completely out-of-scope. I am going to be looking into alternatives.

 :-\ bad luck.
But maybe only some good explosion, smoke and fire effects in c#? Heeelp  :)
Title: Re: c# example for particle system?
Post by: Mister on August 28, 2013, 04:44:40 pm
Alright so it turns out the idea of porting Mercury over to SFML is completely out-of-scope. I am going to be looking into alternatives.

 :-\ bad luck.
But maybe only some good explosion, smoke and fire effects in c#? Heeelp  :)

Yeah when going through it I realized that it was tightly coupled to XNA -- I just don't have time to sift through it. I am actually working on my own particle system right now; strictly 2D.
Title: Re: c# example for particle system?
Post by: Nexus on August 28, 2013, 05:14:32 pm
You can also have a look at my C++ implementation of Thor.Particles (API documentation (http://www.bromeon.ch/libraries/thor/v2.0/doc/group___particles.html), tutorial (http://www.bromeon.ch/libraries/thor/v2.0/tutorial-particles.html), code (https://github.com/Bromeon/Thor/)). Even though the current status allows a lot of customization and flexibility, the basic principle is rather simple:

Title: Re: c# example for particle system?
Post by: SymegPL on August 28, 2013, 09:16:21 pm
You can look at my implementation at: https://github.com/Symeg/Smart2DGameFramework/tree/master/Smart2DGameFramework/Graphics/Particles
Demo on youtube (fire particles, old video, now is better performance) http://www.youtube.com/watch?v=Tybz3uq9HWk

You can also find other useful tools :)
Title: Re: c# example for particle system?
Post by: Mister on August 29, 2013, 03:15:18 am
(http://s7.postimg.org/u460997d7/sfml_mparticle.png)

Looking good so far -- I'd say. Theres a few things that I need to work out but so far so good.  ;D

EDIT:
Heres another shot of it:
(http://s22.postimg.org/hi2vzg0fl/sfml_mparticle_2.png)
Title: Re: c# example for particle system?
Post by: Mad on August 29, 2013, 10:15:38 am
@Nexus
Thanks for your information. I had a look at Thor early. It's a pitty there is no C# clone  :-\
But it seems to be a very useful library!!

@SymegPL
Hey, thanks for sharing. I will have a look at your lib. Is the client/server part stabil?

Mister
Nice one!  :D
Can you tell me, what are you using? Sprites or only Vertex?
As I can see from your blog,you have plans to make a Top Down Shooter shooter? Maybe we can stick together?
I have plans to make also a shooter...but Left Right  ;D my first idea was an uridium clone with much more features.
http://en.wikipedia.org/wiki/Uridium (http://en.wikipedia.org/wiki/Uridium)
Maybe we can combine Top Down Shooter with Top Down and double knowledge?  8)
Title: Re: c# example for particle system?
Post by: Mister on August 29, 2013, 02:32:29 pm
As I can see from your blog,you have plans to make a Top Down Shooter shooter? Maybe we can stick together?
I have plans to make also a shooter...but Left Right  ;D my first idea was an uridium clone with much more features.
http://en.wikipedia.org/wiki/Uridium (http://en.wikipedia.org/wiki/Uridium)
Maybe we can combine Top Down Shooter with Top Down and double knowledge?  8)
I can't really agree to start this new project as a team effort.. not at this time at least. That isnt to say that we can't help each other out with our individual games though.  :)

The game that originally inspired me was a game made by one of my friend's brother back in high school.
http://www.youtube.com/watch?v=kZ2s_Le6iw4

Mister
Nice one!  :D
Can you tell me, what are you using? Sprites or only Vertex?
The way it sits right now -- its renderer agnostic. The only thing it currently focuses on is the underlying numbers that all particles deal with. You can then tell your images to draw accordingly.

I will have the source code up as soon as I get a decent example running.  :D
Title: Re: c# example for particle system?
Post by: Mad on August 29, 2013, 05:03:03 pm
I can't really agree to start this new project as a team effort.. not at this time at least. That isnt to say that we can't help each other out with our individual games though.  :)

no problem, it was just an idea, because I'm still in testings things out.  :D
Your game is very fast at all. too fast for me....  ;D

Quote from: Mister
I will have the source code up as soon as I get a decent example running.  :D

I'm waiting.  :)
Meanwhile a short screen of my current particle test. It's not still, what I want to have...  :-\


edit
screenshot 2 + 3 look now much better, I think?
Title: Re: c# example for particle system?
Post by: Mister on August 30, 2013, 05:38:39 am
Looks pretty good so far -- is this a separate particle system that you are making? How'd you end up handling Particles Per Second?
Title: Re: c# example for particle system?
Post by: Mad on August 30, 2013, 09:48:18 am
Looks pretty good so far -- is this a separate particle system that you are making? How'd you end up handling Particles Per Second?

yes, it's my first experiment in SFML.  :)
I'm using the Stopwatch to get the milliseconds since last frame loop and calculate the new position with it.
Title: Re: c# example for particle system?
Post by: Mister on August 30, 2013, 01:52:09 pm
(http://s7.postimg.org/4nfwh72jv/sfml_mparticle_3.png)

Here is a newer update of the particle system so far.
It now calculates the proper particles per second and fades out based on lifetime  ;D

I think I'll add color to it, clean up some spots, and then it should be good to upload to sourceforge -- just note that its nowhere near 100% done.   :)
Title: Re: c# example for particle system?
Post by: Mad on August 30, 2013, 05:09:06 pm
I think I'll add color to it, clean up some spots, and then it should be good to upload to sourceforge -- just note that its nowhere near 100% done.   :)

gogogo, I will see how you handle the drawing process.   :D
Title: Re: c# example for particle system?
Post by: zsbzsb on August 30, 2013, 07:32:03 pm
Thanks for your information. I had a look at Thor early. It's a pitty there is no C# clone  :-\
But it seems to be a very useful library!!

Actually it does have an almost complete clone. I am currently working on it - particles and large texture/sprite/rendertexture are currently done. I will be publishing it soon too. And here is a screenshot of the ported fireworks example from Thor.

(http://i40.tinypic.com/24lixyw.png)
Title: Re: c# example for particle system?
Post by: Mad on August 30, 2013, 07:44:16 pm
Actually it does have an almost complete clone. I am currently working on it - particles and large texture/sprite/rendertexture are currently done. I will be publishing it soon too. And here is a screenshot of the ported fireworks example from Thor.

YES, that are really good news!  :D
At the end, we will have 5 different Particlesystems here for different application areas. Cool  8)
Title: Re: c# example for particle system?
Post by: zsbzsb on August 30, 2013, 08:48:00 pm
YES, that are really good news!  :D
At the end, we will have 5 different Particlesystems here for different application areas. Cool  8)

Glad you like the idea, I decided to go ahead and upload it. Here is the thread (http://en.sfml-dev.org/forums/index.php?topic=12819) wherre you can read all about NetEXT.
Title: Re: c# example for particle system?
Post by: Mad on August 30, 2013, 09:03:48 pm
Glad you like the idea, I decided to go ahead and upload it. Here is the thread (http://en.sfml-dev.org/forums/index.php?topic=12819) wherre you can read all about NetEXT.

That was quick! Thanks for sharing.  :D I have the fireworks demo up and running. NICE!
I will have a deeper look into the lib to see what effects I can arrange with this particle system.  :D
Title: Re: c# example for particle system?
Post by: Mister on September 01, 2013, 12:07:14 am
https://sourceforge.net/projects/mparticles/

I still haven't added color but I cleaned it up a little bit.

I will be adding a lot to it over the course of Sunday-Monday so watch for updates  8). I will also be making a separate post about it later -- let me know if you think there should be different ways of doing things.
Title: Re: c# example for particle system?
Post by: Mad on September 01, 2013, 01:17:12 pm
Hi there!  :)

I will be adding a lot to it over the course of Sunday-Monday so watch for updates  8). I will also be making a separate post about it later -- let me know if you think there should be different ways of doing things.

First I have to say: Good structured souce code, mate!  :)

At the moment you use CircleShape for the smoke effect. Some plans to integrate texture effects?
I will have a deeper look later.  :)
Title: Re: c# example for particle system?
Post by: Mister on September 01, 2013, 06:59:02 pm
Hi there!  :)

I will be adding a lot to it over the course of Sunday-Monday so watch for updates  8). I will also be making a separate post about it later -- let me know if you think there should be different ways of doing things.

First I have to say: Good structured souce code, mate!  :)

At the moment you use CircleShape for the smoke effect. Some plans to integrate texture effects?
I will have a deeper look later.  :)

Thanks  :D

You can use whatever you like  8). All you gotta do is change CircleShape to a Sprite -- UserObject gets passed around per-particle and eventually gets cast into a Drawable and drawn to screen.

So basically, you could have ANY object that inherits from Drawable as UserObject and it will get drawn however you set it up and refresh the object.

For example -- I am making a fire work example particle effect; this is what I do:

                       
                public RocketEmitter() : base(1, 2)
                {
                        ParticleInitialization = SmokeParticleInit;

                        OnEveryUpdate += PresetAffectors.UpdatePositionBasedOnRotationAndVelocity;
                        OnRefreshUserObject += RefreshUserObject;

                        Texture texture = new Texture(@"Assets\rocket_triangle.png");

                        OnParticleCreated += particle =>
                        {
                                Sprite sprite = new Sprite(texture) {Origin = new Vector2f(20, 24), Scale = new Vector2f(.25f, .25f)};
                                particle.UserObject = sprite;
                        };
                }
 

And then I have this:

                private void RefreshUserObject(Particle particle)
                {
                        Sprite shape = (Sprite)particle.UserObject;
                        shape.Position = new Vector2f(particle.Position.X, particle.Position.Y);
                        shape.Color = new Color(0, 0, 0, (byte)particle.Alpha);
                        shape.Rotation = particle.Rotation;
                }
 

And then it draws rocket sprites on screen  :D

The smoke effect isn't quite done yet -- I will have something better committed soon  ;D
Title: Re: c# example for particle system?
Post by: Mad on September 01, 2013, 08:00:17 pm
Ah!  :D
so this way, you create a sprite for each particle?

In my code I only create one sprite at the beginning and use this instance to draw all particles.
Not sure if it is a good approach, but it's seems to be faster and less ressouce hungry.  ::)

But my code is not clean at the moment and no time to work on it at currently  :-\
Title: Re: c# example for particle system?
Post by: Mister on September 01, 2013, 08:50:03 pm
Ah!  :D
so this way, you create a sprite for each particle?

In my code I only create one sprite at the beginning and use this instance to draw all particles.
Not sure if it is a good approach, but it's seems to be faster and less ressouce hungry.  ::)

But my code is not clean at the moment and no time to work on it at currently  :-\

Yep that would be the better approach so we aren't wasting resources  ;)

I'll make sure the new examples reflects that.

EDIT:
I added Scaling and more functionality to how Alpha is dealt with.
(http://img801.imageshack.us/img801/3474/0b5j.png)
Title: Re: c# example for particle system?
Post by: Mad on September 01, 2013, 09:06:18 pm
Ah!  :D
so this way, you create a sprite for each particle?

In my code I only create one sprite at the beginning and use this instance to draw all particles.
Not sure if it is a good approach, but it's seems to be faster and less ressouce hungry.  ::)

But my code is not clean at the moment and no time to work on it at currently  :-\

Yep that would be the better approach so we aren't wasting resources  ;)

I'll make sure the new examples reflects that.

So we can set the focus on groovy amazing and visionary effects soon ???   8)
Title: Re: c# example for particle system?
Post by: SymegPL on September 02, 2013, 09:16:20 pm
(...)
@SymegPL
Hey, thanks for sharing. I will have a look at your lib. Is the client/server part stabil?
(...)

Should be stable, but I cant guarantee that.
Title: Re: c# example for particle system?
Post by: Mister on September 03, 2013, 01:24:07 am
(http://img443.imageshack.us/img443/5489/gn7f.png)

Updated SVN -- changed mostly everything lol. Color is going in now.

Edit:
Color is in  8)
(http://img24.imageshack.us/img24/9489/zmbf.png)

Edit:
Added a new example to show off different things:
Circle, Square, Line, Point Emitting
(http://img801.imageshack.us/img801/3498/qp6b.png)

Also added acceleration, rotation, rotation velocity, rotation acceleration.
1 more example then I will make my own post.  ;D

Final Edit:
I added another example. Next example I will have in my own post dedicated to MParticles.  :D
(http://img547.imageshack.us/img547/610/9tan.png)
Title: Re: c# example for particle system?
Post by: Mad on September 06, 2013, 01:29:01 pm
looks nice so far!

Some explosions with splitter would be nice, fire effects aso.  8)
Title: Re: c# example for particle system?
Post by: Mister on September 06, 2013, 02:46:26 pm
looks nice so far!

Some explosions with splitter would be nice, fire effects aso.  8)

http://en.sfml-dev.org/forums/index.php?topic=12869.0

MParticles project post ^

I have 2 fire effects so far :D
Title: Re: c# example for particle system?
Post by: Mad on September 06, 2013, 02:56:56 pm
Aaaaaaaaaaaaaah! Havn't seen it yet.
Locks very good so far!!  :)