c# - 2D XNA - Draw a Circle -


yo, hi everybody

is there way draw circle? don't want use texture/sprite draw circle because player circle circle should move ... , i'm trying make player/circle's size gets bigger , bigger when eats food blablabla...

anyways, if knows how please tell me.

otherwise : there way change texture height / width , make simple circle texture , change height / width of it.

thanks.

you can use 3d primitives 'someone' :> posted or use c3.xna.primitives2d libary can use extension spritebatch draw circle

public static void drawcircle(this spritebatch spritebatch, vector2 center, float radius, int sides, color color, float thickness); 

if use same value radius , thickness circle appears filled. didn't find offizial download link, there uploads @ sourceforge.

also can generate circle dynamically via code like:

public static texture2d generatecircletexture(graphicsdevice graphicsdevice, int radius, color color, float sharpness)     {         int diameter = radius * 2;         texture2d circletexture = new texture2d(graphicsdevice, diameter, diameter, false, surfaceformat.color);         color[] colordata = new color[circletexture.width * circletexture.height];         vector2 center = new vector2(radius);         (int colindex = 0; colindex < circletexture.width; colindex++)         {             (int rowindex = 0; rowindex < circletexture.height; rowindex++)             {                 vector2 position = new vector2(colindex, rowindex);                 float distance = vector2.distance(center, position);                  // hermite iterpolation                 float x = distance / diameter;                 float edge0 = (radius * sharpness) / (float)diameter;                 float edge1 = radius / (float)diameter;                 float temp = mathhelper.clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);                 float result = temp * temp * (3.0f - 2.0f * temp);                  colordata[rowindex * circletexture.width + colindex] = color * (1f - result);             }         }         circletexture.setdata<color>(colordata);          return circletexture;     } 

sharpness below 1f blurs circle.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -