Ich arbeite am Spiel. Ich möchte einen Punkt auf dem Bildschirm markieren, wenn etwas passiert.Draw Rectangle mit XNA
habe ich eine Klasse für mich zu tun, und fand ein Stück Code, um das Rechteck zu zeichnen: über jedes Update
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
}
Das Problem ist, dass der Code, genannt wird (60-mal pro Sekunde) und es wurde nicht mit optimierter Optimierung geschrieben. Es muss extrem schnell sein (der obige Code friert das Spiel ein, das gerade nur einen Skeleton-Code hat).
Irgendwelche Vorschläge?
Hinweis: Jeder neue Code wäre großartig (WireFrame/Fill sind beide in Ordnung). Ich möchte gerne Farbe angeben können.
Danke! klappt wunderbar. – Ben