2
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

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
\$\endgroup\$
4
  • \$\begingroup\$ 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. \$\endgroup\$
    – steakbbq
    Commented Feb 19, 2012 at 0:31
  • \$\begingroup\$ 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? \$\endgroup\$
    – steakbbq
    Commented Feb 19, 2012 at 0:43
  • \$\begingroup\$ 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. \$\endgroup\$
    – Mike Cluck
    Commented Feb 19, 2012 at 1:13
  • \$\begingroup\$ AWesome i put that link as a todo in the camera class thanks! \$\endgroup\$
    – steakbbq
    Commented Feb 19, 2012 at 1:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .