Sign in to follow this  

Scaling sprites

This topic is 4529 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'm working through the obligitory tetris, breakout, and pong style games, and wondering about scaling images when resolutions change. For example, if I'm using 64x64 blocks in 1024x768 mode, I may want to use only 32x32 blocks in 800x600 mode. Of course I can alter this with a transform matrix and a call to the sprite interface's setTransform method, but I was wondering if there was another (possibly more elegant and/or efficient) way to do these scalings based on screen resolution? Thanks for any input, Antrim

Share this post


Link to post
Share on other sites
To make resolution-independent sprites, I use a "virtual screen size" which I pass into the D3DXMatrixOrthoOffCenterLH() function. For example, say my "virtual" screen is 800x600. I'll pass this to the ortho function:

D3DXMatrixOrthoOffCenterLH(&matProj,0,800,0,600,zNear,zFar);

Then I set the viewport to cover the entire screen. This way, no matter what resolution I'm using, and no matter what size viewport I use, the sprites will still use an 800x600 grid for placement and such. They'll be scaled to match the screen as well. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Drakex
To make resolution-independent sprites, I use a "virtual screen size" which I pass into the D3DXMatrixOrthoOffCenterLH() function. For example, say my "virtual" screen is 800x600. I'll pass this to the ortho function:

D3DXMatrixOrthoOffCenterLH(&matProj,0,800,0,600,zNear,zFar);

Then I set the viewport to cover the entire screen. This way, no matter what resolution I'm using, and no matter what size viewport I use, the sprites will still use an 800x600 grid for placement and such. They'll be scaled to match the screen as well. :)



This is definitely the way to do it -- set up a virtual resolution that you're comfortable with and then design the entire game around that resolution. If the ACTUAL resolution is, say, 1.5 times greater than your virtual resolution, then multiply every coordinate, vertex, etc. by 1.5.

Share this post


Link to post
Share on other sites
Maybe I'm misunderstanding something, but it seems like both solutions are different.

From what I'm gathering, I can create the whole game with my virtual resolution, and then have it resized.

Where I'm a bit confused is at the resizing...it seems like Drakex is saying that by setting the actual viewport to the user desired resolution and using the virtual resolution that I created, the sprites will be automatically resized. From what MasterWorks is saying though, it seems like I need to do a lot more calculating as to the ratio of the users desired size to my virtual size and perform quite a few adjustments to get the proper scaling done.

Maybe you are both saying the same thing and I'm misunderstanding one of you...or maybe they are just 2 different solutions.

Thanks for the info, and any clarification you can give

Antrim

Share this post


Link to post
Share on other sites
It seems like MasterWorks is thinking of something else, as well. Using my method, all coordinates remain the same - so if your game is running at 2048x1536, and you use a virtual resolution of 1024x768, placing a sprite at 512,384 will place it in the middle of the screen.

Share this post


Link to post
Share on other sites
Quote:
Original post by Drakex
It seems like MasterWorks is thinking of something else, as well. Using my method, all coordinates remain the same - so if your game is running at 2048x1536, and you use a virtual resolution of 1024x768, placing a sprite at 512,384 will place it in the middle of the screen.


That is the same thing I was saying. I used transformed/lit vertices for 2D stuff, so the multiplication is the VERY LAST step, one that only your render class or whatever will care about. Coordinates throughout the game engine, in data files, etc. should all be relative to your virtual resolution. Converting from the virtual resolution to the actual resolution is the very last step before something appears onscreen, if you aren't doing it the '3d way'.

Share this post


Link to post
Share on other sites
Are you manually transforming the vertices and multiplying the coordinates? I'm not sure if that's where we're differing. I just use the projection matrix.

Share this post


Link to post
Share on other sites
Quote:
Original post by Drakex
Are you manually transforming the vertices and multiplying the coordinates? I'm not sure if that's where we're differing. I just use the projection matrix.


Not manually transforming AND multiplying, just manually multiplying. :) Can you use a projection matrix to do this even when using T&L vertices? Either way, our solution is the same... another thing is be sure to use floats/singles/etc and not integers for your coordinates.

Share this post


Link to post
Share on other sites

This topic is 4529 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this