Drawing rectangle using Vector2 causes stuttering. Help.

I am using Primitives2D to draw basic shapes like rectangles for debugging. The library uses rectangles (ints) while I use floats for positioning and this causes stuttering when drawing.

^ As you can see above (running at 0.01 timeScale)

And here’s the code

// Moving sample code
delta.X += _speed * Time.DeltaTime;
Transform.Position += delta;

// Drawing code
Vector2 upperLeft = Transform.Position - (SourceRectangle.Size.ToVector2() / 2);
spriteBatch.DrawRectangle(new Rectangle(upperLeft.ToPoint(), 
    SourceRectangle.Size), Color.Yellow);

Could anyone guide as to how to solve this float to int conversion problem. Thanks.

I don’t know anything about primitives2d but if its using ints you might have to make your own drawabler ectangle class.

Create one with 4 sides and use the spritebatch draw method that takes floats.

For the source rectangle use a 1 pixel white rectangle (off a spritesheet or create your own texture2d) then use a vector 2 as a scale in the spritebatch draw method. So for the top line if it needs to be 50 pixels wide and 2 pixels high use a vector2 50,2 for the scale

If your using a white pixel you can just change the colour in the spritebath draw method. Eg color.red

Its probably best to first create a single line class that will draw a basic line. Then in your rectangle class include 4 lines in it.

I’ve modified the Primitives2D class to draw rectangles using Vector2s instead of Rectangles and it works perfectly. Thanks.

Could you post the spriteBatch.Begin() code you’re using? Also what resolution your game is running and the size of the rectangle you’re drawing.