Polygon Color

Jun 29, 2009 at 5:59 PM

I am using the polygon brush used in the samples and was wondering how I would go about changing the color of the polygon (inside)

I have tried changing the Color (_color) but it isnt working.

Any suggestions appreciated.

Jun 29, 2009 at 6:37 PM

How are you creating the PolygonBrush object?  Looking at the code, there are 2 constructors.  One default, (which defaults to Color.White for the inside), and one that takes in a bunch of parameters:

public PolygonBrush(Vertices vertices, Color color, Color borderColor, float borderThickness, float layer)

So, create the brush using the 2nd constructor, like this:

PolygonBrush newBrush = new PolygonBrush(vertices, Color.Blue, Color.Black, 1, .5);

The interior color is the underlined line.

Jun 29, 2009 at 6:41 PM

I am changing the color within the game and do not want to make a new brush everytime i change the color.

Is there anyway to change the brushes color property after creating it so that it draws with the specified color?

 

Jun 29, 2009 at 7:00 PM
Edited Jun 29, 2009 at 7:00 PM

There should be... what code are you trying to run to change the color?

Jun 29, 2009 at 7:05 PM

PolygonBrush polyBrush = new PolygonBrush(vertices, color, borderColor, 2, 0);

polyBrush.Color = Color.Red;

I create the brush and in the program, I change its color (for example, to red); however, no matter what polyBrush.Color is, it draws the polygon using its original assigned color.

Jun 29, 2009 at 7:19 PM
Edited Jun 29, 2009 at 7:21 PM

Looking through PolygonBrush, the constructor takes the color, then creates the set of vertices based on this color.  The color from this point is stored per vertice. 

This is just a guess looking at the code, but after you change the color, try recreating the vertices of the brush:

PolygonBrush polyBrush = new PolygonBrush(vertices, color, borderColor, 2, 0);

polyBrush.Color = Color.Red;

polyBrush.Vertices = vertices;

Jun 29, 2009 at 8:45 PM

that should work, thanks for all your help