diff --git a/Demo/Content/Content.mgcb b/Demo/Content/Content.mgcb index 9e64613..3d679d7 100644 --- a/Demo/Content/Content.mgcb +++ b/Demo/Content/Content.mgcb @@ -37,7 +37,7 @@ /processorParam:TextureFormat=Color /build:heart.png -#begin heart.png +#begin star.png /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -47,8 +47,11 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:heart.png +/build:star.png #begin testParticle.ptc /copy:testParticle.ptc +#begin testParticle2.ptc +/copy:testParticle2.ptc + diff --git a/Demo/Content/star.png b/Demo/Content/star.png new file mode 100644 index 0000000..b4fe527 Binary files /dev/null and b/Demo/Content/star.png differ diff --git a/Demo/Content/testParticle2.ptc b/Demo/Content/testParticle2.ptc new file mode 100644 index 0000000..5727e3a --- /dev/null +++ b/Demo/Content/testParticle2.ptc @@ -0,0 +1,161 @@ +{ + "Name": null, + "Emitters": { + "principal": { + "SpriteEffects": 0, + "LayerDepth": 0.0, + "TexturePath": "star.xnb", + "HasExpired": false, + "Loop": true, + "ForceLoop": true, + "Capacity": 10, + "Term": "00:00:01", + "ActiveParticles": 10, + "BlendMode": 0, + "TextureKey": null, + "ReclaimFrequency": 1.0, + "Offset": { + "X": 0.0, + "Y": 0.0, + "Length": 0.0, + "LengthSq": 0.0, + "Axis": { + "X": "NaN", + "Y": "NaN", + "Angle": "NaN" + } + }, + "Modifiers": { + "OpacityFastFade": { "Name": "OpacityFastFadeModifier" }, + "Rotation": { + "Name": "RotationModifier", + "RotationRate": 3.0 + }, + "ScaleInterpolator2": { + "Name": "ScaleInterpolator2", + "InitialScale": { + "X": 20.0, + "Y": 20.0, + "Length": 28.2842712, + "LengthSq": 800.0, + "Axis": { + "X": 0.707106769, + "Y": 0.707106769, + "Angle": 0.7853982 + } + }, + "FinalScale": { + "X": 40.0, + "Y": 40.0, + "Length": 56.5685425, + "LengthSq": 3200.0, + "Axis": { + "X": 0.707106769, + "Y": 0.707106769, + "Angle": 0.7853982 + } + } + }, + "Drag": { + "Name": "DragModifier", + "DragCoefficient": 1.5, + "Density": 80.1 + }, + "RectLoopContainerModifier": { + "Name": "RectLoopContainerModifier", + "Width": 100, + "Height": 100 + } + }, + "ModifierExecutionStrategy": { "Name": "Serial" }, + "Profile": { + "Name": "CircleProfile", + "Axis": { + "X": 0.0, + "Y": -1.0, + "Angle": -1.57079637 + }, + "Length": 100.0, + "Direction": { + "X": 0.0, + "Y": -1.0, + "Angle": -1.57079637 + }, + "Spread": 100.0, + "Radius": 100.0, + "Radiate": 1, + "Width": 100.0, + "Height": 100.0 + }, + "Parameters": { + "Quantity": { + "Min": 1, + "Max": 1, + "Diameter": 0, + "Centre": 1, + "Radius": 0, + "IsDegenerate": true, + "IsProper": false + }, + "Speed": { + "Min": 1.1, + "Max": 1.1, + "Diameter": 0.0, + "Centre": 1.1, + "Radius": 0.0, + "IsDegenerate": true, + "IsProper": false + }, + "Colour": { + "Min": { + "H": 0.0, + "S": 0.29, + "L": 1.0 + }, + "Max": { + "H": 0.0, + "S": 0.29, + "L": 1.0 + } + }, + "Opacity": { + "Min": 0.0, + "Max": 0.0, + "Diameter": 0.0, + "Centre": 1.0, + "Radius": 0.0, + "IsDegenerate": true, + "IsProper": false + }, + "Scale": { + "Min": 225.0, + "Max": 225.0, + "Diameter": 0.0, + "Centre": 225.0, + "Radius": 0.0, + "IsDegenerate": true, + "IsProper": false + }, + "Rotation": { + "Min": 0.0, + "Max": 0.0, + "Diameter": 0.0, + "Centre": 0.0, + "Radius": 0.0, + "IsDegenerate": true, + "IsProper": false + }, + "Mass": { + "Min": 1.1, + "Max": 1.1, + "Diameter": 0.0, + "Centre": 1.1, + "Radius": 0.0, + "IsDegenerate": true, + "IsProper": false + } + } + } + }, + "ActiveParticles": 10 +} \ No newline at end of file diff --git a/Demo/Game1.cs b/Demo/Game1.cs index b8f8aa3..b957d26 100644 --- a/Demo/Game1.cs +++ b/Demo/Game1.cs @@ -1,7 +1,8 @@ -using System; -using System.Collections.Generic; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.IO; using VenusParticleEngine.Core; using VenusParticleEngine.Core.Modifiers; using VenusParticleEngine.Core.Modifiers.Container; @@ -11,72 +12,74 @@ namespace Demo { public class Game1 : Game { - GraphicsDeviceManager _graphics; - SpriteBatch _spriteBatch; - - ParticleEffect _particleEffectSquare; - ParticleEffect _particleEffectImage; - ParticleEffect _particleEffectJson; - - Vector _particleJsonPosition = new Vector(700, 0); - + private GraphicsDeviceManager _graphics; + private ParticleEffect _particleEffectImage; + private ParticleEffect _particleEffectJson; + private ParticleEffect _particleEffectJsonString; + private ParticleEffect _particleEffectSquare; + private Vector _particleJsonPosition = new Vector(700, 0); + private SpriteBatch _spriteBatch; public Game1() { _graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } + protected override void Draw(GameTime gameTime) + { + GraphicsDevice.Clear(Color.Black); + + _spriteBatch.Begin(); + { + _spriteBatch.Draw(_particleEffectSquare); + _spriteBatch.Draw(_particleEffectImage); + _spriteBatch.Draw(_particleEffectJson); + _spriteBatch.Draw(_particleEffectJsonString); + } + _spriteBatch.End(); + + base.Draw(gameTime); + } + protected override void Initialize() { ParticleInitSquare(); ParticleInitImage(); ParticleInitJson(); + ParticleInitJsonString(); base.Initialize(); } - private void ParticleInitSquare() + protected override void LoadContent() { - _particleEffectSquare = new ParticleEffect(); - Texture2D blankTexture = new Texture2D(GraphicsDevice, 1, 1); - blankTexture.SetData(new[] { Color.White }); + _spriteBatch = new SpriteBatch(GraphicsDevice); + } - Dictionary Modifiers = new Dictionary - { - { - "effect1", new ColourInterpolator2 - { - InitialColour = new Colour(0.33f, 0.5f, 0.5f), - FinalColour = new Colour(0f, 0.5f, 0.5f) - } - }, - { - "effect2", new RotationModifier - { - RotationRate = 1f - } + protected override void Update(GameTime gameTime) + { + //Square + _particleEffectSquare.Update((float)gameTime.ElapsedGameTime.TotalSeconds); + _particleEffectSquare.Trigger(new Vector(150, 350)); - }, - { - "effect3", new RectContainerModifier - { - Height = 100, - Width = 100, - } - } - }; + //Image + _particleEffectImage.Update((float)gameTime.ElapsedGameTime.TotalSeconds); + _particleEffectImage.Trigger(new Vector(400, 250)); - _particleEffectSquare.Emitters.Add("test", new Emitter(2000, TimeSpan.FromSeconds(2), Profile.Point()) + //Json + _particleEffectJson.Update((float)gameTime.ElapsedGameTime.TotalSeconds); + _particleJsonPosition.Y += 10; + _particleEffectJson.Trigger(_particleJsonPosition); + + _particleEffectJsonString.Update((float)gameTime.ElapsedGameTime.TotalSeconds); + _particleEffectJsonString.Trigger(new Vector(150, 150)); + + if (_particleJsonPosition.Y > 1000) { - Texture = blankTexture, - BlendMode = BlendMode.Alpha, - Parameters = new ReleaseParameters - { - Speed = new RangeF(20f, 50f), - Quantity = 3, - }, - Modifiers = Modifiers - }); + _particleJsonPosition.Y = 0; + } + + base.Update(gameTime); } private void ParticleInitImage() @@ -92,14 +95,12 @@ private void ParticleInitImage() InitialScale = new Vector(10,10), FinalScale = new Vector(20,20) } - }, { "effect2", new RotationModifier { RotationRate = 1f } - }, { "effect3", new LinearGravityModifier @@ -136,47 +137,86 @@ private void ParticleInitJson() } } - protected override void LoadContent() - { - _spriteBatch = new SpriteBatch(GraphicsDevice); - } - - protected override void Update(GameTime gameTime) + private void ParticleInitJsonString() { - //Square - _particleEffectSquare.Update((float)gameTime.ElapsedGameTime.TotalSeconds); - _particleEffectSquare.Trigger(new Vector(150, 350)); + TextReader reader = null; + string fileContents = ""; - //Image - _particleEffectImage.Update((float)gameTime.ElapsedGameTime.TotalSeconds); - _particleEffectImage.Trigger(new Vector(400, 250)); - - //Json - _particleEffectJson.Update((float)gameTime.ElapsedGameTime.TotalSeconds); - _particleJsonPosition.Y += 10; - _particleEffectJson.Trigger(_particleJsonPosition); - - if (_particleJsonPosition.Y > 1000) + try { - _particleJsonPosition.Y = 0; + reader = new StreamReader(Content.RootDirectory + "/testParticle2.ptc"); + fileContents = reader.ReadToEnd(); + Console.WriteLine(fileContents); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + finally + { + if (reader != null) + reader.Close(); } - base.Update(gameTime); + if (fileContents != null) + { + _particleEffectJsonString = ParticleEffect.ReadFromJson( + Content.RootDirectory + "\\", + fileContents, + GraphicsDevice, Content); + + foreach (var item in _particleEffectJsonString.Emitters) + { + if (string.IsNullOrEmpty(item.Value.TexturePath)) + { + item.Value.Texture = new Texture2D(GraphicsDevice, 1, 1); + item.Value.Texture.SetData(new[] { Color.White }); + } + } + } } - protected override void Draw(GameTime gameTime) + private void ParticleInitSquare() { - GraphicsDevice.Clear(Color.Black); + _particleEffectSquare = new ParticleEffect(); + Texture2D blankTexture = new Texture2D(GraphicsDevice, 1, 1); + blankTexture.SetData(new[] { Color.White }); - _spriteBatch.Begin(); + Dictionary Modifiers = new Dictionary { - _spriteBatch.Draw(_particleEffectSquare); - _spriteBatch.Draw(_particleEffectImage); - _spriteBatch.Draw(_particleEffectJson); - } - _spriteBatch.End(); + { + "effect1", new ColourInterpolator2 + { + InitialColour = new Colour(0.33f, 0.5f, 0.5f), + FinalColour = new Colour(0f, 0.5f, 0.5f) + } + }, + { + "effect2", new RotationModifier + { + RotationRate = 1f + } + }, + { + "effect3", new RectContainerModifier + { + Height = 100, + Width = 100, + } + } + }; - base.Draw(gameTime); + _particleEffectSquare.Emitters.Add("test", new Emitter(2000, TimeSpan.FromSeconds(2), Profile.Point()) + { + Texture = blankTexture, + BlendMode = BlendMode.Alpha, + Parameters = new ReleaseParameters + { + Speed = new RangeF(20f, 50f), + Quantity = 3, + }, + Modifiers = Modifiers + }); } } } \ No newline at end of file diff --git a/Demo/libs/VenusParticleEngine.dll b/Demo/libs/VenusParticleEngine.dll index 0d66679..d57e3df 100644 Binary files a/Demo/libs/VenusParticleEngine.dll and b/Demo/libs/VenusParticleEngine.dll differ diff --git a/Demo/libs/VenusParticleEngine.pdb b/Demo/libs/VenusParticleEngine.pdb index 5e09a13..4af5370 100644 Binary files a/Demo/libs/VenusParticleEngine.pdb and b/Demo/libs/VenusParticleEngine.pdb differ diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 23d17c9..f152118 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.1")] -[assembly: AssemblyFileVersion("1.0.0.1")] +[assembly: AssemblyVersion("1.0.0.2")] +[assembly: AssemblyFileVersion("1.0.0.2")]