Пример #1
0
        public Game1()
        {
            _graphics = new GraphicsDeviceManager(this);
            _content = new ContentManager(Services);

            _graphics.SynchronizeWithVerticalRetrace = false;
            IsFixedTimeStep = false;
            _graphics.PreferMultiSampling = false;
            //_graphics.PreferredBackBufferFormat = SurfaceFormat.Bgr565;
            _graphics.ApplyChanges();
            //_graphics.ToggleFullScreen();

            _system = new ParticleSystem(this);

            _snow = new LineEmitter(_system, 1000, 800f, 0f);
            _snow.Position = new Vector2(400f, 0f);
            _snow.ParticleLifespan = 15000;
            _snow.ParticleSpeed = 50f;
            _snow.ParticleSpeedRange = 50f;
            _snow.ParticleColor = Color.Azure;
            _snow.ParticleScale = .25f;
            _snow.ApplyModifier(new SineForceModifier(10f, 20f));
            _snow.ApplyModifier(new RandomScaleModifier(.05f, .2f));
            _snow.ApplyController(new TimedTriggerController(10));
            _snow.ApplyModifier(new OpacityModifier(1f, 0f));

            _fireworks = new SprayEmitter(_system, 500, MathHelper.Pi, MathHelper.PiOver4);
            _fireworks.Position = new Vector2(400f, 600f);
            _fireworks.ParticleSpeed = 500f;
            _fireworks.ParticleSpeedRange = 100f;
            _fireworks.ParticleColor = Color.BurlyWood;
            _fireworks.ParticleLifespan = 2000;
            _fireworks.ParticleScale = .5f;
            _fireworks.ParticleOpacity = .25f;
            _fireworks.ApplyModifier(new GravityModifier(0f, 250f));
            _fireworks.ApplyController(new TimedTriggerController(40));

            _trail = new Emitter(_system, 5000);
            _trail.ParticleLifespan = 250;
            _trail.ParticleSpeed = 25f;
            _trail.ApplyModifier(new ColorModifier(Color.Goldenrod, Color.Honeydew));
            _trail.ApplyModifier(new ScaleModifier(.2f, 0f));
            _trail.ApplyController(new TrailController(_fireworks, 10));

            _explosion = new Emitter(_system, 5000);
            _explosion.DischargeQuantity = 250;
            _explosion.ParticleScale = .5f;
            _explosion.ParticleSpeed = 155f;
            _explosion.ParticleSpeedRange = 300f;
            _explosion.ApplyModifier(new ColorModifier(Color.PowderBlue, Color.Red));
            _explosion.ApplyModifier(new OpacityModifier(1f, 0f));
            _explosion.ApplyModifier(new AtmosphereModifier(0.2f));
            _explosion.ApplyController(new ExplosionController(_fireworks));
        }
Пример #2
0
        public void AddEmitter(Emitter emitter)
        {
            _emitters.Add(emitter);

            foreach (Modifier mod in _modifiers)
            {
                emitter.ApplyModifier(mod);
            }
        }
Пример #3
0
        protected override void Initialize()
        {
            base.Initialize();

            emitter = new Emitter(1000);
            emitter.ParticleLifespan = 2000;
            emitter.ParticleSpeed = 150f;
            emitter.ParticleSpeedRange = 50f;

            //We have seen some examples of Modifiers in the previous examples. Modifiers
            //are always necessary to bring Emitters to life, but there is no limit to the
            //amount, and variety of Modifiers you can apply.
            emitter.ApplyModifier(new EmitterMouseController(false));
            emitter.ApplyModifier(new TimedTriggerController(10f));

            //There are many Modifiers to choose from to get the effect you desire, and it
            //is easy to create you own (there will be another example of this). Here i will
            //demonstrate some of the most useful Modifiers.

            //The GravityModifier applys a linear gravity force to all active Particles. You
            //can adjust the direction, and the strength of gravity.
            emitter.ApplyModifier(new GravityModifier(MathHelper.PiOver2, 350f));

            //The Color3Modifier fades the color of Particles between 3 colors. You can
            //adjust the sweep rate of the middle color. The interpolation is pre-calculated,
            //and you can change the smoothness of the pre-calculation (higher is better).
            emitter.ApplyModifier(new Color3Modifier(Color.White.ToVector3(),
                Color.SteelBlue.ToVector3(), 0.25f, Color.Purple.ToVector3(), 128));

            //Also available is a Color2Modifier, which fades between 2 colors - this is not
            //pre-calculated and so you can change the colors in realtime.
            //Plus, there is a RandomColorModifier, which gives each spawned Particle a
            //random color.

            //As well as color, there are similar Modifiers for adjusting Particles opacity
            //and scale. They work in the same way. There is the addition of MultiOpacity
            //and MultiScale Modifiers, which interpolate between and infinate number of
            //values...
            emitter.ApplyModifier(new Scale2Modifier(0f, 3f));
            emitter.ApplyModifier(new Opacity3Modifier(1f, 1f, 0.75f, 0f, 64));

            //The AtmosphereModifier allows you to simulate dense atmosphere of water. It
            //works by adjusting the speed of the Particles as they move... A density of 1
            //will have no effect on the Particles. A density >1 has the effect of slowing
            //Particles.
            emitter.ApplyModifier(new AtmosphereModifier(1.2f));

            //Finally, the WindowBounceModifier causes Particles to bounce off the edge of
            //game window. You can adjust the bounce coefficient.
            emitter.ApplyModifier(new WindowBounceModifier(this.Window, .75f));

            //As always, we need to add the Emitter to the ParticleSystem.
            system.AddEmitter(emitter);
        }
