XNA沒有任何支持圓繪圖的方法。
通常,當我不得不畫圓圈時,總是用相同的顏色,我只是用那個圓圈做出圖像,然後我可以將它顯示爲精靈。
但是現在在運行時指定了圓的顏色,任何想法如何處理?如何在XNA中繪製具有特定顏色的圓?
10
A
回答
37
您可以簡單地用Transparent
背景和圓圈的彩色部分作爲White
來製作圓形圖像。然後,當談到在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;
}
相關問題
- 1. 繪製特定顏色
- 2. 如何在XNA中繪製顏色的字符串名稱?
- 3. 具有不同顏色邊框的Android繪製圓圈
- 4. 製造具有特定顏色透明
- 5. 在XNA中繪製簡單的圓圈
- 6. gnuplot:如何繪製具有特定寬度,高度和顏色的盒子
- 7. 如何用特定顏色繪製矩陣中的矩陣值
- 8. 在XNA中着色一個特定的顏色
- 9. 如何在iOS中用自定義數量填充顏色來繪製圓圈?
- 10. 如何在Matlab中繪製顏色塊
- 11. 在SVG中繪製具有「負」顏色的路徑
- 12. 在XNA不同的顏色繪製的字體/ C#
- 13. 使用for-loop字符來繪製幾行具有特定顏色的線
- 14. 如何使用特定顏色繪製CGGradient?
- 15. 如何在XNA的3D地形上繪製圓形?
- 16. C#在特定顏色通道中繪製矩形
- 17. 如何使用圓形進度繪製加陣列顏色
- 18. 如何在matlab中繪製具有不同顏色和組的條形圖
- 19. 如何在十六進制顏色的圖形對象上繪製實心圓?
- 20. 製作特定的UITableViewCell具有不同的背景顏色
- 21. 動態更改在Google地圖上繪製的圓的顏色
- 22. XNA繪製一個實心圓
- 23. 如何在R中繪製圖像時指定顏色
- 24. 如何在java中繪製熱圖,顯示圓圈而不是顏色
- 25. XNA SpriteFont有多種顏色?
- 26. 顏色繪製不同的顏色matplotlib
- 27. 如何在XNA中繪製2D像素?
- 28. 如何在MonoGame/XNA中繪製虛線
- 29. 如何繪製不同的顏色
- 30. 如何在Excel中只複製特定顏色的文字?
我記得在XNA的論壇上看到類似的東西。 – Mike 2010-06-06 10:48:23