Mercury project page can be found from here!
( Source of this tutorial and compiled exe )
Download: MercuryExample.Zip
Only thing that bothers me, is the lack of tutorials for it. There really isnt anything, that helps "newbie" coders to get those beatifull particles from editor, to XNA. Well, i made a short example project, that loads and draws the "BasicExplosion", that comes as an example with the editor.
Its quite easy to get particles to drawn on screen. You need to add that particle xml file and all the textures it needs, to content of your XNA project. After that, its just coding.
// Add MercuryProject.dll reference to your projectInside the Game class, add:
// Add using statements
using ProjectMercury;
using ProjectMercury.Emitters;
using ProjectMercury.Modifiers;
using ProjectMercury.Renderers;
// Renderer that draws particles to screenInside the Game constructor add:
Renderer myRenderer;
// Particle effect object to store the info about particle
ParticleEffect myEffect;
// Create new renderer and set its graphics devide to "this" deviceInside LoadContent add:
myRenderer = new SpriteBatchRenderer
{
GraphicsDeviceService = graphics
};
myEffect = new ParticleEffect();
myEffect = Content.Load("BasicExplosion");
myEffect.LoadContent(Content);
myEffect.Initialise();
myRenderer.LoadContent(Content);
Inside Update add:
// get the latest mouse stateAnd finally, add to Draw:
MouseState ms = Mouse.GetState();
// Check if mouse left button was presed
if (ms.LeftButton == ButtonState.Pressed)
{
// Add new particle effect to mouse coordinates
myEffect.Trigger(new Vector2(ms.X, ms.Y));
}
// "Deltatime" ie, time since last update call
float SecondsPassed = (float)gameTime.ElapsedGameTime.TotalSeconds;
myEffect.Update(SecondsPassed);
myRenderer.RenderEffect(myEffect);
Now, compile.
Remember to add the dll to Content references too, or else, it wont know how to import those files. Now, if its running, just click with mouse and enjoy.
Excelent tutorial.
ReplyDeleteSimple, clare and working.
Thanks a lot.
Man, I have a question. How do I know what textures I must load?
ReplyDeleteThe textures are in the BasicExplosion.XML file. Just open it with a text editor (Notepad++). The particle names are next to the 'ParticleTextureAssetName'. The \MercuryExample1\Content folder. You need to add the textures that make up the effect to your project.
ReplyDeleteThanks, this is just what I needed.
ReplyDeleteIt seems to not display anything for me, despite literally copying your code word or word. Could anyone else confirm this?
ReplyDeleteThe same thing happened to me (as our anonymous buddy) this needs to be out of the spriteBatch.Begin() -- End() area
ReplyDeletespriteBatch.Begin();
... Draw your stuff ...
spriteBatch.End();
// Here put the draw effect method
myRenderer.RenderEffect(myEffect);
base.Draw(gameTime);
Hope this helps!
I'm having some difficult to use the Mercury Particle, even tough my code is OK, compiles, buts doesn't display anything =/
ReplyDeleteNot sure what i am doing wrong.
ReplyDeleteget and error with:
myEffect = Content.Load("BasicExplosion");
says error while deserializing intermediate XML?
and does it make a difference
myEffect = Content.Load("BasicExplosion");
or
myEffect = Content.Load("BasicExplosion");
meant
DeletemyEffect = Content.Load("BasicExplosion");
or
myEffect = Content.Load("BasicExplosion");
those are 4 time the exact same line of code dude ...
DeleteThis steps doesnt work at all ... there are no .trigger methods in the particleEffect class ...
ReplyDelete