Пример #4
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);

            system = new ParticleSystem(this);
            emitter = new Emitter(1000);
            emitter.ParticleSpeed = 150f;
            emitter.ApplyModifier(new EmitterMouseController(true));

            //When creating an ImageStrip, you must supply 5 pieces of information. You must
            //give the ImageStrip a name, so that Emitters can identify it. You must specify
            //the number of frames in the ImageStrip, and also the width and height of each
            //frame. Finally you must specify the asset name, as specified in the content
            //pipeline.
            strip = new ImageStrip("custom");
            strip.Asset = "CustomParticleImage";
            strip.FrameHeight = 128;
            strip.FrameWidth = 128;
            strip.Frames = 4;

            //When it is done, you will add the ImageStrip to the ParticleSystem.
            system.ImageStrips.Add("custom", strip);

            //Then you will tell the Emitter to use this ImageStrip.
            emitter.ImageStrip = "custom";
            emitter.Frame = 2;

            //When using the ImageStrip, the Emitter will automatically render the
            //specified frame at the correct size, and the origin will always be at the
            //centre of the frame.

            system.AddEmitter(emitter);

            //If you make an error, either by telling the Emitter to use an ImageStrip that
            //doesn't exist, or telling it to use a frame that doesn't exist - The Emitter
            //will instead render Particles with an exclamation mark (!), to let you know
            //that there has been an error.
        }
        /// <summary>
        /// Adds an Emitter to the ParticleSystem.
        /// </summary>
        /// <param name="emitter">MercuryParticleEngine.Emitters.Emitter object to add.</param>
        /// <returns>True if the Emitter was successfully added, else false.</returns>
        /// <remarks>The system is smart enough to prevent the same Emitter being added
        /// multiple times.</remarks>
        public bool AddEmitter(Emitter emitter)
        {
            if (_emitters.Contains(emitter)) { return false; }

            _emitters.Add(emitter);

            _modifiers.ForEach(delegate(Modifier modifier)
            {
                emitter.ApplyModifier(modifier);
            });

            return true;
        }
Пример #6
0
        protected override void Initialize()
        {
            base.Initialize();

            //When creating an Emitter, you will always need to specify a budget. The budget
            //is the number of Particles the Emittter has, and if the Emitter tries to
            //emit more than this number, it will raise a 'starving' event. (Emitter events
            //will be demonstrated in another example)
            emitter = new Emitter(1000);

            //Setting the DischargeQuantity controls how many Particles the Emitter spawns
            //each time it is triggered.
            emitter.DischargeQuantity = 3;

            //The speed of Particles is controlled with two values. The first value is the
            //base speed of all Particles, and the second value is the range either side of
            //the base speed. Each particle is assigned a random speed value between
            //Speed - (Range /2), and Speed + (Range /2).
            emitter.ParticleSpeed = 50f;
            emitter.ParticleSpeedRange = 50f;
            //So, each Particle will have a speed between 25, and 75.

            //Applying Modififiers to an Emitter is the way to advanced Emitter effects, and
            //can also help integrate the engine into your game. In this example we are
            //applying 3 simple Modifiers. The first is a MouseController, which moves the
            //position of the Emitter to match the Mouse coordinates. The MouseController
            //modifier can also trigger the Emitter when the mouse button is pressed. The
            //second is a RandomColorModifier, which causes each spawned Particle to be a
            //random color. The third is a RandomScaleModifier, which causes each Particle
            //to be a random scale between the minimum and maximum values specified.
            Modifier mouseControl = new EmitterMouseController(true);
            Modifier randomColor = new RandomColorModifier();
            Modifier randomScale = new RandomScaleModifier(.1f, 2f);

            //We must apply each of these Modifiers to the Emitter.
            emitter.ApplyModifier(mouseControl);
            emitter.ApplyModifier(randomColor);
            emitter.ApplyModifier(randomScale);

            //And finally, we must add the Emitter to the ParticleSystem.
            system.AddEmitter(emitter);

            //This demonstration is now ready to run!
        }