Jump to content
  • Advertisement
Sign in to follow this  
FirstStep

Scale entity dynamically

This topic is 831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I got a scree width of 1020. Say I want to place every brick of my game evenly.  For example I want 8 bricks in a row. How can I calculate the estimated scale value to use for the brick? I am using XNA. I was thinking of 1020 / 8  and I got 127.5. I think thats the width I have to give to my bricks. But the scaling in XNA is different. I think the normal scale is 1. So that 127.5, how can I get the correct scale value for that?. I tried 100/127.5 but still cant get the correct value.

 

TY

Edited by FirstStep

Share this post


Link to post
Share on other sites
Advertisement

sx = desired width / texture width

 

sy = desired height / texture height

 

remember that blits are based on the center, not the upper left corner. you'll have to adjust accordingly.

 

so if the screen is 1020 pixels wide, and you want 8 bricks across the screen, that's 1020/8=127.5 pixels wide for each brick.

 

if your brick texture is 256x256 pixels in size, your sx = 127.5/256 = 0.498046875.

 

checking your math...

 

a 256 pixel wide texture scaled by 0.498046875 would be 256*0.498046875= 127.5 pixels wide (correct).

 

8 bricks at 127.5 pixels each = 8*127.5 = 1020 pixels (correct).

 

note that you can't blit at x=127.5, only at x=127 or x=128. so you may have a bit of overlap or a gap at the right edge depending on how you handle rounding off the x coordinate for the blit. probably better to use an integral size for "brick width in pixels".

Edited by Norman Barrows

Share this post


Link to post
Share on other sites

sx = desired width / texture width

 

sy = desired height / texture height

 

remember that blits are based on the center, not the upper left corner. you'll have to adjust accordingly.

 

so if the screen is 1020 pixels wide, and you want 8 bricks across the screen, that's 1020/8=127.5 pixels wide for each brick.

 

if your brick texture is 256x256 pixels in size, your sx = 127.5/256 = 0.498046875.

 

checking your math...

 

a 256 pixel wide texture scaled by 0.498046875 would be 256*0.498046875= 127.5 pixels wide (correct).

 

8 bricks at 127.5 pixels each = 8*127.5 = 1020 pixels (correct).

 

note that you can't blit at x=127.5, only at x=127 or x=128. so you may have a bit of overlap or a gap at the right edge depending on how you handle rounding off the x coordinate for the blit. probably better to use an integral size for "brick width in pixels".

 

 

Im confuse about blits. Search about it and it said the blitting is the process of copying bits of  graphical memory to another part. What does it have to do with the blit your talking about? I mean the center? Im really confuse

Share this post


Link to post
Share on other sites

so if the screen is 1020 pixels wide, and you want 8 bricks across the screen, that's 1020/8=127.5 pixels wide for each brick.

if your brick texture is 256x256 pixels in size, your sx = 127.5/256 = 0.498046875.

This is the scale answer. Scaling means you multiply the brick texture size by some factor S.

The result is that your brick becomes (256*S)x(256*S) pixels (if you scale the same in both directions). Since you want 127.5 pixels, 256 * S = 127.5  <--> S = 127.5 / 256 = 0.498, as Norman computed for you.

 

remember that blits are based on the center, not the upper left corner. you'll have to adjust accordingly.

I have no experience with textures, but I think Norman means that you have to shift the origin of the brick to its center, when blitting it scaled. I don't know what bad things happen when you don't do that, but I'd say, try it for yourself.

Share this post


Link to post
Share on other sites

 

 

 

remember that blits are based on the center, not the upper left corner. you'll have to adjust accordingly.

I have no experience with textures, but I think Norman means that you have to shift the origin of the brick to its center, when blitting it scaled. I don't know what bad things happen when you don't do that, but I'd say, try it for yourself.

 

 

Havent tried it myself. I tried his answer and it works great. I didnt shift the origin of the brick to its center cause I have no idea what he meants. I was thinking like texture.width/2 and texture.height / 2. Thats how I can move it to center. But it works fine on top-left for me, for now..

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!