public override void Draw()
        {
            base.Draw();

            CCApplication app = CCApplication.SharedApplication;
            CCSize        s   = CCDirector.SharedDirector.WinSize;

            CCDrawingPrimitives.Begin();

            // draw a simple line
            CCDrawingPrimitives.DrawLine(new CCPoint(0, 0), new CCPoint(s.Width, s.Height),
                                         new CCColor4B(255, 255, 255, 255));

            // line: color, width, aliased
            CCDrawingPrimitives.DrawLine(new CCPoint(0, s.Height), new CCPoint(s.Width, 0),
                                         new CCColor4B(255, 0, 0, 255));

            // draw big point in the center
            CCDrawingPrimitives.DrawPoint(new CCPoint(s.Width / 2, s.Height / 2), 64, new CCColor4B(0, 0, 255, 128));

            // draw 4 small points
            CCPoint[] points = { new CCPoint(60, 60), new CCPoint(70, 70), new CCPoint(60, 70), new CCPoint(70, 60) };
            CCDrawingPrimitives.DrawPoints(points, 4, 4, new CCColor4B(0, 255, 255, 255));

            // draw a green circle with 10 segments
            CCDrawingPrimitives.DrawCircle(new CCPoint(s.Width / 2, s.Height / 2), 100, 0, 10, false,
                                           new CCColor4B(0, 255, 0, 255));

            // draw a green circle with 50 segments with line to center
            CCDrawingPrimitives.DrawCircle(new CCPoint(s.Width / 2, s.Height / 2), 50, CCMacros.CCDegreesToRadians(90),
                                           50, true, new CCColor4B(0, 255, 255, 255));


            // draw an arc within rectangular region
            CCDrawingPrimitives.DrawArc(new CCRect(200, 200, 100, 200), 0, 180,
                                        new CCColor4B(Microsoft.Xna.Framework.Color.AliceBlue));

            // draw an ellipse within rectangular region
            CCDrawingPrimitives.DrawEllipse(new CCRect(500, 200, 100, 200), new CCColor4B(255, 0, 0, 255));

            // draw an arc within rectangular region
            CCDrawingPrimitives.DrawPie(new CCRect(350, 0, 100, 100), 20, 100,
                                        new CCColor4B(Microsoft.Xna.Framework.Color.AliceBlue));

            // draw an arc within rectangular region
            CCDrawingPrimitives.DrawPie(new CCRect(347, -5, 100, 100), 120, 260,
                                        new CCColor4B(Microsoft.Xna.Framework.Color.Aquamarine));

            // open yellow poly
            CCPoint[] vertices =
            {
                new CCPoint(0,  0), new CCPoint(50, 50), new CCPoint(100, 50), new CCPoint(100, 100),
                new CCPoint(50, 100)
            };
            CCDrawingPrimitives.DrawPoly(vertices, 5, false, new CCColor4B(255, 255, 0, 255));

            // filled poly
            CCPoint[] filledVertices =
            {
                new CCPoint(0,  120), new CCPoint(50, 120), new CCPoint(50, 170),
                new CCPoint(25, 200), new CCPoint(0, 170)
            };
            CCDrawingPrimitives.DrawSolidPoly(filledVertices, 5, new CCColor4B(128, 128, 255, 255));

            // closed purble poly
            CCPoint[] vertices2 = { new CCPoint(30, 130), new CCPoint(30, 230), new CCPoint(50, 200) };
            CCDrawingPrimitives.DrawPoly(vertices2, 3, true, new CCColor4B(255, 0, 255, 255));

            // draw quad bezier path
            CCDrawingPrimitives.DrawQuadBezier(new CCPoint(0, s.Height),
                                               new CCPoint(s.Width / 2, s.Height / 2),
                                               new CCPoint(s.Width, s.Height),
                                               50,
                                               new CCColor4B(255, 0, 255, 255));

            // draw cubic bezier path
            CCDrawingPrimitives.DrawCubicBezier(new CCPoint(s.Width / 2, s.Height / 2),
                                                new CCPoint(s.Width / 2 + 30, s.Height / 2 + 50),
                                                new CCPoint(s.Width / 2 + 60, s.Height / 2 - 50),
                                                new CCPoint(s.Width, s.Height / 2), 100,
                                                new CCColor4B(255, 0, 255, 255));

            //draw a solid polygon
            CCPoint[] vertices3 =
            {
                new CCPoint(60, 160), new CCPoint(70, 190), new CCPoint(100, 190),
                new CCPoint(90, 160)
            };
            CCDrawingPrimitives.DrawSolidPoly(vertices3, 4, new CCColor4B(255, 255, 0, 255));

            CCDrawingPrimitives.End();
        }
