Hello guys
I had a problem with my project, today when I work on it I start to have weird diagonal line appears randomly
here some screen shot: (some time difficult to see, I add red arrow)
How I draw a rectangle:
public Texture2D GetNewUnManagedTexture(int width, int height, bool persistente = false) { Texture2D t = new Texture2D(GraphicsDevice, width, height); if(!persistente) this.TexturesToDispose.Add(t); return t; } private static Dictionary<Color, Texture2D> Pixels = new Dictionary<Color, Texture2D>(); public static Texture2D GetPixel(Color c) { if (Pixels.ContainsKey(c)) return Pixels[c]; // Texture2D texture = GetNewUnManagedTexture(1, 1, true); texture.SetData(new[] { c }); Pixels.Add(c, texture); return Pixels[c]; } public static void DrawRectangleS(int x, int y, int w, int h, Color c) => GameData.DrawOnScreen(GetPixel(c), new Rectangle(x, y, w, h), new Rectangle(0, 0, 1, 1), Color.White);
As you can see I have a Dictionary<Color, Texture2D> for store my texture of 1x1 pixels
I do this to avoid to do texture.SetData(new { color }) every frame
Here my method to draw a texture on screen:
public bool DrawOnScreen(Texture2D texture, Rectangle rPast, Rectangle rCopy, Color color, float angle = 0f) { // check if (texture == null) return false; // reverse and draw or draw directly if (rPast.Width < 0) { rPast.Width = -rPast.Width; this.SpriteBatch.Draw(texture, rPast, rCopy, color, angle, new Vector2(0, 0), SpriteEffects.FlipHorizontally, 0f); } else if (rPast.Height < 0) { rPast.Height = -rPast.Height; this.SpriteBatch.Draw(texture, rPast, rCopy, color, angle, new Vector2(0, 0), SpriteEffects.FlipVertically, 0f); } else if (Math.Abs(angle) > .001f) this.SpriteBatch.Draw(texture, rPast, rCopy, color, angle, new Vector2(rCopy.Width / 2f, rCopy.Height / 2f), SpriteEffects.None, 0f); else this.SpriteBatch.Draw(texture, rPast, rCopy, color); return true; }
Can’t fine what makes them appear and how to fix it, some one with an idea I can work on ?
IDE : VS2015
Mono : 3.5
Template : Desktop OnpenGL