public override void AddParticles(Vector2 size) { if (surfaceLoaded) { if (!inited) { InitSmoke(size); } // 添加的数量 var m = (int)(size.X * minDensity); var n = (int)(size.X * maxDensity); var actualAdd = Tools.Random.Next(m, n) - ActiveParticles.Count; if (actualAdd < 0) { actualAdd = 0; } // 激活这些粒子 for (int i = 0; i < actualAdd; i++) { // 从空闲粒子堆里取粒子,如果没有,那么就 new 一个 Particle particle = (FreeParticles.Count > 0) ? FreeParticles.Pop() : new Particle(); particle.Key = Tools.Random.Next(0, smokeSurfaceName[flag].Length); var where = new Vector2(0 - (float)(surfacesBounds[particle.Key].Width / 2), Tools.RandomBetween(0 - (float)(surfacesBounds[particle.Key].Height / 2), size.Y / 5 - (float)(surfacesBounds[particle.Key].Height / 2))); // 初始化粒子参数 InitializeParticle(particle, where); // 将此粒子加入激活粒子队列 if (ActiveParticles.Capacity <= ActiveParticles.Count) { ActiveParticles.Capacity = ActiveParticles.Count * 2; } ActiveParticles.Add(particle); } } }
public override void AddParticle() { Particle Snowflake = new Particle(Texture, LifeTime); Snowflake.Color = Color.White; Snowflake.Scale = new Vector2(1, 1); Snowflake.Alpha = 1.0f; Snowflake.LayerDepth = 0.81f; //RANDOM POSITION OF SNOW float X = (float)Randomizer.Next((int)startPosition.X, topLength); float Y = (float)Randomizer.Next((int)startPosition.Y, sideLength); Snowflake.Position = new Vector2(X, Y); //RANDOM VELOCITY OF SNOW Snowflake.Velocity.X = 0; Snowflake.Velocity.Y = 100; Snowflake.Alive = true; ActiveParticles.Add(Snowflake); //MAKES THE PARTICLE ACTIVE } //THE LOGIC BEHIND WHEN TO ADD MORE PARTICLES
public override void AddParticle() { if (elaspedtime > mSpawnTime && ActiveParticles.Count < mMaxParticles) { ActiveParticles.Add(Randomize_Particle()); elaspedtime = 0; } }
public override void AddParticle() { Particle SnowTrail = new Particle(Texture, LifeTime); SnowTrail.Color = Color.White; SnowTrail.Scale = new Vector2(0.9f, 0.7f); SnowTrail.Alpha = 1.0f; SnowTrail.Position = EmitterPosition; SnowTrail.LayerDepth = 0.01f; SnowTrail.Alive = true; ActiveParticles.Add(SnowTrail); }
/// <summary> /// 获得画布尺寸,在画布顶部生成粒子 /// </summary> /// <param name="size"></param> public void AddRainDrop(Vector2 size) { { if (surfaceLoaded) { numParticles += (Tools.RandomBetween(minDensity, maxDensity) * size.X); var actualAdd = (int)numParticles; numParticles %= 1; for (int i = 0; i < actualAdd; i++) { Particle particle = (FreeParticles.Count > 0) ? FreeParticles.Pop() : new Particle(); float x = Tools.RandomBetween(0 - size.Y * (float)Math.Tan(1.5708 - (minRotationAngle + maxRotationAngle) / 2), size.X); InitializeParticle(particle, new Vector2(x, -5)); if (ActiveParticles.Capacity <= ActiveParticles.Count) { ActiveParticles.Capacity = ActiveParticles.Count * 2; } ActiveParticles.Add(particle); } } } }
private void InitSmoke(Vector2 size) { var m = (int)(size.X * minDensity); var n = (int)(size.X * maxDensity); var add = Tools.Random.Next(m, n); for (int i = 0; i < add; i++) { // 从空闲粒子堆里取粒子,如果没有,那么就 new 一个 Particle particle = (FreeParticles.Count > 0) ? FreeParticles.Pop() : new Particle(); particle.Key = Tools.Random.Next(0, smokeSurfaceName[flag].Length); var where = new Vector2(Tools.RandomBetween(0 - (float)(surfacesBounds[particle.Key].Width / 2), size.X + (float)(surfacesBounds[particle.Key].Width / 2)), Tools.RandomBetween((0 - (float)(surfacesBounds[particle.Key].Height / 2)), size.Y / 5 - (float)(surfacesBounds[particle.Key].Height / 2))); // 初始化粒子参数 InitializeParticle(particle, where); // 将此粒子加入激活粒子队列 if (ActiveParticles.Capacity <= ActiveParticles.Count) { ActiveParticles.Capacity = ActiveParticles.Count * 2; } ActiveParticles.Add(particle); } inited = true; }
public override void AddParticle() { ActiveParticles.Add(RandomizeParticle()); }