Exemplo n.º 1
0
        public CCParticleMeteor(CCPoint position, CCEmitterMode emitterMode = CCEmitterMode.Gravity) : base(150, emitterMode)
        {
            Duration     = ParticleDurationInfinity;
            Life         = 2;
            LifeVar      = 1;
            Position     = position;
            PositionVar  = CCPoint.Zero;
            Angle        = 90;
            AngleVar     = 360;
            StartSize    = 60.0f;
            StartSizeVar = 10.0f;
            EndSize      = ParticleStartSizeEqualToEndSize;

            EmissionRate = TotalParticles / Life;

            StartColor    = new CCColor4F(0.2f, 0.4f, 0.7f, 1.0f);
            StartColorVar = new CCColor4F(0.0f, 0.0f, 0.2f, 0.1f);
            EndColor      = new CCColor4F(0.0f, 0.0f, 0.0f, 1.0f);
            EndColorVar   = new CCColor4F();

            GravityMoveMode gravityMode = new GravityMoveMode();

            gravityMode.Gravity            = new CCPoint(-200, 200);
            gravityMode.RadialAccel        = 0;
            gravityMode.RadialAccelVar     = 0;
            gravityMode.Speed              = 15;
            gravityMode.SpeedVar           = 5;
            gravityMode.TangentialAccel    = 0;
            gravityMode.TangentialAccelVar = 0;
            GravityMode = gravityMode;

            BlendAdditive = true;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 2
0
        public CCParticleFlower(CCPoint position) : base(250)
        {
            Duration     = ParticleDurationInfinity;
            Life         = 4;
            LifeVar      = 1;
            Position     = position;
            PositionVar  = CCPoint.Zero;
            Angle        = 90;
            AngleVar     = 360;
            StartSize    = 30.0f;
            StartSizeVar = 10.0f;
            EndSize      = ParticleStartSizeEqualToEndSize;

            EmissionRate = TotalParticles / Life;

            StartColor    = new CCColor4F(0.5f, 0.5f, 0.5f, 1.0f);
            StartColorVar = new CCColor4F(0.5f, 0.5f, 0.5f, 0.5f);
            EndColor      = new CCColor4F(0.0f, 0.0f, 0.0f, 1.0f);
            EndColorVar   = new CCColor4F();

            GravityMoveMode gravityMode = new GravityMoveMode();

            gravityMode.Gravity            = new CCPoint(0, 0);
            gravityMode.RadialAccel        = -60;
            gravityMode.RadialAccelVar     = 0;
            gravityMode.Speed              = 80;
            gravityMode.SpeedVar           = 10;
            gravityMode.TangentialAccel    = 15;
            gravityMode.TangentialAccelVar = 0;
            GravityMode = gravityMode;

            BlendAdditive = true;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 3
0
        public CCParticleSun(CCPoint position, int num, CCEmitterMode emitterMode = CCEmitterMode.Gravity) : base(num, emitterMode)
        {
            Duration     = ParticleDurationInfinity;
            Life         = 1;
            LifeVar      = 0.5f;
            Position     = position;
            PositionVar  = CCPoint.Zero;
            Angle        = 90;
            AngleVar     = 360;
            StartSize    = 30.0f;
            StartSizeVar = 10.0f;
            EndSize      = ParticleStartSizeEqualToEndSize;

            EmissionRate = TotalParticles / Life;

            StartColor    = new CCColor4F(0.76f, 0.25f, 0.12f, 1.0f);
            StartColorVar = new CCColor4F();
            EndColor      = new CCColor4F(0.0f, 0.0f, 0.0f, 1.0f);
            EndColorVar   = new CCColor4F();

            GravityMoveMode gravityMode = new GravityMoveMode();

            gravityMode.Gravity        = new CCPoint(0, 0);
            gravityMode.RadialAccel    = 0;
            gravityMode.RadialAccelVar = 0;
            gravityMode.Speed          = 20;
            gravityMode.SpeedVar       = 5;
            GravityMode = gravityMode;

            BlendAdditive = true;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 4
0
        public CCParticleExplosion(CCPoint position, CCEmitterMode emitterMode = CCEmitterMode.Gravity) : base(700, emitterMode)
        {
            Duration     = 0.1f;
            Life         = 5.0f;
            LifeVar      = 2;
            Position     = new CCPoint(position);
            PositionVar  = CCPoint.Zero;
            Angle        = 90;
            AngleVar     = 360;
            StartSize    = 15.0f;
            StartSizeVar = 10.0f;
            EndSize      = ParticleStartSizeEqualToEndSize;

            EmissionRate = TotalParticles / Duration;

            StartColor    = new CCColor4F(0.7f, 0.1f, 0.2f, 1.0f);
            StartColorVar = new CCColor4F(0.5f, 0.5f, 0.5f, 0.0f);
            EndColor      = new CCColor4F(0.5f, 0.5f, 0.5f, 0.0f);
            EndColorVar   = new CCColor4F(0.5f, 0.5f, 0.5f, 0.0f);

            GravityMoveMode gravityMode = new GravityMoveMode();

            gravityMode.Gravity            = new CCPoint(0, 0);
            gravityMode.RadialAccel        = 0;
            gravityMode.RadialAccelVar     = 0;
            gravityMode.Speed              = 70;
            gravityMode.SpeedVar           = 40;
            gravityMode.TangentialAccel    = 0;
            gravityMode.TangentialAccelVar = 0;
            GravityMode = gravityMode;

            BlendAdditive = false;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 5
0
        public CCParticleSpiral(CCPoint position, CCEmitterMode emitterMode = CCEmitterMode.Gravity) : base(500, emitterMode)
        {
            Duration     = ParticleDurationInfinity;
            Position     = position;
            PositionVar  = CCPoint.Zero;
            Life         = 12;
            LifeVar      = 0;
            Angle        = 90;
            AngleVar     = 0;
            StartSize    = 20.0f;
            StartSizeVar = 0.0f;
            EndSize      = ParticleStartSizeEqualToEndSize;

            EmissionRate = TotalParticles / Life;

            StartColor    = new CCColor4F(0.5f, 0.5f, 0.5f, 1.0f);
            StartColorVar = new CCColor4F(0.5f, 0.5f, 0.5f, 0.0f);
            EndColor      = new CCColor4F(0.5f, 0.5f, 0.5f, 1.0f);
            EndColorVar   = new CCColor4F(0.5f, 0.5f, 0.5f, 0.0f);

            GravityMoveMode gravityMode = new GravityMoveMode();

            gravityMode.Gravity            = new CCPoint(0, 0);
            gravityMode.RadialAccel        = -380;
            gravityMode.RadialAccelVar     = 0;
            gravityMode.Speed              = 150;
            gravityMode.SpeedVar           = 0;
            gravityMode.TangentialAccel    = 45;
            gravityMode.TangentialAccelVar = 0;
            GravityMode = gravityMode;

            BlendAdditive = false;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 6
0
        public CCParticleSnow(CCPoint position, CCEmitterMode emitterMode = CCEmitterMode.Gravity) : base(700, emitterMode)
        {
            Duration     = ParticleDurationInfinity;
            Life         = 45;
            LifeVar      = 15;
            Position     = position;
            PositionVar  = new CCPoint(position.X, 0);
            Angle        = -90;
            AngleVar     = 5;
            StartSize    = 10.0f;
            StartSizeVar = 5.0f;
            EndSize      = ParticleStartSizeEqualToEndSize;

            EmissionRate = 10;

            StartColor    = new CCColor4F(1.0f, 1.0f, 1.0f, 1.0f);
            StartColorVar = new CCColor4F();
            EndColor      = new CCColor4F(1.0f, 1.0f, 1.0f, 0.0f);
            EndColorVar   = new CCColor4F();

            GravityMoveMode gravityMode = new GravityMoveMode();

            gravityMode.Gravity            = new CCPoint(0, -1);
            gravityMode.RadialAccel        = 0;
            gravityMode.RadialAccelVar     = 1;
            gravityMode.TangentialAccel    = 0;
            gravityMode.TangentialAccelVar = 1;
            gravityMode.Speed    = 5;
            gravityMode.SpeedVar = 1;
            GravityMode          = gravityMode;

            BlendAdditive = false;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 7
0
        public CCParticleSmoke(CCPoint position, CCEmitterMode emitterMode = CCEmitterMode.Gravity) : base(200, emitterMode)
        {
            Duration     = ParticleDurationInfinity;
            Life         = 4;
            LifeVar      = 1;
            Position     = position;
            PositionVar  = new CCPoint(20, 0);
            Angle        = 90;
            AngleVar     = 5;
            StartSize    = 60.0f;
            StartSizeVar = 10.0f;
            EndSize      = ParticleStartSizeEqualToEndSize;

            EmissionRate = TotalParticles / Life;

            StartColor    = new CCColor4F(0.8f, 0.8f, 0.8f, 1.0f);
            StartColorVar = new CCColor4F(0.02f, 0.02f, 0.02f, 0.0f);
            EndColor      = new CCColor4F(0.0f, 0.0f, 0.0f, 1.0f);
            EndColorVar   = new CCColor4F();

            GravityMoveMode gravityMode = new GravityMoveMode();

            gravityMode.Gravity        = new CCPoint(0, 0);
            gravityMode.RadialAccel    = 0;
            gravityMode.RadialAccelVar = 0;
            gravityMode.Speed          = 25;
            gravityMode.SpeedVar       = 10;
            GravityMode = gravityMode;

            BlendAdditive = false;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 8
0
        public CCParticleRain(CCPoint position, CCEmitterMode emitterMode = CCEmitterMode.Gravity) : base(1000, emitterMode)
        {
            Duration     = ParticleDurationInfinity;
            Position     = position;
            PositionVar  = new CCPoint(position.X, 0);
            Life         = 4.5f;
            LifeVar      = 0;
            Angle        = -90;
            AngleVar     = 5;
            StartSize    = 4.0f;
            StartSizeVar = 2.0f;
            EndSize      = ParticleStartSizeEqualToEndSize;

            EmissionRate = 20;

            StartColor    = new CCColor4F(0.7f, 0.8f, 1.0f, 1.0f);
            StartColorVar = new CCColor4F();
            EndColor      = new CCColor4F(0.7f, 0.8f, 1.0f, 0.5f);
            EndColorVar   = new CCColor4F();

            GravityMoveMode gravityMode = new GravityMoveMode();

            gravityMode.Gravity            = new CCPoint(10, -10);
            gravityMode.RadialAccel        = 0;
            gravityMode.RadialAccelVar     = 1;
            gravityMode.TangentialAccel    = 0;
            gravityMode.TangentialAccelVar = 1;
            gravityMode.Speed    = 130;
            gravityMode.SpeedVar = 30;
            GravityMode          = gravityMode;

            BlendAdditive = false;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 9
0
        public void DrawSegment(CCPoint from, CCPoint to, float radius, CCColor4F color)
        {
            var cl = color;

            var a = from;
            var b = to;

            var n = CCPoint.Normalize(CCPoint.PerpendicularCCW(a - b));

            var lww = radius;
            var nw  = n * lww;
            var v0  = b - nw;
            var v1  = b + nw;
            var v2  = a - nw;
            var v3  = a + nw;

            // Triangles from beginning to end
            AddTriangleVertex(new CCV3F_C4B(v1, cl));
            AddTriangleVertex(new CCV3F_C4B(v2, cl));
            AddTriangleVertex(new CCV3F_C4B(v0, cl));

            AddTriangleVertex(new CCV3F_C4B(v1, cl));
            AddTriangleVertex(new CCV3F_C4B(v2, cl));
            AddTriangleVertex(new CCV3F_C4B(v3, cl));

            var mb = (float)Math.Atan2(v1.Y - b.Y, v1.X - b.X);
            var ma = (float)Math.Atan2(v2.Y - a.Y, v2.X - a.X);

            // Draw rounded line caps
            DrawSolidArc(a, radius, ma, MathHelper.Pi, color);
            DrawSolidArc(b, radius, mb, MathHelper.Pi, color);

            dirty = true;
        }
Exemplo n.º 10
0
        // Update particle

        bool UpdateParticleBase(ref CCParticleBase particleBase, float dt)
        {
            particleBase.TimeToLive -= dt;

            if (particleBase.TimeToLive > 0)
            {
                CCColor4F color = particleBase.Color;
                color.R           += (particleBase.DeltaColor.R * dt);
                color.G           += (particleBase.DeltaColor.G * dt);
                color.B           += (particleBase.DeltaColor.B * dt);
                color.A           += (particleBase.DeltaColor.A * dt);
                particleBase.Color = color;

                particleBase.Size += (particleBase.DeltaSize * dt);
                if (particleBase.Size < 0)
                {
                    particleBase.Size = 0;
                }

                particleBase.Rotation += (particleBase.DeltaRotation * dt);

                return(true);
            }

            return(false);
        }
Exemplo n.º 11
0
        public void DrawSegment(CCPoint from, CCPoint to, float radius, CCColor4F color)
        {
            var cl = color.ToColor();

            var a = from;
            var b = to;

            var n = CCPoint.Normalize(CCPoint.PerpendicularCCW(a - b));

            var lww = radius;
            var nw  = n * lww;
            var v0  = b - nw;
            var v1  = b + nw;
            var v2  = a - nw;
            var v3  = a + nw;

            // Triangles from beginning to end
            triangleVertices.Add(new VertexPositionColor(v1.ToVector3(), cl));
            triangleVertices.Add(new VertexPositionColor(v2.ToVector3(), cl));
            triangleVertices.Add(new VertexPositionColor(v0.ToVector3(), cl));

            triangleVertices.Add(new VertexPositionColor(v1.ToVector3(), cl));
            triangleVertices.Add(new VertexPositionColor(v2.ToVector3(), cl));
            triangleVertices.Add(new VertexPositionColor(v3.ToVector3(), cl));

            var mb = (float)Math.Atan2(v1.Y - b.Y, v1.X - b.X);
            var ma = (float)Math.Atan2(v2.Y - a.Y, v2.X - a.X);

            // Draw rounded line caps
            DrawSolidArc(a, radius, ma, MathHelper.Pi, color);
            DrawSolidArc(b, radius, mb, MathHelper.Pi, color);

            dirty = true;
        }
Exemplo n.º 12
0
        void InitParticleBase(ref CCParticleBase particleBase)
        {
            float timeToLive = Math.Max(0, Life + LifeVar * CCRandom.Float_Minus1_1());

            particleBase.TimeToLive = timeToLive;

            CCPoint particlePos;

            particlePos.X         = SourcePosition.X + PositionVar.X * CCRandom.Float_Minus1_1();
            particlePos.Y         = SourcePosition.Y + PositionVar.Y * CCRandom.Float_Minus1_1();
            particleBase.Position = particlePos;

            CCColor4F start = new CCColor4F();

            start.R            = MathHelper.Clamp(StartColor.R + StartColorVar.R * CCRandom.Float_Minus1_1(), 0, 1);
            start.G            = MathHelper.Clamp(StartColor.G + StartColorVar.G * CCRandom.Float_Minus1_1(), 0, 1);
            start.B            = MathHelper.Clamp(StartColor.B + StartColorVar.B * CCRandom.Float_Minus1_1(), 0, 1);
            start.A            = MathHelper.Clamp(StartColor.A + StartColorVar.A * CCRandom.Float_Minus1_1(), 0, 1);
            particleBase.Color = start;

            CCColor4F end = new CCColor4F();

            end.R = MathHelper.Clamp(EndColor.R + EndColorVar.R * CCRandom.Float_Minus1_1(), 0, 1);
            end.G = MathHelper.Clamp(EndColor.G + EndColorVar.G * CCRandom.Float_Minus1_1(), 0, 1);
            end.B = MathHelper.Clamp(EndColor.B + EndColorVar.B * CCRandom.Float_Minus1_1(), 0, 1);
            end.A = MathHelper.Clamp(EndColor.A + EndColorVar.A * CCRandom.Float_Minus1_1(), 0, 1);

            CCColor4F deltaColor = new CCColor4F();

            deltaColor.R            = (end.R - start.R) / timeToLive;
            deltaColor.G            = (end.G - start.G) / timeToLive;
            deltaColor.B            = (end.B - start.B) / timeToLive;
            deltaColor.A            = (end.A - start.A) / timeToLive;
            particleBase.DeltaColor = deltaColor;

            float startSize = Math.Max(0, StartSize + StartSizeVar * CCRandom.Float_Minus1_1());

            particleBase.Size = startSize;

            if (EndSize == ParticleStartSizeEqualToEndSize)
            {
                particleBase.DeltaSize = 0;
            }
            else
            {
                float endS = EndSize + EndSizeVar * CCRandom.Float_Minus1_1();
                endS = Math.Max(0, endS);
                particleBase.DeltaSize = (endS - startSize) / timeToLive;
            }

            float startSpin = StartSpin + StartSpinVar * CCRandom.Float_Minus1_1();
            float endSpin   = EndSpin + EndSpinVar * CCRandom.Float_Minus1_1();

            particleBase.Rotation      = startSpin;
            particleBase.DeltaRotation = (endSpin - startSpin) / timeToLive;
            particleBase.StartPosition = Position;
        }
Exemplo n.º 13
0
        public override void doTest()
        {
            CCSize s = Layer.VisibleBoundsWorldspace.Size;
            var particleSystem = (CCParticleSystemQuad)GetChildByTag(PerformanceParticleTest.kTagParticleSystem);

            // duration
            particleSystem.Duration = -1;

            // gravity
            particleSystem.Gravity = (new CCPoint(0, -90));

            // angle
            particleSystem.Angle = 90;
            particleSystem.AngleVar = 0;

            // radial
            particleSystem.RadialAccel = (0);
            particleSystem.RadialAccelVar = (0);

            // speed of particles
            particleSystem.Speed = (180);
            particleSystem.SpeedVar = (50);

            // emitter position
            particleSystem.Position = new CCPoint(s.Width / 2, 100);
            particleSystem.PositionVar = new CCPoint(s.Width / 2, 0);

            // life of particles
            particleSystem.Life = 2.0f;
            particleSystem.LifeVar = 1;

            // emits per frame
            particleSystem.EmissionRate = particleSystem.TotalParticles / particleSystem.Life;

            // color of particles
            CCColor4F startColor = new CCColor4F { R = 0.5f, G = 0.5f, B = 0.5f, A = 1.0f };
            particleSystem.StartColor = startColor;

            CCColor4F startColorVar = new CCColor4F { R = 0.5f, G = 0.5f, B = 0.5f, A = 1.0f };
            particleSystem.StartColorVar = startColorVar;

            CCColor4F endColor = new CCColor4F { R = 0.1f, G = 0.1f, B = 0.1f, A = 0.2f };
            particleSystem.EndColor = endColor;

            CCColor4F endColorVar = new CCColor4F { R = 0.1f, G = 0.1f, B = 0.1f, A = 0.2f };
            particleSystem.EndColorVar = endColorVar;

            // size, in pixels
            particleSystem.EndSize = 64.0f;
            particleSystem.StartSize = 64.0f;
            particleSystem.EndSizeVar = 0;
            particleSystem.StartSizeVar = 0;

            // additive
            particleSystem.BlendAdditive = false;
        }
Exemplo n.º 14
0
        public CCParticleFireworks(CCPoint position, CCEmitterMode emitterMode = CCEmitterMode.Gravity) : base(1500, emitterMode)
        {
            Duration     = ParticleDurationInfinity;
            Life         = 3.5f;
            LifeVar      = 1;
            Position     = position;
            Angle        = 90;
            AngleVar     = 20;
            StartSize    = 8.0f;
            StartSizeVar = 2.0f;
            EndSize      = ParticleStartSizeEqualToEndSize;

            EmissionRate = TotalParticles / Life;

            StartColor = new CCColor4F(0.5f, 0.5f, 0.5f, 1.0f);

            CCColor4F startColorVar = new CCColor4F();

            startColorVar.R = 0.5f;
            startColorVar.G = 0.5f;
            startColorVar.B = 0.5f;
            startColorVar.A = 0.1f;
            StartColorVar   = startColorVar;

            CCColor4F endColor = new CCColor4F();

            endColor.R = 0.1f;
            endColor.G = 0.1f;
            endColor.B = 0.1f;
            endColor.A = 0.2f;
            EndColor   = endColor;

            CCColor4F endColorVar = new CCColor4F();

            endColorVar.R = 0.1f;
            endColorVar.G = 0.1f;
            endColorVar.B = 0.1f;
            endColorVar.A = 0.2f;
            EndColorVar   = endColorVar;

            GravityMoveMode gravityMode = new GravityMoveMode();

            gravityMode.Gravity        = new CCPoint(0, -90);
            gravityMode.RadialAccel    = 0;
            gravityMode.RadialAccelVar = 0;
            gravityMode.Speed          = 180;
            gravityMode.SpeedVar       = 50;
            GravityMode = gravityMode;

            BlendAdditive = false;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 15
0
        // See http://slabode.exofire.net/circle_draw.shtml
        // An Efficient Way to Draw Approximate Circles in OpenGL
        // Try to keep from calculating Cos and Sin of values everytime and just use
        // add and subtract where possible to calculate the values.
        public void DrawDot(CCPoint pos, float radius, CCColor4F color)
        {
            var cl = color;

            var segments = 10 * (float)Math.Sqrt(radius);              //<- Let's try to guess at # segments for a reasonable smoothness

            float theta            = MathHelper.Pi * 2.0f / segments;
            float tangetial_factor = (float)Math.Tan(theta); //calculate the tangential factor

            float radial_factor = (float)Math.Cos(theta);    //calculate the radial factor

            float x = radius;                                //we start at angle = 0
            float y = 0;

            var   verticeCenter = new CCV3F_C4B(pos, cl);
            var   vert1         = new CCV3F_C4B(CCVertex3F.Zero, cl);
            float tx            = 0;
            float ty            = 0;

            for (int i = 0; i < segments; i++)
            {
                vert1.Vertices.X = x + pos.X;
                vert1.Vertices.Y = y + pos.Y;
                AddTriangleVertex(vert1);                 // output vertex

                //calculate the tangential vector
                //remember, the radial vector is (x, y)
                //to get the tangential vector we flip those coordinates and negate one of them
                tx = -y;
                ty = x;

                //add the tangential vector
                x += tx * tangetial_factor;
                y += ty * tangetial_factor;

                //correct using the radial factor
                x *= radial_factor;
                y *= radial_factor;

                vert1.Vertices.X = x + pos.X;
                vert1.Vertices.Y = y + pos.Y;
                AddTriangleVertex(vert1);                 // output vertex

                AddTriangleVertex(verticeCenter);
            }

            dirty = true;
        }
Exemplo n.º 16
0
        public void DrawRect(CCRect rect, CCColor4B fillColor, float borderWidth,
                             CCColor4B borderColor)
        {
            float x1 = rect.MinX;
            float y1 = rect.MinY;
            float x2 = rect.MaxX;
            float y2 = rect.MaxY;

            CCPoint[] pt = new CCPoint[] {
                new CCPoint(x1, y1), new CCPoint(x2, y1), new CCPoint(x2, y2), new CCPoint(x1, y2)
            };
            CCColor4F cf = new CCColor4F(fillColor.R / 255f, fillColor.G / 255f, fillColor.B / 255f, fillColor.A / 255f);
            CCColor4F bc = new CCColor4F(borderColor.R / 255f, borderColor.G / 255f, borderColor.B / 255f, borderColor.A / 255f);

            DrawPolygon(pt, 4, cf, borderWidth, bc);
        }
Exemplo n.º 17
0
        public void DrawCircle(CCPoint center, float radius, float angle, int segments, CCColor4B color)
        {
            float  increment = MathHelper.Pi * 2.0f / segments;
            double theta     = 0.0;

            CCPoint        v1;
            List <CCPoint> verts = new List <CCPoint>();

            for (int i = 0; i < segments; i++)
            {
                v1 = center + new CCPoint((float)Math.Cos(theta), (float)Math.Sin(theta)) * radius;
                verts.Add(v1);
                theta += increment;
            }

            CCColor4F cf = new CCColor4F(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f);

            DrawPolygon(verts.ToArray(), verts.Count, cf, 0, new CCColor4F(0f, 0f, 0f, 0f));
        }
Exemplo n.º 18
0
 internal static Microsoft.Xna.Framework.Color ToColor(this CCColor4F color)
 {
     return(new Microsoft.Xna.Framework.Color(color.R, color.G, color.B, color.A));
 }
Exemplo n.º 19
0
        public CCParticleSpiral(CCPoint position, CCEmitterMode emitterMode=CCEmitterMode.Gravity) : base(500, emitterMode)
        {
            Duration = ParticleDurationInfinity;
            Position = position;
            PositionVar = CCPoint.Zero;
            Life = 12;
            LifeVar = 0;
            Angle = 90;
            AngleVar = 0;
            StartSize = 20.0f;
            StartSizeVar = 0.0f;
            EndSize = ParticleStartSizeEqualToEndSize;

            EmissionRate = TotalParticles / Life;

            StartColor = new CCColor4F(0.5f, 0.5f, 0.5f, 1.0f);
            StartColorVar = new CCColor4F(0.5f, 0.5f, 0.5f, 0.0f);
            EndColor = new CCColor4F(0.5f, 0.5f, 0.5f, 1.0f);
            EndColorVar = new CCColor4F(0.5f, 0.5f, 0.5f, 0.0f);

            GravityMoveMode gravityMode = new GravityMoveMode();
            gravityMode.Gravity = new CCPoint(0, 0);
            gravityMode.RadialAccel = -380;
            gravityMode.RadialAccelVar = 0;
            gravityMode.Speed = 150;
            gravityMode.SpeedVar = 0;
            gravityMode.TangentialAccel = 45;
            gravityMode.TangentialAccelVar = 0;
            GravityMode = gravityMode;

            BlendAdditive = false;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 20
0
        public CCParticleGalaxy(CCPoint position, CCEmitterMode emitterMode=CCEmitterMode.Gravity) : base(200, emitterMode)
        {
            Duration = ParticleDurationInfinity;
            Life = 4;
            LifeVar = 1;
            Position = position;
            PositionVar = CCPoint.Zero;
            Angle = 90;
            AngleVar = 360;
            StartSize = 37.0f;
            StartSizeVar = 10.0f;
            EndSize = ParticleStartSizeEqualToEndSize;

            EmissionRate = TotalParticles / Life;

            StartColor = new CCColor4F(0.12f, 0.25f, 0.76f, 1.0f);
            StartColorVar = new CCColor4F();
            EndColor = new CCColor4F(0.0f, 0.0f, 0.0f, 1.0f);
            EndColorVar = new CCColor4F();

            GravityMoveMode gravityMode = new GravityMoveMode();
            gravityMode.Gravity = new CCPoint(0, 0);
            gravityMode.RadialAccel = -80;
            gravityMode.RadialAccelVar = 0;
            gravityMode.Speed = 60;
            gravityMode.SpeedVar = 10;
            gravityMode.TangentialAccel = 80;
            gravityMode.TangentialAccelVar = 0;
            GravityMode = gravityMode;

            // additive
            BlendAdditive = true;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 21
0
        public CCParticleRain(CCPoint position, CCEmitterMode emitterMode=CCEmitterMode.Gravity) : base(1000, emitterMode)
        {
            Duration = ParticleDurationInfinity;
            Position = position;
            PositionVar = new CCPoint(position.X, 0);
            Life = 4.5f;
            LifeVar = 0;
            Angle = -90;
            AngleVar = 5;
            StartSize = 4.0f;
            StartSizeVar = 2.0f;
            EndSize = ParticleStartSizeEqualToEndSize;

            EmissionRate = 20;

            StartColor = new CCColor4F(0.7f, 0.8f, 1.0f, 1.0f);
            StartColorVar = new CCColor4F();
            EndColor = new CCColor4F(0.7f, 0.8f, 1.0f, 0.5f);
            EndColorVar = new CCColor4F();

            GravityMoveMode gravityMode = new GravityMoveMode();
            gravityMode.Gravity = new CCPoint(10, -10);
            gravityMode.RadialAccel = 0;
            gravityMode.RadialAccelVar = 1;
            gravityMode.TangentialAccel = 0;
            gravityMode.TangentialAccelVar = 1;
            gravityMode.Speed = 130;
            gravityMode.SpeedVar = 30;
            GravityMode = gravityMode;

            BlendAdditive = false;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 22
0
        public CCParticleSmoke(CCPoint position, CCEmitterMode emitterMode=CCEmitterMode.Gravity) : base(200, emitterMode)
        {
            Duration = ParticleDurationInfinity;
            Life = 4;
            LifeVar = 1;
            Position = position;
            PositionVar = new CCPoint(20, 0);
            Angle = 90;
            AngleVar = 5;
            StartSize = 60.0f;
            StartSizeVar = 10.0f;
            EndSize = ParticleStartSizeEqualToEndSize;

            EmissionRate = TotalParticles / Life;

            StartColor = new CCColor4F(0.8f, 0.8f, 0.8f, 1.0f);
            StartColorVar = new CCColor4F(0.02f, 0.02f, 0.02f, 0.0f);
            EndColor = new CCColor4F(0.0f, 0.0f, 0.0f, 1.0f);
            EndColorVar = new CCColor4F();

            GravityMoveMode gravityMode = new GravityMoveMode();
            gravityMode.Gravity = new CCPoint(0, 0);
            gravityMode.RadialAccel = 0;
            gravityMode.RadialAccelVar = 0;
            gravityMode.Speed = 25;
            gravityMode.SpeedVar = 10;
            GravityMode = gravityMode;

            BlendAdditive = false;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 23
0
        public void DrawPolygon(CCPoint[] verts, int count, CCColor4F fillColor, float borderWidth,
                                CCColor4F borderColor)
        {
            var extrude = new ExtrudeVerts[count];

            for (int i = 0; i < count; i++)
            {
                var v0 = verts[(i - 1 + count) % count];
                var v1 = verts[i];
                var v2 = verts[(i + 1) % count];

                var n1 = CCPoint.Normalize(CCPoint.PerpendicularCCW(v1 - v0));
                var n2 = CCPoint.Normalize(CCPoint.PerpendicularCCW(v2 - v1));

                var offset = (n1 + n2) * (1.0f / (CCPoint.Dot(n1, n2) + 1.0f));
                extrude[i] = new ExtrudeVerts()
                {
                    offset = offset, n = n2
                };
            }

            bool outline = (borderColor.A > 0.0f && borderWidth > 0.0f);

            var colorFill  = new CCColor4B(fillColor);
            var borderFill = new CCColor4B(borderColor);

            float inset = (!outline ? 0.5f : 0.0f);

            for (int i = 0; i < count - 2; i++)
            {
                var v0 = verts[0] - (extrude[0].offset * inset);
                var v1 = verts[i + 1] - (extrude[i + 1].offset * inset);
                var v2 = verts[i + 2] - (extrude[i + 2].offset * inset);

                AddTriangleVertex(new CCV3F_C4B(v0, colorFill)); //__t(v2fzero)
                AddTriangleVertex(new CCV3F_C4B(v1, colorFill)); //__t(v2fzero)
                AddTriangleVertex(new CCV3F_C4B(v2, colorFill)); //__t(v2fzero)
            }

            for (int i = 0; i < count; i++)
            {
                int j  = (i + 1) % count;
                var v0 = verts[i];
                var v1 = verts[j];

                var n0 = extrude[i].n;

                var offset0 = extrude[i].offset;
                var offset1 = extrude[j].offset;

                if (outline)
                {
                    var inner0 = (v0 - (offset0 * borderWidth));
                    var inner1 = (v1 - (offset1 * borderWidth));
                    var outer0 = (v0 + (offset0 * borderWidth));
                    var outer1 = (v1 + (offset1 * borderWidth));

                    AddTriangleVertex(new CCV3F_C4B(inner0, borderFill)); //__t(v2fneg(n0))
                    AddTriangleVertex(new CCV3F_C4B(inner1, borderFill)); //__t(v2fneg(n0))
                    AddTriangleVertex(new CCV3F_C4B(outer1, borderFill)); //__t(n0)

                    AddTriangleVertex(new CCV3F_C4B(inner0, borderFill)); //__t(v2fneg(n0))
                    AddTriangleVertex(new CCV3F_C4B(outer0, borderFill)); //__t(n0)
                    AddTriangleVertex(new CCV3F_C4B(outer1, borderFill)); //__t(n0)
                }
                else
                {
                    var inner0 = (v0 - (offset0 * 0.5f));
                    var inner1 = (v1 - (offset1 * 0.5f));
                    var outer0 = (v0 + (offset0 * 0.5f));
                    var outer1 = (v1 + (offset1 * 0.5f));

                    AddTriangleVertex(new CCV3F_C4B(inner0, colorFill)); //__t(v2fzero)
                    AddTriangleVertex(new CCV3F_C4B(inner1, colorFill)); //__t(v2fzero)
                    AddTriangleVertex(new CCV3F_C4B(outer1, colorFill)); //__t(n0)

                    AddTriangleVertex(new CCV3F_C4B(inner0, colorFill)); //__t(v2fzero)
                    AddTriangleVertex(new CCV3F_C4B(outer0, colorFill)); //__t(n0)
                    AddTriangleVertex(new CCV3F_C4B(outer1, colorFill)); //__t(n0)
                }
            }

            dirty = true;
        }
Exemplo n.º 24
0
		// See http://slabode.exofire.net/circle_draw.shtml
		// An Efficient Way to Draw Approximate Circles in OpenGL
		// Try to keep from calculating Cos and Sin of values everytime and just use
		// add and subtract where possible to calculate the values.
		public void DrawDot(CCPoint pos, float radius, CCColor4F color)
		{
			var cl = color.ToColor();

			var segments = 10 * (float)Math.Sqrt(radius);  //<- Let's try to guess at # segments for a reasonable smoothness

			float theta = MathHelper.Pi * 2.0f / segments; 
			float tangetial_factor = (float)Math.Tan(theta);   //calculate the tangential factor 

			float radial_factor = (float)Math.Cos(theta);   //calculate the radial factor 

			float x = radius;  //we start at angle = 0 
			float y = 0; 

			var verticeCenter = new VertexPositionColor(new Vector3(pos.X, pos.Y, 0), cl);
			var vert1 = new VertexPositionColor(Vector3.Zero, cl);
			float tx = 0; 
			float ty = 0; 

			for (int i = 0; i < segments; i++)
			{
			
				vert1.Position.X = x + pos.X;
				vert1.Position.Y = y + pos.Y;
				triangleVertices.Add(vert1); // output vertex

				//calculate the tangential vector 
				//remember, the radial vector is (x, y) 
				//to get the tangential vector we flip those coordinates and negate one of them 
				tx = -y; 
				ty = x; 

				//add the tangential vector 
				x += tx * tangetial_factor; 
				y += ty * tangetial_factor; 

				//correct using the radial factor 
				x *= radial_factor; 
				y *= radial_factor; 

				vert1.Position.X = x + pos.X;
				vert1.Position.Y = y + pos.Y;
				triangleVertices.Add(vert1); // output vertex

				triangleVertices.Add(verticeCenter);
			} 

			dirty = true;
		}
Exemplo n.º 25
0
        public void DrawPolygon(CCPoint[] verts, int count, CCColor4F fillColor, float borderWidth,
                                CCColor4F borderColor, bool closePolygon = true)
        {

            var polycount = count;

            var colorFill = new CCColor4B(fillColor);
            var borderFill = new CCColor4B(borderColor);

            bool outline = (borderColor.A > 0.0f && borderWidth > 0.0f);
            bool fill = fillColor.A > 0.0f;

            var numberOfTriangles = outline ? (3 * polycount - 2) : (polycount - 2);

            if (numberOfTriangles > 0 && fill && closePolygon)
            {
                for (int i = 1; i < polycount - 1; i++)
                {
                    AddTriangleVertex(new CCV3F_C4B(verts[0], colorFill));
                    AddTriangleVertex(new CCV3F_C4B(verts[i], colorFill));
                    AddTriangleVertex(new CCV3F_C4B(verts[i + 1], colorFill));
                }
            }
            else
            {
                for (int i = 0; i < polycount - 1; i++)
                {
                    DrawLine(verts[i], verts[i + 1], borderWidth, colorFill);
                }

            }

            if (outline)
            {
                var extrude = new ExtrudeVerts[polycount];

                for (int i = 0; i < polycount; i++)
                {
                    var v0 = verts[(i - 1 + polycount) % polycount];
                    var v1 = verts[i];
                    var v2 = verts[(i + 1) % polycount];

                    var n1 = CCPoint.Normalize(CCPoint.PerpendicularCCW(v1 - v0));
                    var n2 = CCPoint.Normalize(CCPoint.PerpendicularCCW(v2 - v1));

                    var offset = (n1 + n2) * (1.0f / (CCPoint.Dot(n1, n2) + 1.0f));
                    extrude[i] = new ExtrudeVerts() { offset = offset, n = n2 };
                }

                for (int i = 0; i < polycount - 2; i++)
                {
                    var v0 = verts[0];
                    var v1 = verts[i + 1];
                    var v2 = verts[i + 2];

                    AddTriangleVertex(new CCV3F_C4B(v0, colorFill)); //__t(v2fzero)
                    AddTriangleVertex(new CCV3F_C4B(v1, colorFill)); //__t(v2fzero)
                    AddTriangleVertex(new CCV3F_C4B(v2, colorFill)); //__t(v2fzero)
                }

                for (int i = 0; i < polycount - 1; i++)
                {
                    int j = (i + 1) % polycount;
                    var v0 = verts[i];
                    var v1 = verts[j];

                    var offset0 = extrude[i].offset;
                    var offset1 = extrude[j].offset;

                    var inner0 = (v0 - (offset0 * borderWidth));
                    var inner1 = (v1 - (offset1 * borderWidth));
                    var outer0 = (v0 + (offset0 * borderWidth));
                    var outer1 = (v1 + (offset1 * borderWidth));

                    AddTriangleVertex(new CCV3F_C4B(inner0, borderFill)); 
                    AddTriangleVertex(new CCV3F_C4B(inner1, borderFill)); 
                    AddTriangleVertex(new CCV3F_C4B(outer1, borderFill)); 

                    AddTriangleVertex(new CCV3F_C4B(inner0, borderFill)); 
                    AddTriangleVertex(new CCV3F_C4B(outer0, borderFill)); 
                    AddTriangleVertex(new CCV3F_C4B(outer1, borderFill)); 
                }

                if (closePolygon)
                {
                    for (int i = polycount - 1; i < polycount; i++)
                    {
                        int j = (i + 1) % polycount;
                        var v0 = verts[i];
                        var v1 = verts[j];

                        var offset0 = extrude[i].offset;
                        var offset1 = extrude[j].offset;

                        var inner0 = (v0 - (offset0 * borderWidth));
                        var inner1 = (v1 - (offset1 * borderWidth));
                        var outer0 = (v0 + (offset0 * borderWidth));
                        var outer1 = (v1 + (offset1 * borderWidth));

                        AddTriangleVertex(new CCV3F_C4B(inner0, borderFill)); 
                        AddTriangleVertex(new CCV3F_C4B(inner1, borderFill)); 
                        AddTriangleVertex(new CCV3F_C4B(outer1, borderFill)); 

                        AddTriangleVertex(new CCV3F_C4B(inner0, borderFill)); 
                        AddTriangleVertex(new CCV3F_C4B(outer0, borderFill)); 
                        AddTriangleVertex(new CCV3F_C4B(outer1, borderFill)); 
                    }
                }
            }
        
            dirty = true;
        }
Exemplo n.º 26
0
 public void DrawSegment(CCPoint from, CCPoint to, float radius, CCColor4F color, CCLineCap lineCap = CCLineCap.Round)
 {
     DrawLine(from, to, radius, (CCColor4B)color, lineCap);
 }
Exemplo n.º 27
0
        public CCParticleSystem(CCParticleSystemConfig particleConfig) : this(particleConfig.MaxParticles, false)
        {
            Duration     = particleConfig.Duration;;
            Life         = particleConfig.Life;
            LifeVar      = particleConfig.LifeVar;
            EmissionRate = TotalParticles / Life;

            Angle    = particleConfig.Angle;
            AngleVar = particleConfig.AngleVar;

            CCBlendFunc blendFunc = new CCBlendFunc();

            blendFunc.Source      = particleConfig.BlendFunc.Source;
            blendFunc.Destination = particleConfig.BlendFunc.Destination;
            BlendFunc             = blendFunc;

            CCColor4F startColor = new CCColor4F();

            startColor.R = particleConfig.StartColor.R;
            startColor.G = particleConfig.StartColor.G;
            startColor.B = particleConfig.StartColor.B;
            startColor.A = particleConfig.StartColor.A;
            StartColor   = startColor;

            CCColor4F startColorVar = new CCColor4F();

            startColorVar.R = particleConfig.StartColorVar.R;
            startColorVar.G = particleConfig.StartColorVar.G;
            startColorVar.B = particleConfig.StartColorVar.B;
            startColorVar.A = particleConfig.StartColorVar.A;
            StartColorVar   = startColorVar;

            CCColor4F endColor = new CCColor4F();

            endColor.R = particleConfig.EndColor.R;
            endColor.G = particleConfig.EndColor.G;
            endColor.B = particleConfig.EndColor.B;
            endColor.A = particleConfig.EndColor.A;
            EndColor   = endColor;

            CCColor4F endColorVar = new CCColor4F();

            endColorVar.R = particleConfig.EndColorVar.R;
            endColorVar.G = particleConfig.EndColorVar.G;
            endColorVar.B = particleConfig.EndColorVar.B;
            endColorVar.A = particleConfig.EndColorVar.A;
            EndColorVar   = endColorVar;

            StartSize    = particleConfig.StartSize;
            StartSizeVar = particleConfig.StartSizeVar;
            EndSize      = particleConfig.EndSize;
            EndSizeVar   = particleConfig.EndSizeVar;

            CCPoint position;

            position.X = particleConfig.Position.X;
            position.Y = particleConfig.Position.Y;
            Position   = position;

            CCPoint positionVar;

            positionVar.X = particleConfig.PositionVar.X;
            positionVar.Y = particleConfig.PositionVar.X;
            PositionVar   = positionVar;

            StartSpin    = particleConfig.StartSpin;
            StartSpinVar = particleConfig.StartSpinVar;
            EndSpin      = particleConfig.EndSpin;
            EndSpinVar   = particleConfig.EndSpinVar;

            EmitterMode = particleConfig.EmitterMode;

            if (EmitterMode == CCEmitterMode.Gravity)
            {
                GravityParticles = new CCParticleGravity[TotalParticles];

                GravityMoveMode newGravityMode = new GravityMoveMode();

                CCPoint gravity;
                gravity.X = particleConfig.Gravity.X;
                gravity.Y = particleConfig.Gravity.Y;
                newGravityMode.Gravity = gravity;

                newGravityMode.Speed              = particleConfig.GravitySpeed;
                newGravityMode.SpeedVar           = particleConfig.GravitySpeedVar;
                newGravityMode.RadialAccel        = particleConfig.GravityRadialAccel;
                newGravityMode.RadialAccelVar     = particleConfig.GravityRadialAccelVar;
                newGravityMode.TangentialAccel    = particleConfig.GravityTangentialAccel;
                newGravityMode.TangentialAccelVar = particleConfig.GravityTangentialAccelVar;
                newGravityMode.RotationIsDir      = particleConfig.GravityRotationIsDir;

                GravityMode = newGravityMode;
            }
            else if (EmitterMode == CCEmitterMode.Radius)
            {
                RadialParticles = new CCParticleRadial[TotalParticles];

                RadialMoveMode newRadialMode = new RadialMoveMode();

                newRadialMode.StartRadius        = particleConfig.RadialStartRadius;
                newRadialMode.StartRadiusVar     = particleConfig.RadialStartRadiusVar;
                newRadialMode.EndRadius          = particleConfig.RadialEndRadius;
                newRadialMode.EndRadiusVar       = particleConfig.RadialEndRadiusVar;
                newRadialMode.RotatePerSecond    = particleConfig.RadialRotatePerSecond;
                newRadialMode.RotatePerSecondVar = particleConfig.RadialRotatePerSecondVar;

                RadialMode = newRadialMode;
            }
            else
            {
                Debug.Assert(false, "Invalid emitterType in config file");
                return;
            }

            // Don't get the internal texture if a batchNode is used
            if (BatchNode == null)
            {
                Texture = particleConfig.Texture;
            }
        }
Exemplo n.º 28
0
        public void DrawPolygon(CCPoint[] verts, int count, CCColor4F fillColor, float borderWidth,
                                CCColor4F borderColor, bool closePolygon = true)
        {
            var polycount = count;

            var extrude = new ExtrudeVerts[polycount];

            for (int i = 0; i < polycount; i++)
            {
                var v0 = verts[(i - 1 + polycount) % polycount];
                var v1 = verts[i];
                var v2 = verts[(i + 1) % polycount];

                var n1 = CCPoint.Normalize(CCPoint.PerpendicularCCW(v1 - v0));
                var n2 = CCPoint.Normalize(CCPoint.PerpendicularCCW(v2 - v1));

                var offset = (n1 + n2) * (1.0f / (CCPoint.Dot(n1, n2) + 1.0f));
                extrude[i] = new ExtrudeVerts() {offset = offset, n = n2};
            }

            bool outline = (borderColor.A > 0.0f && borderWidth > 0.0f);

            var colorFill = new CCColor4B(fillColor);
            var borderFill = new CCColor4B(borderColor);
            
            float inset = (!outline ? 0.5f : 0.0f);
            
            for (int i = 0; i < polycount - 2; i++)
            {
                var v0 = verts[0] - (extrude[0].offset * inset);
                var v1 = verts[i + 1] - (extrude[i + 1].offset * inset);
                var v2 = verts[i + 2] - (extrude[i + 2].offset * inset);

                AddTriangleVertex(new CCV3F_C4B(v0, colorFill)); //__t(v2fzero)
                AddTriangleVertex(new CCV3F_C4B(v1, colorFill)); //__t(v2fzero)
                AddTriangleVertex(new CCV3F_C4B(v2, colorFill)); //__t(v2fzero)
            }

            //if (closePolygon)
            //{
            //    var i = polycount - 3;
            //    var v0 = verts[0] - (extrude[0].offset * inset);
            //    var v1 = verts[i + 1] - (extrude[i + 1].offset * inset);
            //    var v2 = verts[i + 2] - (extrude[i + 2].offset * inset);

            //    AddTriangleVertex(new CCV3F_C4B(v0, colorFill)); //__t(v2fzero)
            //    AddTriangleVertex(new CCV3F_C4B(v1, colorFill)); //__t(v2fzero)
            //    AddTriangleVertex(new CCV3F_C4B(v2, colorFill)); //__t(v2fzero)
            //}

            for (int i = 0; i < polycount - 1; i++)
            {
                int j = (i + 1) % polycount;
                var v0 = verts[i];
                var v1 = verts[j];

                var n0 = extrude[i].n;

                var offset0 = extrude[i].offset;
                var offset1 = extrude[j].offset;

                if (outline)
                {
                    var inner0 = (v0 - (offset0 * borderWidth));
                    var inner1 = (v1 - (offset1 * borderWidth));
                    var outer0 = (v0 + (offset0 * borderWidth));
                    var outer1 = (v1 + (offset1 * borderWidth));

                    AddTriangleVertex(new CCV3F_C4B(inner0, borderFill)); //__t(v2fneg(n0))
                    AddTriangleVertex(new CCV3F_C4B(inner1, borderFill)); //__t(v2fneg(n0))
                    AddTriangleVertex(new CCV3F_C4B(outer1, borderFill)); //__t(n0)

                    AddTriangleVertex(new CCV3F_C4B(inner0, borderFill)); //__t(v2fneg(n0))
                    AddTriangleVertex(new CCV3F_C4B(outer0, borderFill)); //__t(n0)
                    AddTriangleVertex(new CCV3F_C4B(outer1, borderFill)); //__t(n0)
                }
                else
                {
                    var inner0 = (v0 - (offset0 * 0.5f));
                    var inner1 = (v1 - (offset1 * 0.5f));
                    var outer0 = (v0 + (offset0 * 0.5f));
                    var outer1 = (v1 + (offset1 * 0.5f));

                    AddTriangleVertex(new CCV3F_C4B(inner0, colorFill)); //__t(v2fzero)
                    AddTriangleVertex(new CCV3F_C4B(inner1, colorFill)); //__t(v2fzero)
                    AddTriangleVertex(new CCV3F_C4B(outer1, colorFill)); //__t(n0)

                    AddTriangleVertex(new CCV3F_C4B(inner0, colorFill)); //__t(v2fzero)
                    AddTriangleVertex(new CCV3F_C4B(outer0, colorFill)); //__t(n0)
                    AddTriangleVertex(new CCV3F_C4B(outer1, colorFill)); //__t(n0)
                }
            }

            if (closePolygon)
            {
                for (int i = polycount - 1; i < polycount; i++)
                {
                    int j = (i + 1) % polycount;
                    var v0 = verts[i];
                    var v1 = verts[j];

                    var n0 = extrude[i].n;

                    var offset0 = extrude[i].offset;
                    var offset1 = extrude[j].offset;

                    if (outline)
                    {
                        var inner0 = (v0 - (offset0 * borderWidth));
                        var inner1 = (v1 - (offset1 * borderWidth));
                        var outer0 = (v0 + (offset0 * borderWidth));
                        var outer1 = (v1 + (offset1 * borderWidth));

                        AddTriangleVertex(new CCV3F_C4B(inner0, borderFill)); //__t(v2fneg(n0))
                        AddTriangleVertex(new CCV3F_C4B(inner1, borderFill)); //__t(v2fneg(n0))
                        AddTriangleVertex(new CCV3F_C4B(outer1, borderFill)); //__t(n0)

                        AddTriangleVertex(new CCV3F_C4B(inner0, borderFill)); //__t(v2fneg(n0))
                        AddTriangleVertex(new CCV3F_C4B(outer0, borderFill)); //__t(n0)
                        AddTriangleVertex(new CCV3F_C4B(outer1, borderFill)); //__t(n0)
                    }
                    else
                    {
                        var inner0 = (v0 - (offset0 * 0.5f));
                        var inner1 = (v1 - (offset1 * 0.5f));
                        var outer0 = (v0 + (offset0 * 0.5f));
                        var outer1 = (v1 + (offset1 * 0.5f));

                        AddTriangleVertex(new CCV3F_C4B(inner0, colorFill)); //__t(v2fzero)
                        AddTriangleVertex(new CCV3F_C4B(inner1, colorFill)); //__t(v2fzero)
                        AddTriangleVertex(new CCV3F_C4B(outer1, colorFill)); //__t(n0)

                        AddTriangleVertex(new CCV3F_C4B(inner0, colorFill)); //__t(v2fzero)
                        AddTriangleVertex(new CCV3F_C4B(outer0, colorFill)); //__t(n0)
                        AddTriangleVertex(new CCV3F_C4B(outer1, colorFill)); //__t(n0)
                    }
                }
            }
            dirty = true;
        }
Exemplo n.º 29
0
 public void DrawSegment(CCPoint from, CCPoint to, float radius, CCColor4F color)
 {
     DrawSegment(from, to, radius, (CCColor4B)color);
 }
Exemplo n.º 30
0
        void InitParticleBase(ref CCParticleBase particleBase)
        {
            float timeToLive = Math.Max(0, Life + LifeVar * CCRandom.Float_Minus1_1());
            particleBase.TimeToLive = timeToLive;

            CCPoint particlePos;
            particlePos.X = SourcePosition.X + PositionVar.X * CCRandom.Float_Minus1_1();
            particlePos.Y = SourcePosition.Y + PositionVar.Y * CCRandom.Float_Minus1_1();
            particleBase.Position = particlePos;

            CCColor4F start = new CCColor4F();
            start.R = MathHelper.Clamp(StartColor.R + StartColorVar.R * CCRandom.Float_Minus1_1(), 0, 1);
            start.G = MathHelper.Clamp(StartColor.G + StartColorVar.G * CCRandom.Float_Minus1_1(), 0, 1);
            start.B = MathHelper.Clamp(StartColor.B + StartColorVar.B * CCRandom.Float_Minus1_1(), 0, 1);
            start.A = MathHelper.Clamp(StartColor.A + StartColorVar.A * CCRandom.Float_Minus1_1(), 0, 1);
            particleBase.Color = start;

            CCColor4F end = new CCColor4F();
            end.R = MathHelper.Clamp(EndColor.R + EndColorVar.R * CCRandom.Float_Minus1_1(), 0, 1);
            end.G = MathHelper.Clamp(EndColor.G + EndColorVar.G * CCRandom.Float_Minus1_1(), 0, 1);
            end.B = MathHelper.Clamp(EndColor.B + EndColorVar.B * CCRandom.Float_Minus1_1(), 0, 1);
            end.A = MathHelper.Clamp(EndColor.A + EndColorVar.A * CCRandom.Float_Minus1_1(), 0, 1);

            CCColor4F deltaColor = new CCColor4F();
            deltaColor.R = (end.R - start.R) / timeToLive;
            deltaColor.G = (end.G - start.G) / timeToLive;
            deltaColor.B = (end.B - start.B) / timeToLive;
            deltaColor.A = (end.A - start.A) / timeToLive;
            particleBase.DeltaColor = deltaColor;

            float startSize = Math.Max(0, StartSize + StartSizeVar * CCRandom.Float_Minus1_1());
            particleBase.Size = startSize;

            if (EndSize == ParticleStartSizeEqualToEndSize)
            {
                particleBase.DeltaSize = 0;
            }
            else
            {
                float endS = EndSize + EndSizeVar * CCRandom.Float_Minus1_1();
                endS = Math.Max(0, endS);
                particleBase.DeltaSize = (endS - startSize) / timeToLive;
            }

            float startSpin = StartSpin + StartSpinVar * CCRandom.Float_Minus1_1();
            float endSpin = EndSpin + EndSpinVar * CCRandom.Float_Minus1_1();
            particleBase.Rotation = startSpin;
            particleBase.DeltaRotation = (endSpin - startSpin) / timeToLive;

            if (PositionType == CCPositionType.Free)
            {
                particleBase.StartPosition = Layer.VisibleBoundsWorldspace.Origin;
            }
            else if (PositionType == CCPositionType.Relative)
            {
                particleBase.StartPosition = Position;
            }
        }
Exemplo n.º 31
0
 public CCV2F_C4F_T2F()
 {
     Vertices = new CCVertex2F();
     Colors = new CCColor4F();
     TexCoords = new CCTex2F();
 }
Exemplo n.º 32
0
        public void DrawPolygon(CCPoint[] verts, int count, CCColor4F fillColor, float borderWidth,
                                CCColor4F borderColor)
        {
            var extrude = new ExtrudeVerts[count];

            for (int i = 0; i < count; i++)
            {
                var v0 = verts[(i - 1 + count) % count];
                var v1 = verts[i];
                var v2 = verts[(i + 1) % count];

                var n1 = CCPoint.Normalize(CCPoint.PerpendicularCCW(v1 - v0));
                var n2 = CCPoint.Normalize(CCPoint.PerpendicularCCW(v2 - v1));

                var offset = (n1 + n2) * (1.0f / (CCPoint.Dot(n1, n2) + 1.0f));
                extrude[i] = new ExtrudeVerts() {offset = offset, n = n2};
            }

            bool outline = (borderColor.A > 0.0f && borderWidth > 0.0f);

            var colorFill = fillColor.ToColor();
            var borderFill = borderColor.ToColor();
            
            float inset = (!outline ? 0.5f : 0.0f);
            
            for (int i = 0; i < count - 2; i++)
            {
                var v0 = verts[0] - (extrude[0].offset * inset);
                var v1 = verts[i + 1] - (extrude[i + 1].offset * inset);
                var v2 = verts[i + 2] - (extrude[i + 2].offset * inset);

                triangleVertices.Add(new VertexPositionColor(v0.ToVector3(), colorFill)); //__t(v2fzero)
                triangleVertices.Add(new VertexPositionColor(v1.ToVector3(), colorFill)); //__t(v2fzero)
                triangleVertices.Add(new VertexPositionColor(v2.ToVector3(), colorFill)); //__t(v2fzero)
            }

            for (int i = 0; i < count; i++)
            {
                int j = (i + 1) % count;
                var v0 = verts[i];
                var v1 = verts[j];

                var n0 = extrude[i].n;

                var offset0 = extrude[i].offset;
                var offset1 = extrude[j].offset;

                if (outline)
                {
                    var inner0 = (v0 - (offset0 * borderWidth));
                    var inner1 = (v1 - (offset1 * borderWidth));
                    var outer0 = (v0 + (offset0 * borderWidth));
                    var outer1 = (v1 + (offset1 * borderWidth));

                    triangleVertices.Add(new VertexPositionColor(inner0.ToVector3(), borderFill)); //__t(v2fneg(n0))
                    triangleVertices.Add(new VertexPositionColor(inner1.ToVector3(), borderFill)); //__t(v2fneg(n0))
                    triangleVertices.Add(new VertexPositionColor(outer1.ToVector3(), borderFill)); //__t(n0)

                    triangleVertices.Add(new VertexPositionColor(inner0.ToVector3(), borderFill)); //__t(v2fneg(n0))
                    triangleVertices.Add(new VertexPositionColor(outer0.ToVector3(), borderFill)); //__t(n0)
                    triangleVertices.Add(new VertexPositionColor(outer1.ToVector3(), borderFill)); //__t(n0)
                }
                else
                {
                    var inner0 = (v0 - (offset0 * 0.5f));
                    var inner1 = (v1 - (offset1 * 0.5f));
                    var outer0 = (v0 + (offset0 * 0.5f));
                    var outer1 = (v1 + (offset1 * 0.5f));

                    triangleVertices.Add(new VertexPositionColor(inner0.ToVector3(), colorFill)); //__t(v2fzero)
                    triangleVertices.Add(new VertexPositionColor(inner1.ToVector3(), colorFill)); //__t(v2fzero)
                    triangleVertices.Add(new VertexPositionColor(outer1.ToVector3(), colorFill)); //__t(n0)

                    triangleVertices.Add(new VertexPositionColor(inner0.ToVector3(), colorFill)); //__t(v2fzero)
                    triangleVertices.Add(new VertexPositionColor(outer0.ToVector3(), colorFill)); //__t(n0)
                    triangleVertices.Add(new VertexPositionColor(outer1.ToVector3(), colorFill)); //__t(n0)
                }
            }

            dirty = true;
        }
Exemplo n.º 33
0
        public RainbowEffect(int numOfParticles) : base(numOfParticles)
        {
            // additive
            BlendAdditive = (false);

            // duration
            Duration = (ParticleDurationInfinity);;

            // Gravity Mode: gravity
            Gravity = (new CCPoint(0, 0));

            // Gravity mode: radial acceleration
            RadialAccel = (0);
            RadialAccelVar = (0);

            // Gravity mode: speed of particles
            Speed = (120);
            SpeedVar = (0);


            // angle
            Angle = (180);
            AngleVar = (0);



            // life of particles
            Life = (0.5f);
            LifeVar = (0);

            // size, in pixels
            StartSize = (25.0f);
            StartSizeVar = (0);
            EndSize = (ParticleStartSizeEqualToEndSize);

            // emits per seconds
            EmissionRate = (TotalParticles / Life);

            // color of particles
            StartColor = (new CCColor4F(50, 50, 50, 50));
            EndColor = (new CCColor4F(0, 0, 0, 0));
            StartColorVar = new CCColor4F();
            EndColorVar = new CCColor4F();

            Texture = (CCTextureCache.SharedTextureCache.AddImage("Images/particles"));
        }
Exemplo n.º 34
0
        public CCParticleFire(CCPoint position, CCEmitterMode emitterMode=CCEmitterMode.Gravity) : base(250, emitterMode)
        {
            if (config == null) 
            {
                config = new CCParticleSystemConfig ();
                config.ParticleSystemType = CCParticleSystemType.Internal;

                config.Duration = ParticleDurationInfinity;
                config.Life = 3;
                config.LifeVar = 0.25f;
                config.Position = position;
                config.PositionVar = new CCPoint(40, 20);
                config.Angle = 90;
                config.AngleVar = 10;
                config.StartSize = 54.0f;
                config.StartSizeVar = 10.0f;
                config.EndSize = ParticleStartSizeEqualToEndSize;

                config.EmitterMode = CCEmitterMode.Gravity;

                CCColor4F cstartColor = new CCColor4F();
                cstartColor.R = 0.76f;
                cstartColor.G = 0.25f;
                cstartColor.B = 0.12f;
                cstartColor.A = 1.0f;
                config.StartColor = cstartColor;

                CCColor4F cstartColorVar = new CCColor4F();
                cstartColorVar.R = 0.0f;
                cstartColorVar.G = 0.0f;
                cstartColorVar.B = 0.0f;
                cstartColorVar.A = 0.0f;
                config.StartColorVar = cstartColorVar;

                CCColor4F cendColor = new CCColor4F();
                cendColor.R = 0.0f;
                cendColor.G = 0.0f;
                cendColor.B = 0.0f;
                cendColor.A = 1.0f;
                config.EndColor = cendColor;

                CCColor4F cendColorVar = new CCColor4F();
                cendColorVar.R = 0.0f;
                cendColorVar.G = 0.0f;
                cendColorVar.B = 0.0f;
                cendColorVar.A = 0.0f;
                config.EndColorVar = cendColorVar;

                config.Gravity = new CCPoint(0, 0);
                config.GravityRadialAccel = 0;
                config.GravityRadialAccelVar = 0;
                config.GravitySpeed = 60;
                config.GravitySpeedVar = 20;

                config.Texture = CCParticleExample.DefaultTexture;

            }

            Duration = config.Duration;
            Life = config.Life;
            LifeVar = config.LifeVar;
            Position = config.Position;
            PositionVar = config.PositionVar;
            Angle = config.Angle;
            AngleVar = config.AngleVar;
            StartSize = config.StartSize;
            StartSizeVar = config.StartSizeVar;
            EndSize = config.EndSize;

            EmissionRate = TotalParticles / Life;

            CCColor4F startColor = new CCColor4F();
            startColor.R = config.StartColor.R;
            startColor.G = config.StartColor.G;
            startColor.B = config.StartColor.B;
            startColor.A = config.StartColor.A;
            StartColor = startColor;

            CCColor4F startColorVar = new CCColor4F();
            startColorVar.R = config.StartColorVar.R;
            startColorVar.G = config.StartColorVar.G;
            startColorVar.B = config.StartColorVar.B;
            startColorVar.A = config.StartColorVar.A;
            StartColorVar = startColorVar;

            CCColor4F endColor = new CCColor4F();
            endColor.R = config.EndColor.R;
            endColor.G = config.EndColor.G;
            endColor.B = config.EndColor.B;
            endColor.A = config.EndColor.A;
            EndColor = endColor;

            CCColor4F endColorVar = new CCColor4F();
            endColorVar.R = config.EndColorVar.R;
            endColorVar.G = config.EndColorVar.G;
            endColorVar.B = config.EndColorVar.B;
            endColorVar.A = config.EndColorVar.A;
            EndColorVar = endColorVar;

            GravityMoveMode gravityMode = new GravityMoveMode();
            gravityMode.Gravity = new CCPoint(config.Gravity);
            gravityMode.RadialAccel = config.GravityRadialAccel;
            gravityMode.RadialAccelVar = config.GravityRadialAccelVar;
            gravityMode.Speed = config.GravitySpeed;
            gravityMode.SpeedVar = config.GravitySpeedVar;
            GravityMode = gravityMode;

            BlendAdditive = true;

            Texture = config.Texture;
        }
Exemplo n.º 35
0
        public override void OnEnter()
        {
base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;

            Emitter = new CCParticleSystemQuad(300);
            //Emitter.autorelease();

            Background.AddChild(Emitter, 10);
            ////Emitter.release();    // win32 : Remove this line
            Emitter.Texture = CCTextureCache.SharedTextureCache.AddImage(TestResource.s_stars2);

            // duration
            Emitter.Duration = -1;

            // gravity
            Emitter.Gravity = (new CCPoint(0, 0));

            // angle
            Emitter.Angle = 90;
            Emitter.AngleVar = 360;

            // speed of particles
            Emitter.Speed = (160);
            Emitter.SpeedVar = (20);

            // radial
            Emitter.RadialAccel = (-120);
            Emitter.RadialAccelVar = (0);

            // tagential
            Emitter.TangentialAccel = (30);
            Emitter.TangentialAccelVar = (0);

            // emitter position
            Emitter.Position = new CCPoint(160, 240);
            Emitter.PositionVar = new CCPoint(0, 0);

            // life of particles
            Emitter.Life = 3;
            Emitter.LifeVar = 1;

            // spin of particles
            Emitter.StartSpin = 0;
            Emitter.StartSpinVar = 0;
            Emitter.EndSpin = 0;
            Emitter.EndSpinVar = 2000;

            // color of particles
            var startColor = new CCColor4F(0.5f, 0.5f, 0.5f, 1.0f);
            Emitter.StartColor = startColor;

            var startColorVar = new CCColor4F(0.5f, 0.5f, 0.5f, 1.0f);
            Emitter.StartColorVar = startColorVar;

            var endColor = new CCColor4F(0.1f, 0.1f, 0.1f, 0.2f);
            Emitter.EndColor = endColor;

            var endColorVar = new CCColor4F(0.1f, 0.1f, 0.1f, 0.2f);
            Emitter.EndColorVar = endColorVar;

            // size, in pixels
            Emitter.StartSize = 30.0f;
            Emitter.StartSizeVar = 00.0f;
            Emitter.EndSize = CCParticleSystem.ParticleStartSizeEqualToEndSize;

            // emits per second
            Emitter.EmissionRate = Emitter.TotalParticles / Emitter.Life;

            // additive
            Emitter.BlendAdditive = false;

			SetEmitterPosition();

        }
Exemplo n.º 36
0
        public CCParticleSnow(CCPoint position, CCEmitterMode emitterMode=CCEmitterMode.Gravity) : base(700, emitterMode)
        {
            Duration = ParticleDurationInfinity;
            Life = 45;
            LifeVar = 15;
            Position = position;
            PositionVar = new CCPoint(position.X, 0);
            Angle = -90;
            AngleVar = 5;
            StartSize = 10.0f;
            StartSizeVar = 5.0f;
            EndSize = ParticleStartSizeEqualToEndSize;

            EmissionRate = 10;

            StartColor = new CCColor4F(1.0f, 1.0f, 1.0f, 1.0f);
            StartColorVar = new CCColor4F();
            EndColor = new CCColor4F(1.0f, 1.0f, 1.0f, 0.0f);
            EndColorVar = new CCColor4F();

            GravityMoveMode gravityMode = new GravityMoveMode();
            gravityMode.Gravity = new CCPoint(0, -1);
            gravityMode.RadialAccel = 0;
            gravityMode.RadialAccelVar = 1;
            gravityMode.TangentialAccel = 0;
            gravityMode.TangentialAccelVar = 1;
            gravityMode.Speed = 5;
            gravityMode.SpeedVar = 1;
            GravityMode = gravityMode;

            BlendAdditive = false;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 37
0
 public void DrawSegment(CCPoint from, CCPoint to, float radius, CCColor4F color, CCLineCap lineCap = CCLineCap.Round)
 {
     DrawLine(from, to, radius, (CCColor4B)color, lineCap);
 }
Exemplo n.º 38
0
        public CCParticleExplosion(CCPoint position, CCEmitterMode emitterMode=CCEmitterMode.Gravity) : base(700, emitterMode)
        {
            Duration = 0.1f;
            Life = 2.0f;
            LifeVar = 2;
            Position = new CCPoint(position);
            PositionVar = CCPoint.Zero;
            Angle = 90;
            AngleVar = 360;
            StartSize = 15.0f;
            StartSizeVar = 10.0f;
            EndSize = ParticleStartSizeEqualToEndSize;

            EmissionRate = TotalParticles / Duration;

            StartColor = new CCColor4F(0.7f, 0.1f, 0.2f, 1.0f);
            StartColorVar = new CCColor4F(0.5f, 0.5f, 0.5f, 0.0f);
            EndColor = new CCColor4F(0.5f, 0.5f, 0.5f, 0.0f);
            EndColorVar = new CCColor4F(0.5f, 0.5f, 0.5f, 0.0f);

            GravityMoveMode gravityMode = new GravityMoveMode();
            gravityMode.Gravity = new CCPoint(0, 0);
            gravityMode.RadialAccel = 0;
            gravityMode.RadialAccelVar = 0;
            gravityMode.Speed = 70;
            gravityMode.SpeedVar = 40;
            gravityMode.TangentialAccel = 0;
            gravityMode.TangentialAccelVar = 0;
            GravityMode = gravityMode;

            BlendAdditive = false;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 39
0
        public override void Setup()
        {
			CCClippingNode clipper = new CCClippingNode() { Tag = kTagClipperNode };
            clipper.ContentSize = new CCSize(200, 200);
            clipper.AnchorPoint = new CCPoint(0.5f, 0.5f);
            AddChild(clipper);

            CCDrawNode stencil = new CCDrawNode();
            CCPoint[] rectangle =
                {
                    new CCPoint(0, 0),
                    new CCPoint(clipper.ContentSize.Width, 0),
                    new CCPoint(clipper.ContentSize.Width, clipper.ContentSize.Height),
                    new CCPoint(0, clipper.ContentSize.Height),
                };

            CCColor4F white = new CCColor4F(0, 0, 0, 1);
            stencil.DrawPolygon(rectangle, 4, white, 0, white);
            clipper.Stencil = stencil;

            CCSprite content = new CCSprite(TestResource.s_back2);
            content.Tag = kTagContentNode;
            content.AnchorPoint = new CCPoint(0.5f, 0.5f);
            clipper.AddChild(content);

            content.RunAction(new CCRepeatForever(new CCRotateBy(1, 45)));

            m_bScrolling = false;

			// Register Touch Event
			var touchListener = new CCEventListenerTouchAllAtOnce();

			touchListener.OnTouchesBegan = onTouchesBegan;
			touchListener.OnTouchesMoved = onTouchesMoved;
			touchListener.OnTouchesEnded = onTouchesEnded;

            AddEventListener(touchListener);        
		}
Exemplo n.º 40
0
        public CCParticleMeteor(CCPoint position, CCEmitterMode emitterMode=CCEmitterMode.Gravity) : base(150, emitterMode)
        {
            Duration = ParticleDurationInfinity;
            Life = 2;
            LifeVar = 1;
            Position = position;
            PositionVar = CCPoint.Zero;
            Angle = 90;
            AngleVar = 360;
            StartSize = 60.0f;
            StartSizeVar = 10.0f;
            EndSize = ParticleStartSizeEqualToEndSize;

            EmissionRate = TotalParticles / Life;

            StartColor = new CCColor4F(0.2f, 0.4f, 0.7f, 1.0f);
            StartColorVar = new CCColor4F(0.0f, 0.0f, 0.2f, 0.1f);
            EndColor = new CCColor4F(0.0f, 0.0f, 0.0f, 1.0f);
            EndColorVar = new CCColor4F();

            GravityMoveMode gravityMode = new GravityMoveMode();
            gravityMode.Gravity = new CCPoint(-200, 200);
            gravityMode.RadialAccel = 0;
            gravityMode.RadialAccelVar = 0;
            gravityMode.Speed = 15;
            gravityMode.SpeedVar = 5;
            gravityMode.TangentialAccel = 0;
            gravityMode.TangentialAccelVar = 0;
            GravityMode = gravityMode;

            BlendAdditive = true;

            Texture = CCParticleExample.DefaultTexture;
        }
Exemplo n.º 41
0
        public void DrawSegment(CCPoint from, CCPoint to, float radius, CCColor4F color)
        {
			var cl = color.ToColor();

			var a = from;
			var b = to;

			var n = CCPoint.Normalize(CCPoint.PerpendicularCCW(a - b));

			var lww = radius;
			var nw = n * lww;
			var v0 = b - nw;
			var v1 = b + nw;
			var v2 = a - nw;
			var v3 = a + nw;

			// Triangles from beginning to end
            triangleVertices.Add(new VertexPositionColor(v1.ToVector3(), cl));
            triangleVertices.Add(new VertexPositionColor(v2.ToVector3(), cl));
            triangleVertices.Add(new VertexPositionColor(v0.ToVector3(), cl));

            triangleVertices.Add(new VertexPositionColor(v1.ToVector3(), cl));
            triangleVertices.Add(new VertexPositionColor(v2.ToVector3(), cl));
            triangleVertices.Add(new VertexPositionColor(v3.ToVector3(), cl));

            var mb = (float)Math.Atan2(v1.Y - b.Y, v1.X - b.X);
            var ma = (float)Math.Atan2(v2.Y - a.Y, v2.X - a.X);

            // Draw rounded line caps
            DrawSolidArc(a, radius, ma, MathHelper.Pi, color);
            DrawSolidArc(b, radius, mb, MathHelper.Pi, color);

            dirty = true;
        }
Exemplo n.º 42
0
        public CCParticleFire(CCPoint position, CCEmitterMode emitterMode = CCEmitterMode.Gravity) : base(250, emitterMode)
        {
            if (config == null)
            {
                config = new CCParticleSystemConfig();
                config.ParticleSystemType = CCParticleSystemType.Internal;

                config.Duration     = ParticleDurationInfinity;
                config.Life         = 3;
                config.LifeVar      = 0.25f;
                config.Position     = position;
                config.PositionVar  = new CCPoint(40, 20);
                config.Angle        = 90;
                config.AngleVar     = 10;
                config.StartSize    = 54.0f;
                config.StartSizeVar = 10.0f;
                config.EndSize      = ParticleStartSizeEqualToEndSize;

                config.EmitterMode = CCEmitterMode.Gravity;

                CCColor4F cstartColor = new CCColor4F();
                cstartColor.R     = 0.76f;
                cstartColor.G     = 0.25f;
                cstartColor.B     = 0.12f;
                cstartColor.A     = 1.0f;
                config.StartColor = cstartColor;

                CCColor4F cstartColorVar = new CCColor4F();
                cstartColorVar.R     = 0.0f;
                cstartColorVar.G     = 0.0f;
                cstartColorVar.B     = 0.0f;
                cstartColorVar.A     = 0.0f;
                config.StartColorVar = cstartColorVar;

                CCColor4F cendColor = new CCColor4F();
                cendColor.R     = 0.0f;
                cendColor.G     = 0.0f;
                cendColor.B     = 0.0f;
                cendColor.A     = 1.0f;
                config.EndColor = cendColor;

                CCColor4F cendColorVar = new CCColor4F();
                cendColorVar.R     = 0.0f;
                cendColorVar.G     = 0.0f;
                cendColorVar.B     = 0.0f;
                cendColorVar.A     = 0.0f;
                config.EndColorVar = cendColorVar;

                config.Gravity               = new CCPoint(0, 0);
                config.GravityRadialAccel    = 0;
                config.GravityRadialAccelVar = 0;
                config.GravitySpeed          = 60;
                config.GravitySpeedVar       = 20;

                config.Texture = CCParticleExample.DefaultTexture;
            }

            Duration     = config.Duration;
            Life         = config.Life;
            LifeVar      = config.LifeVar;
            Position     = config.Position;
            PositionVar  = config.PositionVar;
            Angle        = config.Angle;
            AngleVar     = config.AngleVar;
            StartSize    = config.StartSize;
            StartSizeVar = config.StartSizeVar;
            EndSize      = config.EndSize;

            EmissionRate = TotalParticles / Life;

            CCColor4F startColor = new CCColor4F();

            startColor.R = config.StartColor.R;
            startColor.G = config.StartColor.G;
            startColor.B = config.StartColor.B;
            startColor.A = config.StartColor.A;
            StartColor   = startColor;

            CCColor4F startColorVar = new CCColor4F();

            startColorVar.R = config.StartColorVar.R;
            startColorVar.G = config.StartColorVar.G;
            startColorVar.B = config.StartColorVar.B;
            startColorVar.A = config.StartColorVar.A;
            StartColorVar   = startColorVar;

            CCColor4F endColor = new CCColor4F();

            endColor.R = config.EndColor.R;
            endColor.G = config.EndColor.G;
            endColor.B = config.EndColor.B;
            endColor.A = config.EndColor.A;
            EndColor   = endColor;

            CCColor4F endColorVar = new CCColor4F();

            endColorVar.R = config.EndColorVar.R;
            endColorVar.G = config.EndColorVar.G;
            endColorVar.B = config.EndColorVar.B;
            endColorVar.A = config.EndColorVar.A;
            EndColorVar   = endColorVar;

            GravityMoveMode gravityMode = new GravityMoveMode();

            gravityMode.Gravity        = new CCPoint(config.Gravity);
            gravityMode.RadialAccel    = config.GravityRadialAccel;
            gravityMode.RadialAccelVar = config.GravityRadialAccelVar;
            gravityMode.Speed          = config.GravitySpeed;
            gravityMode.SpeedVar       = config.GravitySpeedVar;
            GravityMode = gravityMode;

            BlendAdditive = true;

            Texture = config.Texture;
        }
Exemplo n.º 43
0
        public void DrawCircle(CCPoint center, float radius, float angle, int segments, CCColor4B color)
        {
            float increment = MathHelper.Pi * 2.0f / segments;
            double theta = 0.0;

            CCPoint v1;
            CCPoint v2 = CCPoint.Zero;
            List<CCPoint> verts = new List<CCPoint>();

            for (int i = 0; i < segments; i++)
            {
                v1 = center + new CCPoint((float)Math.Cos(theta), (float)Math.Sin(theta)) * radius;
                v2 = center + new CCPoint((float)Math.Cos(theta + increment), (float)Math.Sin(theta + increment)) * radius;
                verts.Add(v1);
                theta += increment;
            }

            CCColor4F cf = new CCColor4F(color.R/255f, color.G/255f, color.B/255f, color.A/255f);
            DrawPolygon(verts.ToArray(), verts.Count, cf, 0, new CCColor4F(0f, 0f, 0f, 0f));
        }
Exemplo n.º 44
0
        public void DrawPolygon(CCPoint[] verts, int count, CCColor4F fillColor, float borderWidth,
                                CCColor4F borderColor, bool closePolygon = true)
        {
            var polycount = count;

            var colorFill  = new CCColor4B(fillColor);
            var borderFill = new CCColor4B(borderColor);

            bool outline = (borderColor.A > 0.0f && borderWidth > 0.0f);
            bool fill    = fillColor.A > 0.0f;

            var numberOfTriangles = outline ? (3 * polycount - 2) : (polycount - 2);

            if (numberOfTriangles > 0 && fill && closePolygon)
            {
                for (int i = 1; i < polycount - 1; i++)
                {
                    AddTriangleVertex(new CCV3F_C4B(verts[0], colorFill));
                    AddTriangleVertex(new CCV3F_C4B(verts[i], colorFill));
                    AddTriangleVertex(new CCV3F_C4B(verts[i + 1], colorFill));
                }
            }
            else
            {
                for (int i = 0; i < polycount - 1; i++)
                {
                    DrawLine(verts[i], verts[i + 1], borderWidth, colorFill);
                }
            }

            if (outline)
            {
                var extrude = new ExtrudeVerts[polycount];

                for (int i = 0; i < polycount; i++)
                {
                    var v0 = verts[(i - 1 + polycount) % polycount];
                    var v1 = verts[i];
                    var v2 = verts[(i + 1) % polycount];

                    var n1 = CCPoint.Normalize(CCPoint.PerpendicularCCW(v1 - v0));
                    var n2 = CCPoint.Normalize(CCPoint.PerpendicularCCW(v2 - v1));

                    var offset = (n1 + n2) * (1.0f / (CCPoint.Dot(n1, n2) + 1.0f));
                    extrude[i] = new ExtrudeVerts()
                    {
                        offset = offset, n = n2
                    };
                }

                float inset = (!outline ? 0.5f : 0.0f);

                for (int i = 0; i < polycount - 2; i++)
                {
                    var v0 = verts[0] - (extrude[0].offset * inset);
                    var v1 = verts[i + 1] - (extrude[i + 1].offset * inset);
                    var v2 = verts[i + 2] - (extrude[i + 2].offset * inset);

                    AddTriangleVertex(new CCV3F_C4B(v0, colorFill)); //__t(v2fzero)
                    AddTriangleVertex(new CCV3F_C4B(v1, colorFill)); //__t(v2fzero)
                    AddTriangleVertex(new CCV3F_C4B(v2, colorFill)); //__t(v2fzero)
                }

                for (int i = 0; i < polycount - 1; i++)
                {
                    int j  = (i + 1) % polycount;
                    var v0 = verts[i];
                    var v1 = verts[j];

                    var offset0 = extrude[i].offset;
                    var offset1 = extrude[j].offset;

                    var inner0 = (v0 - (offset0 * borderWidth));
                    var inner1 = (v1 - (offset1 * borderWidth));
                    var outer0 = (v0 + (offset0 * borderWidth));
                    var outer1 = (v1 + (offset1 * borderWidth));

                    AddTriangleVertex(new CCV3F_C4B(inner0, borderFill));
                    AddTriangleVertex(new CCV3F_C4B(inner1, borderFill));
                    AddTriangleVertex(new CCV3F_C4B(outer1, borderFill));

                    AddTriangleVertex(new CCV3F_C4B(inner0, borderFill));
                    AddTriangleVertex(new CCV3F_C4B(outer0, borderFill));
                    AddTriangleVertex(new CCV3F_C4B(outer1, borderFill));
                }

                if (closePolygon)
                {
                    for (int i = polycount - 1; i < polycount; i++)
                    {
                        int j  = (i + 1) % polycount;
                        var v0 = verts[i];
                        var v1 = verts[j];

                        var offset0 = extrude[i].offset;
                        var offset1 = extrude[j].offset;

                        var inner0 = (v0 - (offset0 * borderWidth));
                        var inner1 = (v1 - (offset1 * borderWidth));
                        var outer0 = (v0 + (offset0 * borderWidth));
                        var outer1 = (v1 + (offset1 * borderWidth));

                        AddTriangleVertex(new CCV3F_C4B(inner0, borderFill));
                        AddTriangleVertex(new CCV3F_C4B(inner1, borderFill));
                        AddTriangleVertex(new CCV3F_C4B(outer1, borderFill));

                        AddTriangleVertex(new CCV3F_C4B(inner0, borderFill));
                        AddTriangleVertex(new CCV3F_C4B(outer0, borderFill));
                        AddTriangleVertex(new CCV3F_C4B(outer1, borderFill));
                    }
                }
            }

            dirty = true;
        }
Exemplo n.º 45
0
 public void DrawRect(CCRect rect, CCColor4B color)
 {
     float x1 = rect.MinX;
     float y1 = rect.MinY;
     float x2 = rect.MaxX;
     float y2 = rect.MaxY;
     CCPoint[] pt = new CCPoint[] { 
         new CCPoint(x1,y1), new CCPoint(x2,y1), new CCPoint(x2,y2), new CCPoint(x1,y2)
     };
     CCColor4F cf = new CCColor4F(color.R/255f, color.G/255f, color.B/255f, color.A/255f);
     DrawPolygon(pt, 4, cf, 0, new CCColor4F(0f, 0f, 0f, 0f));
 }
        CCParticleSystemConfig(PlistDictionary dictionary, string directoryName, bool loadingAsync)
        {
            ParticleSystemType = CCParticleSystemType.Cocos2D;

            MaxParticles = dictionary ["maxParticles"].AsInt;
            Duration     = dictionary["duration"].AsFloat;
            Life         = dictionary["particleLifespan"].AsFloat;
            LifeVar      = dictionary["particleLifespanVariance"].AsFloat;

            Angle    = dictionary["angle"].AsFloat;
            AngleVar = dictionary["angleVariance"].AsFloat;

            CCBlendFunc blendFunc = new CCBlendFunc();

            blendFunc.Source      = dictionary["blendFuncSource"].AsInt;
            blendFunc.Destination = dictionary["blendFuncDestination"].AsInt;
            BlendFunc             = blendFunc;

            CCColor4F startColor = new CCColor4F();

            startColor.R = dictionary["startColorRed"].AsFloat;
            startColor.G = dictionary["startColorGreen"].AsFloat;
            startColor.B = dictionary["startColorBlue"].AsFloat;
            startColor.A = dictionary["startColorAlpha"].AsFloat;
            StartColor   = startColor;

            CCColor4F startColorVar = new CCColor4F();

            startColorVar.R = dictionary["startColorVarianceRed"].AsFloat;
            startColorVar.G = dictionary["startColorVarianceGreen"].AsFloat;
            startColorVar.B = dictionary["startColorVarianceBlue"].AsFloat;
            startColorVar.A = dictionary["startColorVarianceAlpha"].AsFloat;
            StartColorVar   = startColorVar;

            CCColor4F endColor = new CCColor4F();

            endColor.R = dictionary["finishColorRed"].AsFloat;
            endColor.G = dictionary["finishColorGreen"].AsFloat;
            endColor.B = dictionary["finishColorBlue"].AsFloat;
            endColor.A = dictionary["finishColorAlpha"].AsFloat;
            EndColor   = endColor;

            CCColor4F endColorVar = new CCColor4F();

            endColorVar.R = dictionary["finishColorVarianceRed"].AsFloat;
            endColorVar.G = dictionary["finishColorVarianceGreen"].AsFloat;
            endColorVar.B = dictionary["finishColorVarianceBlue"].AsFloat;
            endColorVar.A = dictionary["finishColorVarianceAlpha"].AsFloat;
            EndColorVar   = endColorVar;

            StartSize    = dictionary["startParticleSize"].AsFloat;
            StartSizeVar = dictionary["startParticleSizeVariance"].AsFloat;
            EndSize      = dictionary["finishParticleSize"].AsFloat;
            EndSizeVar   = dictionary["finishParticleSizeVariance"].AsFloat;

            CCPoint position;

            position.X = dictionary["sourcePositionx"].AsFloat;
            position.Y = dictionary["sourcePositiony"].AsFloat;
            Position   = position;

            CCPoint positionVar;

            positionVar.X = dictionary["sourcePositionVariancex"].AsFloat;
            positionVar.Y = dictionary["sourcePositionVariancey"].AsFloat;
            PositionVar   = positionVar;

            StartSpin    = dictionary["rotationStart"].AsFloat;
            StartSpinVar = dictionary["rotationStartVariance"].AsFloat;
            EndSpin      = dictionary["rotationEnd"].AsFloat;
            EndSpinVar   = dictionary["rotationEndVariance"].AsFloat;

            EmitterMode = (CCEmitterMode)dictionary["emitterType"].AsInt;

            if (EmitterMode == CCEmitterMode.Gravity)
            {
                CCPoint gravity;
                gravity.X = dictionary["gravityx"].AsFloat;
                gravity.Y = dictionary["gravityy"].AsFloat;
                Gravity   = gravity;

                GravitySpeed              = dictionary["speed"].AsFloat;
                GravitySpeedVar           = dictionary["speedVariance"].AsFloat;
                GravityRadialAccel        = dictionary["radialAcceleration"].AsFloat;
                GravityRadialAccelVar     = dictionary["radialAccelVariance"].AsFloat;
                GravityTangentialAccel    = dictionary["tangentialAcceleration"].AsFloat;
                GravityTangentialAccelVar = dictionary["tangentialAccelVariance"].AsFloat;
                GravityRotationIsDir      = dictionary["rotationIsDir"].AsBool;
            }

            else if (EmitterMode == CCEmitterMode.Radius)
            {
                RadialStartRadius        = dictionary["maxRadius"].AsFloat;
                RadialStartRadiusVar     = dictionary["maxRadiusVariance"].AsFloat;
                RadialEndRadius          = dictionary["minRadius"].AsFloat;
                RadialEndRadiusVar       = 0.0f;
                RadialRotatePerSecond    = dictionary["rotatePerSecond"].AsFloat;
                RadialRotatePerSecondVar = dictionary["rotatePerSecondVariance"].AsFloat;
            }
            else
            {
                Debug.Assert(false, "Invalid emitterType in config file");
                return;
            }

            TextureName = dictionary["textureFileName"].AsString;
            TextureData = dictionary["textureImageData"].AsString;

            if (!loadingAsync)
            {
                LoadParticleTexture();
            }
        }
Exemplo n.º 47
0
        public CCParticleSystem(CCParticleSystemConfig particleConfig) : this(particleConfig.MaxParticles, false)
        {
            Duration = particleConfig.Duration;;
            Life = particleConfig.Life;
            LifeVar = particleConfig.LifeVar;
            EmissionRate = TotalParticles / Life;

            Angle = particleConfig.Angle;
            AngleVar = particleConfig.AngleVar;

            CCColor4F startColor = new CCColor4F();
            startColor.R = particleConfig.StartColor.R;
            startColor.G = particleConfig.StartColor.G;
            startColor.B = particleConfig.StartColor.B;
            startColor.A = particleConfig.StartColor.A;
            StartColor = startColor;

            CCColor4F startColorVar = new CCColor4F();
            startColorVar.R = particleConfig.StartColorVar.R;
            startColorVar.G = particleConfig.StartColorVar.G;
            startColorVar.B = particleConfig.StartColorVar.B;
            startColorVar.A = particleConfig.StartColorVar.A;
            StartColorVar = startColorVar;

            CCColor4F endColor = new CCColor4F();
            endColor.R = particleConfig.EndColor.R;
            endColor.G = particleConfig.EndColor.G;
            endColor.B = particleConfig.EndColor.B;
            endColor.A = particleConfig.EndColor.A;
            EndColor = endColor;

            CCColor4F endColorVar = new CCColor4F();
            endColorVar.R = particleConfig.EndColorVar.R;
            endColorVar.G = particleConfig.EndColorVar.G;
            endColorVar.B = particleConfig.EndColorVar.B;
            endColorVar.A = particleConfig.EndColorVar.A;
            EndColorVar = endColorVar;

            StartSize = particleConfig.StartSize;
            StartSizeVar = particleConfig.StartSizeVar;
            EndSize = particleConfig.EndSize;
            EndSizeVar = particleConfig.EndSizeVar;

            CCPoint position;
            position.X = particleConfig.Position.X;
            position.Y = particleConfig.Position.Y;
            Position = position;

            CCPoint positionVar;
            positionVar.X = particleConfig.PositionVar.X;
            positionVar.Y = particleConfig.PositionVar.X;
            PositionVar = positionVar;

            StartSpin = particleConfig.StartSpin;
            StartSpinVar = particleConfig.StartSpinVar;
            EndSpin = particleConfig.EndSpin;
            EndSpinVar = particleConfig.EndSpinVar;

            EmitterMode = particleConfig.EmitterMode;

            if (EmitterMode == CCEmitterMode.Gravity)
            {
                GravityParticles = new CCParticleGravity[TotalParticles];

                GravityMoveMode newGravityMode = new GravityMoveMode();

                CCPoint gravity;
                gravity.X = particleConfig.Gravity.X;
                gravity.Y = particleConfig.Gravity.Y;
                newGravityMode.Gravity = gravity;

                newGravityMode.Speed = particleConfig.GravitySpeed;
                newGravityMode.SpeedVar = particleConfig.GravitySpeedVar;
                newGravityMode.RadialAccel = particleConfig.GravityRadialAccel;
                newGravityMode.RadialAccelVar = particleConfig.GravityRadialAccelVar;
                newGravityMode.TangentialAccel = particleConfig.GravityTangentialAccel;
                newGravityMode.TangentialAccelVar = particleConfig.GravityTangentialAccelVar;
                newGravityMode.RotationIsDir = particleConfig.GravityRotationIsDir;

                GravityMode = newGravityMode;
            }
            else if (EmitterMode == CCEmitterMode.Radius)
            {
                RadialParticles = new CCParticleRadial[TotalParticles];

                RadialMoveMode newRadialMode = new RadialMoveMode();

                newRadialMode.StartRadius = particleConfig.RadialStartRadius;
                newRadialMode.StartRadiusVar = particleConfig.RadialStartRadiusVar;
                newRadialMode.EndRadius = particleConfig.RadialEndRadius;
                newRadialMode.EndRadiusVar = particleConfig.RadialEndRadiusVar;
                newRadialMode.RotatePerSecond = particleConfig.RadialRotatePerSecond;
                newRadialMode.RotatePerSecondVar = particleConfig.RadialRotatePerSecondVar;

                RadialMode = newRadialMode;
            }
            else
            {
                Debug.Assert(false, "Invalid emitterType in config file");
                return;
            }
        }
Exemplo n.º 48
0
 public bool Equals(CCColor4F other)        
 {            
     return this == other;       
 } 
Exemplo n.º 49
0
        public void DrawSegment(CCPoint from, CCPoint to, float radius, CCColor4F color)
        {
			var cl = color;

			var a = from;
			var b = to;

			var n = CCPoint.Normalize(CCPoint.PerpendicularCCW(a - b));

			var lww = radius;
			var nw = n * lww;
			var v0 = b - nw;
			var v1 = b + nw;
			var v2 = a - nw;
			var v3 = a + nw;

			// Triangles from beginning to end
            AddTriangleVertex(new CCV3F_C4B(v1, cl));
            AddTriangleVertex(new CCV3F_C4B(v2, cl));
            AddTriangleVertex(new CCV3F_C4B(v0, cl));

            AddTriangleVertex(new CCV3F_C4B(v1, cl));
            AddTriangleVertex(new CCV3F_C4B(v2, cl));
            AddTriangleVertex(new CCV3F_C4B(v3, cl));

            var mb = (float)Math.Atan2(v1.Y - b.Y, v1.X - b.X);
            var ma = (float)Math.Atan2(v2.Y - a.Y, v2.X - a.X);

            // Draw rounded line caps
            DrawSolidArc(a, radius, ma, MathHelper.Pi, color);
            DrawSolidArc(b, radius, mb, MathHelper.Pi, color);

            dirty = true;
        }
Exemplo n.º 50
0
        public override void OnEnter()
        {
            base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;

            Color = new CCColor3B(0, 0, 0);
            RemoveChild(Background, true);
            Background = null;

            Emitter = new CCParticleSystemQuad(100, CCEmitterMode.Radius);
            AddChild(Emitter, 10);
            Emitter.Texture = CCTextureCache.SharedTextureCache.AddImage("Images/fire");

            // duration
            Emitter.Duration = CCParticleSystem.ParticleDurationInfinity; 

            // radius mode: start and end radius in pixels
            Emitter.StartRadius = (50);
            Emitter.StartRadiusVar = (0);
            Emitter.EndRadius = (CCParticleSystem.ParticleStartRadiusEqualToEndRadius);
            Emitter.EndRadiusVar = (0);

            // radius mode: degrees per second
            Emitter.RotatePerSecond = (0);
            Emitter.RotatePerSecondVar = (0);


            // angle
            Emitter.Angle = 90;
            Emitter.AngleVar = 0;

            // emitter position
            CCSize size = WindowSize;
            Emitter.Position = new CCPoint(size.Width / 2, size.Height / 2);
            Emitter.PositionVar = new CCPoint(0, 0);

            // life of particles
            Emitter.Life = 5;
            Emitter.LifeVar = 0;

            // spin of particles
            Emitter.StartSpin = 0;
            Emitter.StartSpinVar = 0;
            Emitter.EndSpin = 0;
            Emitter.EndSpinVar = 0;

            // color of particles
            var startColor = new CCColor4F(0.5f, 0.5f, 0.5f, 1.0f);
            Emitter.StartColor = startColor;

            var startColorVar = new CCColor4F(0.5f, 0.5f, 0.5f, 1.0f);
            Emitter.StartColorVar = startColorVar;

            var endColor = new CCColor4F(0.1f, 0.1f, 0.1f, 0.2f);
            Emitter.EndColor = endColor;

            var endColorVar = new CCColor4F(0.1f, 0.1f, 0.1f, 0.2f);
            Emitter.EndColorVar = endColorVar;

            // size, in pixels
            Emitter.StartSize = 16;
            Emitter.StartSizeVar = 0;
            Emitter.EndSize = CCParticleSystem.ParticleStartSizeEqualToEndSize;

            // emits per second
            Emitter.EmissionRate = Emitter.TotalParticles / Emitter.Life;

            // additive
            Emitter.BlendAdditive = false;

            CCRotateBy rot = new CCRotateBy (16, 360);
            Emitter.RunAction(new CCRepeatForever (rot));
        }
Exemplo n.º 51
0
 public void DrawRect(CCRect rect, CCColor4B fillColor, float borderWidth,
     CCColor4B borderColor)
 {
     float x1 = rect.MinX;
     float y1 = rect.MinY;
     float x2 = rect.MaxX;
     float y2 = rect.MaxY;
     CCPoint[] pt = new CCPoint[] { 
         new CCPoint(x1,y1), new CCPoint(x2,y1), new CCPoint(x2,y2), new CCPoint(x1,y2)
     };
     CCColor4F cf = new CCColor4F(fillColor.R/255f, fillColor.G/255f, fillColor.B/255f, fillColor.A/255f);
     CCColor4F bc = new CCColor4F(borderColor.R/255f, borderColor.G/255f, borderColor.B/255f, borderColor.A/255f);
     DrawPolygon(pt, 4, cf, borderWidth, bc);
 }
Exemplo n.º 52
0
        public override void OnEnter()
        {
base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;

            Color = CCColor3B.Black;
            RemoveChild(Background, true);
            Background = null;

            batchNode = new CCParticleBatchNode("Images/stars-grayscale", 3000);

            AddChild(batchNode, 1, 2);


            for (int i = 0; i < 3; i++)
            {
                var particleSystem = new CCParticleSystemQuad(200, CCEmitterMode.Radius);
                particleSystem.Texture = (batchNode.Texture);

                // duration
                particleSystem.Duration = CCParticleSystem.ParticleDurationInfinity;

                // radius mode: 100 pixels from center
                particleSystem.StartRadius = (100);
                particleSystem.StartRadiusVar = (0);
                particleSystem.EndRadius = (CCParticleSystem.ParticleStartRadiusEqualToEndRadius);
                particleSystem.EndRadiusVar = (0); // not used when start == end

                // radius mode: degrees per second
                // 45 * 4 seconds of life = 180 degrees
                particleSystem.RotatePerSecond = (45);
                particleSystem.RotatePerSecondVar = (0);


                // angle
                particleSystem.Angle = (90);
                particleSystem.AngleVar = (0);

                // emitter position
                particleSystem.PositionVar = (CCPoint.Zero);

                // life of particles
                particleSystem.Life = (4);
                particleSystem.LifeVar = (0);

                // spin of particles
                particleSystem.StartSpin = (0);
                particleSystem.StartSpinVar = (0);
                particleSystem.EndSpin = (0);
                particleSystem.EndSpinVar = (0);

                // color of particles
                var color = new float[3] {0, 0, 0};
                color[i] = 1;
                var startColor = new CCColor4F(color[0], color[1], color[2], 1.0f);
                particleSystem.StartColor = (startColor);

                var startColorVar = new CCColor4F(0, 0, 0, 0);
                particleSystem.StartColorVar = (startColorVar);

                CCColor4F endColor = startColor;
                particleSystem.EndColor = (endColor);

                CCColor4F endColorVar = startColorVar;
                particleSystem.EndColorVar = (endColorVar);

                // size, in pixels
                particleSystem.StartSize = (32);
                particleSystem.StartSizeVar = (0);
                particleSystem.EndSize = CCParticleSystem.ParticleStartSizeEqualToEndSize;

                // emits per second
                particleSystem.EmissionRate = (particleSystem.TotalParticles / particleSystem.Life);

                // additive

                particleSystem.Position = (new CCPoint(i * 10 + 120, 200));


                batchNode.AddChild(particleSystem);
                particleSystem.PositionType = CCPositionType.Free;
            }

            Schedule(ReorderSystem, 2.0f);
            Emitter = null;
        }
Exemplo n.º 53
0
 public bool Equals(CCColor4F other)
 {
     return(this == other);
 }
Exemplo n.º 54
0
        public override void OnEnter()
        {
            base.OnEnter(); 
            CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;

            Emitter = new CCParticleSystemQuad(1000);

            Background.AddChild(Emitter, 10);

            CCSize s = windowSize;

            // duration
            Emitter.Duration = -1;

            // gravity
            Emitter.Gravity = (new CCPoint(0, 0));

            // angle
            Emitter.Angle = 0;
            Emitter.AngleVar = 360;

            // radial
            Emitter.RadialAccel = (70);
            Emitter.RadialAccelVar = (10);

            // tagential
            Emitter.TangentialAccel = (80);
            Emitter.TangentialAccelVar = (0);

            // speed of particles
            Emitter.Speed = (50);
            Emitter.SpeedVar = (10);

            // emitter position
            Emitter.Position = new CCPoint(s.Width / 2, s.Height / 2);
            Emitter.PositionVar = new CCPoint(0, 0);

            // life of particles
            Emitter.Life = 2.0f;
            Emitter.LifeVar = 0.3f;

            // emits per frame
            Emitter.EmissionRate = Emitter.TotalParticles / Emitter.Life;

            // color of particles
            var startColor = new CCColor4F(0.5f, 0.5f, 0.5f, 1.0f);
            Emitter.StartColor = startColor;

            var startColorVar = new CCColor4F(0.5f, 0.5f, 0.5f, 1.0f);
            Emitter.StartColorVar = startColorVar;

            var endColor = new CCColor4F(0.1f, 0.1f, 0.1f, 0.2f);
            Emitter.EndColor = endColor;

            var endColorVar = new CCColor4F(0.1f, 0.1f, 0.1f, 0.2f);
            Emitter.EndColorVar = endColorVar;

            // size, in pixels
            Emitter.StartSize = 1.0f;
            Emitter.StartSizeVar = 1.0f;
            Emitter.EndSize = 32.0f;
            Emitter.EndSizeVar = 8.0f;

            // texture
            Emitter.Texture = CCTextureCache.SharedTextureCache.AddImage(TestResource.s_fire);

            // additive
            Emitter.BlendAdditive = false;

			SetEmitterPosition();

        }
Exemplo n.º 55
0
 public CCV2F_C4F_T2F()
 {
     Vertices  = new CCVertex2F();
     Colors    = new CCColor4F();
     TexCoords = new CCTex2F();
 }