示例#2
0
        void RenderDrawPrimTest()
        {
            CCSize size = Layer.VisibleBoundsWorldspace.Size;

            var visibleRect = VisibleBoundsWorldspace;

            CCDrawingPrimitives.Begin();


            // *NOTE* Using the Director.ContentScaleFactor for now until we work something out with the initialization
            // CCDrawPriitives should be able to do this converstion themselves.

            // draw a simple line
            // The default state is:
            // Line Width: 1
            // color: 255,255,255,255 (white, non-transparent)
            // Anti-Aliased
            //  glEnable(GL_LINE_SMOOTH);
            CCDrawingPrimitives.LineWidth = 1;
            CCDrawingPrimitives.DrawLine(visibleRect.LeftBottom(), visibleRect.RightTop());

            // line: color, width, aliased
            CCDrawingPrimitives.LineWidth = 5;
            CCDrawingPrimitives.DrawColor = CCColor4B.Red;
            CCDrawingPrimitives.DrawLine(visibleRect.LeftTop(), visibleRect.RightBottom());

            // TIP:
            // If you are going to use always thde same color or width, you don't
            // need to call it before every draw
            //

            // draw big point in the center
            CCDrawingPrimitives.PointSize = 64;
            CCDrawingPrimitives.DrawColor = new CCColor4B(0, 0, 255, 128);
            CCDrawingPrimitives.DrawPoint(visibleRect.Center());

            // draw 4 small points
            CCPoint[] points = { new CCPoint(60, 60), new CCPoint(70, 70), new CCPoint(60, 70), new CCPoint(70, 60) };

            CCDrawingPrimitives.PointSize = 8;
            CCDrawingPrimitives.DrawColor = new CCColor4B(0, 255, 255, 255);
            CCDrawingPrimitives.DrawPoints(points);

            // draw a green circle with 10 segments
            CCDrawingPrimitives.LineWidth = 16;
            CCDrawingPrimitives.DrawColor = CCColor4B.Green;
            CCDrawingPrimitives.DrawCircle(visibleRect.Center, 100, 0, 10, false);


            // draw a green circle with 50 segments with line to center
            CCDrawingPrimitives.LineWidth = 2;
            CCDrawingPrimitives.DrawColor = new CCColor4B(0, 255, 255, 255);
            CCDrawingPrimitives.DrawCircle(visibleRect.Center, 50, CCMacros.CCDegreesToRadians(45), 50, true);


            // draw a pink solid circle with 50 segments
            CCDrawingPrimitives.LineWidth = 2;
            CCDrawingPrimitives.DrawColor = new CCColor4B(255, 0, 255, 255);
            CCDrawingPrimitives.DrawSolidCircle(visibleRect.Center + new CCPoint(140, 0), 40, CCMacros.CCDegreesToRadians(90), 50);


            // draw an arc within rectangular region
            CCDrawingPrimitives.LineWidth = 5;
            CCDrawingPrimitives.DrawArc(new CCRect(200, 100, 100, 200), 0, 180, CCColor4B.AliceBlue);

            // draw an ellipse within rectangular region
            CCDrawingPrimitives.DrawEllipse(new CCRect(100, 100, 100, 200), CCColor4B.Red);

            // draw an arc within rectangular region
            CCDrawingPrimitives.DrawPie(new CCRect(350, 0, 100, 100), 20, 100, CCColor4B.AliceBlue);

            // draw an arc within rectangular region
            CCDrawingPrimitives.DrawPie(new CCRect(347, -5, 100, 100), 120, 260, CCColor4B.Aquamarine);

            // open yellow poly
            CCPoint[] vertices =
            {
                new CCPoint(0,  0), new CCPoint(50, 50), new CCPoint(100, 50), new CCPoint(100, 100),
                new CCPoint(50, 100)
            };
            CCDrawingPrimitives.LineWidth = 10;
            CCDrawingPrimitives.DrawColor = CCColor4B.Yellow;
            CCDrawingPrimitives.DrawPoly(vertices, 5, false, new CCColor4B(255, 255, 0, 255));


            // filled poly
            CCDrawingPrimitives.LineWidth = 1;
            CCPoint[] filledVertices =
            {
                new CCPoint(0,  120), new CCPoint(50, 120), new CCPoint(50, 170),
                new CCPoint(25, 200), new CCPoint(0, 170)
            };
            CCDrawingPrimitives.DrawSolidPoly(filledVertices, new CCColor4F(0.5f, 0.5f, 1, 1));

            // closed purple poly
            CCDrawingPrimitives.LineWidth = 2;
            CCDrawingPrimitives.DrawColor = new CCColor4B(255, 0, 255, 255);
            CCPoint[] vertices2 = { new CCPoint(30, 130), new CCPoint(30, 230), new CCPoint(50, 200) };
            CCDrawingPrimitives.DrawPoly(vertices2, true);

            // draw quad bezier path
            CCDrawingPrimitives.DrawQuadBezier(new CCPoint(0, size.Height),
                                               visibleRect.Center,
                                               (CCPoint)visibleRect.Size,
                                               50,
                                               new CCColor4B(255, 0, 255, 255));

            // draw cubic bezier path
            CCDrawingPrimitives.DrawCubicBezier(visibleRect.Center,
                                                new CCPoint(size.Width / 2 + 30, size.Height / 2 + 50),
                                                new CCPoint(size.Width / 2 + 60, size.Height / 2 - 50),
                                                new CCPoint(size.Width, size.Height / 2), 100);

            //draw a solid polygon
            CCPoint[] vertices3 =
            {
                new CCPoint(60, 160), new CCPoint(70, 190), new CCPoint(100, 190),
                new CCPoint(90, 160)
            };
            CCDrawingPrimitives.DrawSolidPoly(vertices3, 4, new CCColor4F(1, 1, 0, 1));

            CCDrawingPrimitives.End();
        }
