# SpriteBatch Draw Using Floats with the Destination Rectangle

So I created a nice little isometric tile engine and I have it so that when you scroll with the mouse it changes a variable called scale. Scale is a float and gets passed through the spritebatch.draw() function. I apply scale to all of the math I do when generating the positions of the tiles.

The problem I am having is Rectangle will not accept float numbers so when I make my Dest Rectangle for the spritebatch.draw() I can not use the numbers I need to because they are now floats.

I tried using vector4 instead of rectangle but the spritebatch.draw was throwing an exception saying it was expecting Rectangle not Vector4.

Is it possible to draw the dest rect using floats instead of ints?

Btw the scale is all working properly however since I am casting the floats to ints any scale that should have a decimal gets truncated and I end up with spaces between my tiles.

Rather than drawing out through the destination rectangle, you could draw from a position and apply a scale.

Spritebatch.Draw(myTexture, // Texture
myPosition,             // Position
sourceRect,             // Source rectangle
Color.White, // If you don't want to add tinting use white
0,                      // Rotation
null,                   // Origin
Scale,                  // You guessed it
SpriteEffects.None,     // Mirroring effects
depth);                 // Layer depth

• Okay, I will try this, I knew it was something so obvious I was over looking it. Let me see if I can get this to work. – steakbbq Feb 19 '12 at 0:31
• Perfect works amazing! Any hints on how to make it so that when I zoom in and out it zooms in and out to the center of the screen? – steakbbq Feb 19 '12 at 0:43
• Cool, glad that worked for you ;D If you want to zoom in on the center, you might look in to using a full-on 2D camera system. This is where I learned how to make mine. – Mike Cluck Feb 19 '12 at 1:13
• AWesome i put that link as a todo in the camera class thanks! – steakbbq Feb 19 '12 at 1:35