protected override CCDrawNode Draw()
        {
            var node = new CCDrawNode();

            var color = GameColors.WallsColor4B;

            var basisX  = this.Position == WallPosition.Left ? 0 : 6;
            var vertexX = this.Position == WallPosition.Left ? 6 : 0;

            var numberOfTriangles = this.Height / 12;
            var triangles         = new List <CCV3F_C4B>();

            for (int i = 0; i < numberOfTriangles; i++)
            {
                var y = i * 12;

                triangles.AddRange(new [] {
                    new CCV3F_C4B(new CCPoint(basisX, y), color),
                    new CCV3F_C4B(new CCPoint(vertexX, y + 12 / 2), color),
                    new CCV3F_C4B(new CCPoint(basisX, y + 12), color),
                });
            }

            node.DrawTriangleList(triangles.ToArray());
            node.PositionX = this.Position == WallPosition.Left ? 20 : ScreenRight - 26;

            return(node);
        }
Пример #2
0
        /*
         *  TL    TR
         *   0----1 0,1,2,3 = index offsets for vertex indices
         *   |   /|
         *   |  / |
         *   | /  |
         *   |/   |
         *   2----3
         *  BL    BR
         */
        void GenerateStripes(CCSize textureSizeInPixels, CCColor4B c2, int numberOfStripes)
        {
            var gradientNode = new CCDrawNode();

            // Layer 1: Stripes
            CCV3F_C4B[] vertices = new CCV3F_C4B[numberOfStripes * 6];

            var textureWidth  = textureSizeInPixels.Width;
            var textureHeight = textureSizeInPixels.Height;

            int   nVertices = 0;
            float x1        = -textureHeight;
            float x2;
            float y1          = textureHeight;
            float y2          = 0;
            float dx          = textureWidth / numberOfStripes * 2;
            float stripeWidth = dx / 2;

            for (int i = 0; i < numberOfStripes; i++)
            {
                x2 = x1 + textureHeight;

                // Left triangle TL - 0
                vertices[nVertices].Vertices = new CCVertex3F(x1, y1, 0);
                vertices[nVertices++].Colors = c2;

                // Left triangle BL - 2
                vertices[nVertices].Vertices = new CCVertex3F(x1 + stripeWidth, y1, 0);
                vertices[nVertices++].Colors = c2;

                // Left triangle TR - 1
                vertices[nVertices].Vertices = new CCVertex3F(x2, y2, 0);
                vertices[nVertices++].Colors = c2;

                // Right triangle BL - 2
                vertices[nVertices].Vertices = vertices[nVertices - 2].Vertices;
                vertices[nVertices++].Colors = c2;

                // Right triangle BR - 3
                vertices[nVertices].Vertices = vertices[nVertices - 2].Vertices;
                vertices[nVertices++].Colors = c2;

                // Right triangle TR - 1
                vertices[nVertices].Vertices = new CCVertex3F(x2 + stripeWidth, y2, 0);
                vertices[nVertices++].Colors = c2;

                x1 += dx;
            }

            gradientNode.DrawTriangleList(vertices);

            gradientNode.Visit();
        }
Пример #3
0
        void TriangleList()
        {
            CCV3F_C4B[] verts = new CCV3F_C4B[] {
                // First triangle:
                new CCV3F_C4B(new CCPoint(0, 0), CCColor4B.White),
                new CCV3F_C4B(new CCPoint(30, 60), CCColor4B.White),
                new CCV3F_C4B(new CCPoint(60, 0), CCColor4B.White),
                // second triangle, each point has different colors:
                new CCV3F_C4B(new CCPoint(90, 0), CCColor4B.Yellow),
                new CCV3F_C4B(new CCPoint(120, 60), CCColor4B.Red),
                new CCV3F_C4B(new CCPoint(150, 0), CCColor4B.Blue)
            };

            drawNode.DrawTriangleList(verts);
        }
Пример #4
0
        public override void OnEnter()
        {
            base.OnEnter();

            CreateGeometry();

            var draw = new CCDrawNode();

            draw.BlendFunc = CCBlendFunc.NonPremultiplied;

            AddChild(draw, 10);

            draw.DrawTriangleList(drawBuffer.TriangleVertices.ToArray());
            draw.DrawLineList(drawBuffer.LineVertices.ToArray());
        }
