Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Colors 如何在XNA中绘制特定颜色的圆?_Colors_Drawing_Xna_Geometry - Fatal编程技术网

Colors 如何在XNA中绘制特定颜色的圆?

Colors 如何在XNA中绘制特定颜色的圆?,colors,drawing,xna,geometry,Colors,Drawing,Xna,Geometry,XNA没有任何支持圆绘制的方法。 通常,当我必须画圆圈时,总是用相同的颜色,我只是用那个圆圈做了一个图像,然后我可以把它显示为精灵。 但是现在圆的颜色是在运行时指定的,你知道如何处理吗?你可以简单地用透明的背景制作一个圆的图像,并且圆的有色部分是白色的。然后,在使用Draw()方法绘制圆时,选择所需的色调: Texture2D circle = CreateCircle(100); // Change Color.Red to the colour you want spriteBatch.D

XNA没有任何支持圆绘制的方法。
通常,当我必须画圆圈时,总是用相同的颜色,我只是用那个圆圈做了一个图像,然后我可以把它显示为精灵。

但是现在圆的颜色是在运行时指定的,你知道如何处理吗?

你可以简单地用
透明的
背景制作一个圆的图像,并且圆的有色部分是
白色的
。然后,在使用
Draw()
方法绘制圆时,选择所需的色调:

Texture2D circle = CreateCircle(100);

// Change Color.Red to the colour you want
spriteBatch.Draw(circle, new Vector2(30, 30), Color.Red); 

为了好玩,下面是CreateCircle方法:

    public Texture2D CreateCircle(int radius)
    {
        int outerRadius = radius*2 + 2; // So circle doesn't go out of bounds
        Texture2D texture = new Texture2D(GraphicsDevice, outerRadius, outerRadius);

        Color[] data = new Color[outerRadius * outerRadius];

        // Colour the entire texture transparent first.
        for (int i = 0; i < data.Length; i++)
            data[i] = Color.TransparentWhite;

        // Work out the minimum step necessary using trigonometry + sine approximation.
        double angleStep = 1f/radius;

        for (double angle = 0; angle < Math.PI*2; angle += angleStep)
        {
            // Use the parametric definition of a circle: http://en.wikipedia.org/wiki/Circle#Cartesian_coordinates
            int x = (int)Math.Round(radius + radius * Math.Cos(angle));
            int y = (int)Math.Round(radius + radius * Math.Sin(angle));

            data[y * outerRadius + x + 1] = Color.White;
        }

        texture.SetData(data);
        return texture;
    }
public Texture2D CreateCircle(整数半径)
{
int outerRadius=radius*2+2;//所以圆不会超出边界
纹理2d纹理=新纹理2d(图形设备、外层、外层);
颜色[]数据=新颜色[outerRadius*outerRadius];
//首先将整个纹理着色为透明。
for(int i=0;i
我记得在XNA的论坛上读过类似的文章。我知道这个帖子很老,但你的代码给我返回了一个圆圈。你知道我怎么解决这个问题吗?@Weszzz7,它不应该返回一个圆吗?