blob: 4da6efa98654ff5fc8ad5a25fbf89a74780a73c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
using Microsoft.Xna.Framework;
namespace MonoGame.Extended.Particles.Modifiers.Containers
{
public class RectangleLoopContainerModifier : Modifier
{
public int Width { get; set; }
public int Height { get; set; }
public override unsafe void Update(float elapsedSeconds, ParticleBuffer.ParticleIterator iterator)
{
while (iterator.HasNext)
{
var particle = iterator.Next();
var left = particle->TriggerPos.X + Width*-0.5f;
var right = particle->TriggerPos.X + Width*0.5f;
var top = particle->TriggerPos.Y + Height*-0.5f;
var bottom = particle->TriggerPos.Y + Height*0.5f;
var xPos = particle->Position.X;
var yPos = particle->Position.Y;
if ((int) particle->Position.X < left)
xPos = particle->Position.X + Width;
else
{
if ((int) particle->Position.X > right)
xPos = particle->Position.X - Width;
}
if ((int) particle->Position.Y < top)
yPos = particle->Position.Y + Height;
else
{
if ((int) particle->Position.Y > bottom)
yPos = particle->Position.Y - Height;
}
particle->Position = new Vector2(xPos, yPos);
}
}
}
}
|