Repos

MELHARFI-2D-Game-Engine.

Got to repo.

08. FillPolygon (shapes)

FillPolygon class

FillPolygon is a shape that you can draw on the screen with a filled color inside.

  • Parameters
  • 1- Brush = color

    2- Point[] Corners of the polygon

    The trick is that you have to define the location of each corner of polygone, if you have 3 corners, then it's a triangle, 4 corners is a rectangle and so on

    First we need to define a Point[] object that will store all corner's points, make attention that order is important, the last point will be automatically linked with the first entry of the array point to complete the Polygon like this :

                            
    Manager manager = new Manager(this, "CORE_ENGINE");
    manager.Background = Color.Blue;
    
    Point[] points = new Point[6];
    points[0] = new Point(100, 150);
    points[1] = new Point(150, 100);
    points[2] = new Point(300, 100);
    points[3] = new Point(350, 150);
    points[4] = new Point(300, 200);
    points[5] = new Point(150, 200);
                            
                          

  • 3- FillMode
  • describ the way the fill color will be applyed there's 2 options : FillMode.Alternate and FillMode.Winding

    FillMode.Alternate FillPolygon can draw many sections, and those sections can be superposed, and when it's the case, the alternate mode will negate the filling purpose, meaning that if an area is filled, and another shape is going to be filled over an existed shape, the color that intersect with it well be voided (not colored).

    Here is a Link to better understand link.

    FillMode.Winfing it's the default value, all the contente of the Polygon will be filled with the brush color.

                            
    Manager manager = new Manager(this, "CORE_ENGINE");
    manager.Background = Color.Blue;
                  
    Point[] points = new Point[6];
    points[0] = new Point(100, 150);
    points[1] = new Point(150, 100);
    points[2] = new Point(300, 100);
    points[3] = new Point(350, 150);
    points[4] = new Point(300, 200);
    points[5] = new Point(150, 200);
                  
    FillPolygon fp = new FillPolygon(Brushes.Green, points, Manager.TypeGfx.Object, "fp", true, System.Drawing.Drawing2D.FillMode.Winding, manager);
    manager.BackgroundLayer.Add(fp);
                            
                          

  • Second overload
  • 2 parameters are added Border color and size

                            
    FillPolygon fp = new FillPolygon(Brushes.Green, points, Manager.TypeGfx.Object, "fp", true, System.Drawing.Drawing2D.FillMode.Winding, Color.Red, 3, manager);
                            
                          

    Services

    App Developpement

    Want me to dev an app for you ? dont hesitate to contact me.

    Programming

    Are you looking for a coder/teammate for your project ? Let's give it a try.

    Job Invitation

    Have a proposal for me ? we can discuss about it.

    Donation maybe ?!

    You want to buy me a coffe ? m.elharfi@gmail.com