Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
 /// <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);
             }
         }
     }
 }
Ejemplo n.º 3
0
        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;
        }