MonoGame.Extended icon indicating copy to clipboard operation
MonoGame.Extended copied to clipboard

[Particles] Particles Demo creating artifacts in top left window corner

Open schmendrick opened this issue 7 years ago • 3 comments

Hi guys,

I tried to play around with the framework and looked into the particle system but it seems I found an issue.

Happening for me on:

  • branches "2.0", "develop" and "1.0". (tried with VS2017) of the repository
  • official nuget package resharper suggested me: 1.0.617 (tried with VS2013) where i added it to a monogame test project

Behavior seems normal on tag 0.6.359 of the repository.

See image for what I mean: image

schmendrick avatar Feb 23 '18 11:02 schmendrick

I noticed it as well. I was stepping through the code to try to find what was causing it, but I'm not having much luck myself.

stefanrbk avatar Feb 25 '18 02:02 stefanrbk

It would appear there's a couple of things going on here.

The particles are being triggered by this line in the demo:

_particleEffect.Update(deltaTime);

and also this line:

_particleEffect.Trigger(new Vector2(400, 240));

The reason it gets triggered in the Update method is because AutoTrigger is defaulting to true on the emitter.

The reason that it's triggering in the top left corner is because it's using the Position property of the emitter as the trigger point.

I suspect this odd behavior was inadvertently introduced to fix another bug. So putting it back to the old behavior might not be the right choice.

I think the "correct" fix to the demo is the remove the _particleEffect.Trigger(new Vector2(400, 240)); line from the Update method and add a Position = new Vector2(400, 240) line when creating the particle effect in the ParticleInit method.

This will probably suffice to get around the issue in the develop branch but I think the real problem here is that the API around this stuff has evolved into something quite confusing.

One of the goals of 2.0 is to clean up these confusing API's and implement a more consistent and clean approach across the board. It's not entirely clear what that is yet but it's good that these issues are getting raised and discussed.

My gut feeling at the moment is that having a Position on the particle emitter is the wrong choice. It doesn't fit well with the ECS and generally makes it difficult to keep things in sync when it's part of an entity. This also applies when you're not using the ECS. I've been experimenting with this idea on the Sprite class in the 2.0 branch but I haven't got around to particles yet.

craftworkgames avatar Feb 25 '18 11:02 craftworkgames

I haven't yet got around to doing a new particles demo. I'll keep this issue open until then.

craftworkgames avatar May 28 '18 12:05 craftworkgames

This is the only article I could find on this subject. Possibly out of date, but if you have a similar issue with current version (3.8) then maybe this will be helpful. Solved by updating _particleEffect.Position for my sparkly mouse cursor:

    public override void Update(GameTime gameTime)
    {
        Entities.Cursor.Update();
        var mousePos = Entities.Cursor.Position;
        var m = new Vector2(mousePos.X, mousePos.Y);
        _particleEffect.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
        _particleEffect.Position = new(m.X, m.Y);
    }

    public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
    {
         spriteBatch.Draw(_particleEffect);            
    }

jmwrepos avatar Apr 19 '24 20:04 jmwrepos