我正在开发一个游戏。当某些事情发生时,我想在屏幕上突出显示一个点。
我创建了一个类来完成这个任务,然后找到了一段画矩形的代码:
static private Texture2D CreateRectangle(int width, int height, Color colori)
{
Texture2D rectangleTexture = new Texture2D(game.GraphicsDevice, width, height, 1, TextureUsage.None,
SurfaceFormat.Color);// create the rectangle texture, ,but it will have no color! lets fix that
Color[] color = new Color[width * height];//set the color to the amount of pixels in the textures
for (int i = 0; i < color.Length; i++)//loop through all the colors setting them to whatever values we want
{
color[i] = colori;
}
rectangleTexture.SetData(color);//set the color data on the texture
return rectangleTexture;//return the texture
}
问题在于上述代码每次更新都会被调用(每秒60次),而它并没有考虑到优化。它需要非常快(上面的代码会冻结游戏,现在游戏只有骨架代码)。
有任何建议吗?
注意:任何新的代码都可以(线框/填充都可以)。我想能够指定颜色。