1
\$\begingroup\$

Problem: It seems like the Draw() call allows us to use either Destination Rectangle for resizing (5of8) or Scale (6of8/7of8) but not both.

Purpose: I would like to resize a button from 567x634 to 400x480 and then using scale to further reduce it by 0.8 to 320x400.

\$\endgroup\$
7
  • \$\begingroup\$ Why would you want to resize a texture twice? Personally I think the Texture uploaded should have a different size itself. \$\endgroup\$
    – Steven
    Dec 6 '19 at 7:33
  • \$\begingroup\$ Can you elaborate on what is the difference when you say "resize" a texture, and "scale" it? Also I'm not sure I understand what you mean when you say (5of8). I'm not sure if that's something specific to XNA. Could you maybe provide more details? \$\endgroup\$
    – TomTsagk
    Dec 6 '19 at 14:57
  • \$\begingroup\$ @TomTsagk: It's just XNA's Draw calls. There is a total of 8 ways fill in the parameters for SpriteBatch.Draw(). Once you loaded in the texture, there is a draw call that takes into account the destination (that can be resized), and then there's a draw call that can scale it down to 0.9, 0.8... from the original size. But you can't do both. \$\endgroup\$
    – spirits
    Dec 6 '19 at 19:07
  • \$\begingroup\$ @Steven So that we can be more sloppy with the image file resolution. The second time I scale down is just to feel like a button pressed down. I suppose there is no easy inherent way to resize and scale via monogame, and that I had to take it to photoshop and make a couple of extra png files? \$\endgroup\$
    – spirits
    Dec 6 '19 at 19:12
  • \$\begingroup\$ the overload 8of8 does have all of them - you just have to add "scale: 0.5f" as parameter. And you can also just scale the rectangle on your own before sendign to Draw \$\endgroup\$
    – reiti.net
    Dec 7 '19 at 17:38
1
\$\begingroup\$

You can make a RenderTarget of any width and height. You can optional set up that render target to be persistant by sending in PreserveContents as the final parameter when you create the render target. You can set the render target to the GraphicsDevice in the Game1.Draw method. You can then draw your current texture to that render target with Spritebatch.Draw

SpriteBatch.Draw has a parameter that you will see by the name of 'destination'.

That rectangle should have the same size as the render target its location should be 0,0.

Once drawn to the desired new size you then have the option to use the render target as if it were a texture.

This means you can call save on it, in order to write it to file. You can use it as a texture and draw it to the back buffer. You can draw it with SpriteBatch.Draw using the scale parameter or by destination again.

If you made your render target persistent you can keep it around. However this would be frowned upon by many as well as re-scaling and not pre-scaling the texture before loading. In addition this may not be supported on older hardware and on new hardware may incur a performance penalty. However i digress.

I believe the above answers to this part of the question generally.

Purpose: I would like to resize a button from 567x634 to 400x480 and then using scale to further reduce it

While the below is not exactly a clear question, i surmise you are asking why?

Problem: It seems like the Draw() call allows us to use either Destination Rectangle for resizing (5of8) or Scale (6of8/7of8) but not both.

The act of setting a destination Rectangle means that scaling is implicit. E.G. i have a texture of width and height 100,100 and i set it to a destination rectangle on screen of new Rectangle(0,0,80,80); That is equivillent to performing a scaling of .8f,.8f on the width and height of the texture. i.e. 100 *.8 = 80.

Therefor it would be first of all confusing, additionally it would be open to alternate interpretations to the operational precedence of what scaling operation happens in what order, finally it would be pointless to have both the destination and scaling parameter in the same overload.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.