/// <summary> /// This function generates a new array of particle sprites to attach to the emitter. /// </summary> /// <param name="graphics">Texture for the particles - can be one square or a spritesheet. Set Multiple to true if it is a spritesheet and it will automatically create the particles as long as each frame on the spritesheet is square</param> /// <param name="Multiple">Whether or not the Texture contains multiple sprites for particles</param> /// <param name="Quantity">The number of particles to generate</param> /// <param name="Rotation">The amount of rotation in degrees per frame, so keep this number low</param> /// <param name="Collide">The collidability of the particle, 1 = Full and 0 = None</param> /// <returns>This FlxEmitter instance (nice for chaining stuff together, if you're into that).</returns> //public FlxEmitter makeParticles(Texture2D graphics, bool Multiple=false, uint Quantity = 50, float Rotation = 1f, float Collide = 0.8f) public FlxEmitter makeParticles(Texture2D graphics, uint Quantity = 50, uint BakedRotations = 0, bool Multiple = false, float Collide = 0.8f) { maxSize = Quantity; if (Multiple || BakedRotations > 0) { throw new NotSupportedException(); } for (int i = 0; i < Quantity; ++i) { var particle = new FlxParticle(); particle.loadGraphic(graphics); if (Collide > 0) { particle.Width = particle.Width * Collide; particle.Height = particle.Height * Collide; particle.centerOffsets(); } else { particle.AllowCollisions = FlxObject.None; } particle.Exists = false; this.add(particle); } /* FlxParticle particle; uint i = 0; while(i < Quantity) { particle = new FlxParticle(); if (Multiple) particle.loadParticleGraphic(Graphic, Rotation); else particle.loadGraphic(Graphic); if(Collide > 0) { particle.width *= Collide; particle.height *= Collide; particle.centerOffsets(); } else particle.allowCollisions = FlxObject.NONE; particle.exists = false; add(particle); i++; } */ return this; }
/// <summary> /// This function generates a new array of sprites to attach to the emitter. /// </summary> /// <param name="graphics">If you opted to not pre-configure an array of FlxSprite objects, you can simply pass in a particle image or sprite sheet.</param> /// <param name="quantity">The number of particles to generate when using the "create from image" option.</param> /// <param name="Multiple">Whether the image in the graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!).</param> /// <param name="Collide">Whether the particles should be flagged as not 'dead' (non-colliding particles are higher performance). 0 means no collisions, 0-1 controls scale of particle's bounding box.</param> /// <param name="Bounce">Whether the particles should bounce after colliding with things. 0 means no bounce, 1 means full reflection.</param> /// <returns>his FlxEmitter instance (nice for chaining stuff together, if you're into that).</returns> public FlxEmitter CreateSprites(Texture2D graphics, int quantity, bool Multiple, float Collide, float Bounce) { members = new List<FlxObject>(); int r; FlxSprite s; int tf = 1; float sw; float sh; if(Multiple) { s = new FlxSprite(); s.LoadGraphic(graphics,true); tf = s.frames; } int i = 0; while(i < quantity) { if((Collide > 0) && (Bounce > 0)) s = new FlxParticle(Bounce) as FlxSprite; else s = new FlxSprite(); if(Multiple) { r = (int)(FlxU.random()*tf); //if(BakedRotations > 0) // s.loadRotatedGraphic(graphics,BakedRotations,r); //else //{ s.LoadGraphic(graphics,true); s.frame = r; //} } else { //if(BakedRotations > 0) // s.loadRotatedGraphic(graphics,BakedRotations); //else s.LoadGraphic(graphics); } if(Collide > 0) { sw = s.Width; sh = s.Height; s.Width = (int)(s.Width * Collide); s.Height = (int)(s.Height * Collide); s.offset.X = (int)(sw-s.Width)/2; s.offset.Y = (int)(sh-s.Height)/2; s.Solid = true; } else s.Solid = false; s.Exists = false; s.scrollFactor = scrollFactor; Add(s); i++; } return this; }