示例#3
0
        void CreateObject()
        {
            // Define the dynamic body.
            var bodyDef = new b2BodyDef();

            bodyDef.type = b2BodyType.b2_dynamicBody;             //or you could use b2_staticBody

            bodyDef.position.Set(initialLocation.X / Constants.PTM_RATIO, initialLocation.Y / Constants.PTM_RATIO);

            var shape       = new b2PolygonShape();
            var shapeCircle = new b2CircleShape();

            if (shapeCreationMethod == CreationMethod.DiameterOfImageForCircle)
            {
                var tempSprite     = new CCSprite(spriteImageName);
                var radiusInMeters = (tempSprite.Texture.ContentSizeInPixels.Width / Constants.PTM_RATIO) * 0.5f;

                shapeCircle.Radius = radiusInMeters;
            }


            else if (shapeCreationMethod == CreationMethod.ShapeOfSourceImage)
            {
                var tempSprite = new CCSprite(spriteImageName);

                var      num      = 4;
                b2Vec2[] vertices =
                {
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2) / Constants.PTM_RATIO),                      //top left corner
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO),                     //bottom left corner
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO),                      //bottom right corner
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2) / Constants.PTM_RATIO)                        //top right corner
                };
                shape.Set(vertices, num);
            }

            else if (shapeCreationMethod == CreationMethod.Triangle)
            {
                var tempSprite = new CCSprite(spriteImageName);

                var      num      = 3;
                b2Vec2[] vertices =
                {
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO), //bottom left corner
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO),  //bottom right corner
                    new b2Vec2(0.0f / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2) / Constants.PTM_RATIO)                                                  // top center of image
                };

                shape.Set(vertices, num);
            }

            else if (shapeCreationMethod == CreationMethod.TriangleRightAngle)
            {
                var tempSprite = new CCSprite(spriteImageName);

                var      num      = 3;
                b2Vec2[] vertices =
                {
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2) / Constants.PTM_RATIO),                        //top right corner
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2) / Constants.PTM_RATIO),                       //top left corner
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO)                       //bottom left corner
                };

                shape.Set(vertices, num);
            }

            else if (shapeCreationMethod == CreationMethod.Trapezoid)
            {
                var tempSprite = new CCSprite(spriteImageName);

                var      num      = 4;
                b2Vec2[] vertices =
                {
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 4) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2) / Constants.PTM_RATIO),                        //top of image, 3/4's across
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -4) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2) / Constants.PTM_RATIO),                       //top of image, 1/4's across
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO),                      //bottom left corner
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO),                       //bottom right corner
                };

                shape.Set(vertices, num);
            }


            else if (shapeCreationMethod == CreationMethod.Hexagon)
            {
                var tempSprite = new CCSprite(spriteImageName);

                var      num      = 6;
                b2Vec2[] vertices =
                {
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -4) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2) / Constants.PTM_RATIO),  //top of image, 1/4 across
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -2) / Constants.PTM_RATIO, 0.0f / Constants.PTM_RATIO),                                                 // left, center
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -4) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO), //bottom of image, 1/4 across
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 4) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO),  //bottom of image, 3/4's across
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 2) / Constants.PTM_RATIO, 0.0f / Constants.PTM_RATIO),                                                  // right, center
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 4) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2) / Constants.PTM_RATIO)    //top of image, 3/4's across
                };

                shape.Set(vertices, num);
            }

            else if (shapeCreationMethod == CreationMethod.Pentagon)
            {
                var tempSprite = new CCSprite(spriteImageName);

                var      num      = 5;
                b2Vec2[] vertices =
                {
                    new b2Vec2(0 / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2) / Constants.PTM_RATIO),                                                    //top of image, center
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -2) / Constants.PTM_RATIO, 0.0f / Constants.PTM_RATIO),                                                 // left, center
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -4) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO), //bottom of image, 1/4 across
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 4) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO),  //bottom of image, 3/4's across
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 2) / Constants.PTM_RATIO, 0.0f / Constants.PTM_RATIO),                                                  // right, center
                };

                shape.Set(vertices, num);
            }

            else if (shapeCreationMethod == CreationMethod.Octagon)
            {
                var tempSprite = new CCSprite(spriteImageName);

                var      num      = 8;
                b2Vec2[] vertices =
                {
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -6) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2) / Constants.PTM_RATIO),                        //use the source image octogonShape.png for reference
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 6) / Constants.PTM_RATIO),
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -6) / Constants.PTM_RATIO),
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -6) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO),
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 6) / Constants.PTM_RATIO,  (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO),
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 2) / Constants.PTM_RATIO,  (tempSprite.Texture.ContentSizeInPixels.Height / -6) / Constants.PTM_RATIO),
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 2) / Constants.PTM_RATIO,  (tempSprite.Texture.ContentSizeInPixels.Height / 6) / Constants.PTM_RATIO),
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 6) / Constants.PTM_RATIO,  (tempSprite.Texture.ContentSizeInPixels.Height / 2) / Constants.PTM_RATIO)
                };

                shape.Set(vertices, num);
            }
            else if (shapeCreationMethod == CreationMethod.Parallelogram)
            {
                var tempSprite = new CCSprite(spriteImageName);

                var      num      = 4;
                b2Vec2[] vertices =
                {
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -4) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2) / Constants.PTM_RATIO),                      //top of image, 1/4 across
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / -2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO),                     //bottom left corner
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 4) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / -2) / Constants.PTM_RATIO),                      //bottom of image, 3/4's across
                    new b2Vec2((tempSprite.Texture.ContentSizeInPixels.Width / 2) / Constants.PTM_RATIO, (tempSprite.Texture.ContentSizeInPixels.Height / 2) / Constants.PTM_RATIO)                        //top right corner
                };

                shape.Set(vertices, num);
            }

            else if (shapeCreationMethod == CreationMethod.CustomCoordinates1)                 //use your own custom coordinates from a program like Vertex Helper Pro

            {
                var      num      = 4;
                b2Vec2[] vertices =
                {
                    new b2Vec2(-64.0f / Constants.PTM_RATIO,  16.0f / Constants.PTM_RATIO),
                    new b2Vec2(-64.0f / Constants.PTM_RATIO, -16.0f / Constants.PTM_RATIO),
                    new b2Vec2(64.0f / Constants.PTM_RATIO,  -16.0f / Constants.PTM_RATIO),
                    new b2Vec2(64.0f / Constants.PTM_RATIO, 16.0f / Constants.PTM_RATIO)
                };
                shape.Set(vertices, num);
            }



            // Define the dynamic body fixture.
            var fixtureDef = new b2FixtureDef();

            if (shapeCreationMethod == CreationMethod.DiameterOfImageForCircle)
            {
                fixtureDef.shape = shapeCircle;
            }
            else
            {
                fixtureDef.shape = shape;
            }

            fixtureDef.density     = theDensity;
            fixtureDef.friction    = 0.3f;
            fixtureDef.restitution = 0.1f;

            CreateBodyWithSpriteAndFixture(theWorld, bodyDef, fixtureDef, spriteImageName);


            if (angle != 0)
            {
                int    currentAngle     = (int)body.Angle;
                b2Vec2 locationInMeters = body.Position;
                body.SetTransform(locationInMeters, CCMacros.CCDegreesToRadians(currentAngle + angle));
            }

            if (IsStatic)
            {
                MakeBodyStatic();
            }
        }
示例#4
0
        private void MyGamePadTriggerUpdate(float leftTriggerStrength, float rightTriggerStrength, PlayerIndex player)
        {
            CCNode node = GetChildByTag(kTagTileMap);

            if (node != null)
            {
                float incrementRotation = rightTriggerStrength * CCMacros.CCDegreesToRadians(15f) - leftTriggerStrength * CCMacros.CCDegreesToRadians(15f);
                node.RotationX += incrementRotation;
                node.RotationY += incrementRotation;
            }
        }