Пример #5
0
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;


            var line = new CCDrawNode();

            line.DrawLine(new CCPoint(0, windowSize.Height / 2), new CCPoint(windowSize.Width, windowSize.Height / 2), 10);
            AddChild(line, 0);

            byte alpha = 100; // 255 is full opacity

            var green = new CCColor4B(0, 255, 0, alpha);

            CCV3F_C4B[] verts = new CCV3F_C4B[] {
                new CCV3F_C4B(new CCPoint(0, 0), green),
                new CCV3F_C4B(new CCPoint(30, 60), green),
                new CCV3F_C4B(new CCPoint(60, 0), green)
            };

            triangleList1.DrawTriangleList(verts);

            triangleList1.Position   = windowSize.Center;
            triangleList1.PositionX -= windowSize.Width / 4;
            triangleList1.PositionY -= triangleList1.ContentSize.Center.Y;

            // Because the default BlendFunc of our DrawNode is AlphaBlend we need
            // to pass the colors as pre multiplied alpha.
            var greenPreMultiplied = green;

            greenPreMultiplied.G = (byte)(greenPreMultiplied.G * alpha / 255.0f);

            verts[0].Colors = greenPreMultiplied;
            verts[1].Colors = greenPreMultiplied;
            verts[2].Colors = greenPreMultiplied;

            triangleList2.DrawTriangleList(verts);

            triangleList2.Position   = windowSize.Center;
            triangleList2.PositionX += windowSize.Width / 4;
            triangleList2.PositionY -= triangleList2.BoundingRect.Size.Height / 2;
        }
Пример #6
0
        /*
         *  TL    TR
         *   0----1 0,1,2,3 = index offsets for vertex indices
         *   |   /|
         *   |  / |
         *   | /  |
         *   |/   |
         *   2----3
         *  BL    BR
         */
        void GenerateGradient(CCSize textureSizeInPixels)
        {
            var gradientNode = new CCDrawNode();

            var gradientAlpha = new CCColor4B(0, 0, 0, (byte)(0.7f * 255f));

            CCV3F_C4B[] vertices = new CCV3F_C4B[6];

            // Left triangle TL - 0
            vertices[0].Vertices = new CCVertex3F(0, textureSizeInPixels.Height, 0);
            vertices[0].Colors   = CCColor4B.Transparent;

            // Left triangle BL - 2
            vertices[1].Vertices = new CCVertex3F(0, 0, 0);
            vertices[1].Colors   = gradientAlpha;

            // Left triangle TR - 1
            vertices[2].Vertices = new CCVertex3F(textureSizeInPixels.Width, textureSizeInPixels.Height, 0);
            vertices[2].Colors   = CCColor4B.Transparent;

            // Right triangle BL - 2
            vertices[3].Vertices = new CCVertex3F(0, 0, 0);
            vertices[3].Colors   = gradientAlpha;

            // Right triangle BR - 3
            vertices[4].Vertices = new CCVertex3F(textureSizeInPixels.Width, 0, 0);
            vertices[4].Colors   = gradientAlpha;

            // Right triangle TR - 1
            vertices[5].Vertices = new CCVertex3F(textureSizeInPixels.Width, textureSizeInPixels.Height, 0);
            vertices[5].Colors   = CCColor4B.Transparent;

            gradientNode.DrawTriangleList(vertices);

            gradientNode.Visit();
        }
Пример #7
0
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize     windowSize = Layer.VisibleBoundsWorldspace.Size;
            CCDrawNode draw       = new CCDrawNode();

            AddChild(draw, 10);

            var s = windowSize;

            // Draw 10 circles
            for (int i = 0; i < 10; i++)
            {
                draw.DrawDot(s.Center, 10 * (10 - i),
                             new CCColor4F(CCRandom.Float_0_1(), CCRandom.Float_0_1(), CCRandom.Float_0_1(), 1));
            }

            // Draw polygons
            CCV3F_C4B[] points = new CCV3F_C4B[3];

            points[0].Colors   = CCColor4B.Red;
            points[0].Colors.A = 127;

            points[1].Colors   = CCColor4B.Green;
            points[1].Colors.A = 127;

            points[2].Colors   = CCColor4B.Blue;
            points[2].Colors.A = 127;

            points[0].Vertices.X = windowSize.Height / 4;
            points[0].Vertices.Y = 0;

            points[1].Vertices.X = windowSize.Width;
            points[1].Vertices.Y = windowSize.Height / 5;

            points[2].Vertices.X = windowSize.Width / 3 * 2;
            points[2].Vertices.Y = windowSize.Height;

            draw.DrawTriangleList(points);

            // star poly (triggers buggs)
            {
                const float o    = 80;
                const float w    = 20;
                const float h    = 50;
                CCPoint[]   star = new CCPoint[]
                {
                    new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o),                               // lower spike
                    new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2),               // right spike
                };

                draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1));
            }

            // star poly (doesn't trigger bug... order is important un tesselation is supported.
            {
                const float o    = 180;
                const float w    = 20;
                const float h    = 50;
                var         star = new CCPoint[]
                {
                    new CCPoint(o, o), new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o), // lower spike
                    new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2),    // right spike
                    new CCPoint(o + w, o + w * 2 + h), new CCPoint(o, o + w * 2),            // top spike
                    new CCPoint(o - h, o + w),                                               // left spike
                };

                draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1));
            }


            // Draw segment
            draw.DrawSegment(new CCPoint(20, windowSize.Height), new CCPoint(20, windowSize.Height / 2), 10, new CCColor4F(0, 1, 0, 1));

            draw.DrawSegment(new CCPoint(10, windowSize.Height / 2), new CCPoint(windowSize.Width / 2, windowSize.Height / 2), 40,
                             new CCColor4F(1, 0, 1, 0.5f));
        }