Jump to content
  • Advertisement
Sign in to follow this  
idlewire

newbie question about sprites and screen resolution

This topic is 4234 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

Hi, I'm experimenting with a 2d game. I have sprites that are 128x128. At my resolution they take up about 10% of the screen width. If I want to support different resolutions, what's the best way to go about it? I don't want my sprite to take up 20% of screen width if someone is running at 640x480... Right now, I'm calling D3DXMatrixTransformation2D with a scaling factor to take into account different resolutions. This is followed by SetTransform. Is this the best way to do it? And then anything in the game that cares about screen position also has to be multiplied by this factor. Is that correct? Because everything seems to be tied to absolute pixel units... Also, a related question: how "expensive" is this call to D3DXMatrixTransformation2D? I want to support rotation of sprites in the game, but that means I have to call this for each individual sprite. And it seems like I have to do this even if the rotation factor is the same, since this function takes "rotation center" into account which seems to be completely dependent on the sprites position. That means I wouldn't be able to pre-compute typical rotations that might take place. Any feedback/help is appreciated! Thanks!

Share this post


Link to post
Share on other sites
Advertisement
It will probably be negligible compared to the time needed to actually blit the sprite.

"Best way" is subjective. At low resolutions, scaling might not be ideal if only because of the graphical artifacts that are introduced (anti-aliasing and resampling for scaling might turn your 16x16 HUD icon into a very muddy-looking 24x24 icon that you'd be better off redrawing).

Share this post


Link to post
Share on other sites

Hi, when I use D3DMatrixTransformation2D and put in a scaling factor of (0.8f, 0.8f), for example, it is cutting down my frame-rate.

The thing is, I am just using this scaling to deal with different resolutions.


In other words, my sprites at their native scale are meant to fit 10 across on a screen width of 1280. So if someone is running at 1024, and I want them to take up just as much screen space, I have to scale them by 80%.

Is there a way to only do this *once*? I don't want/need to keep scaling them before every Draw. I would just like to scale them when I load in the textures the first time, or somewhere else but only once.

How should I go about doing this?

Or should I just make textures for all the different resolutions I want to support??

Share this post


Link to post
Share on other sites
Scale them and draw to some kind of offscreen buffer instead of the screen (i.e. create another, blank texture of the desired destination size, and cause the scaled original texture to be blitted onto the blank one). Then you can freely use the second buffer in place of the first, to get the scaled versions. Be sure to account for the new texture size (if texture coordinates are in pixels; if they're percentages, i.e. relative to the image size, then there should be no problem). Also be sure to deallocate the first texture once you have the second one prepared (unless you'll need it for something else).

I don't know any D3D stuff so I can't give you specifics, sorry.

Share this post


Link to post
Share on other sites
I went ahead and implemented that. Interestingly, it didn't provide any performance gains. Maybe it has to do with blitting certain sizes of things? I notice when I tweak the scaling factor that there are certain factors that cause a drop in the frame rate, namely between 0.60 and 0.85. Literally when I go from using 0.85 to using 0.86, my frame rate goes from 45 to 60 (refresh rate).

Is there something about the dimensions of textures or something that causes this? Any good way to avoid this?


While I'm here, what is the best way to have a static background behind my sprites? I have a 1024x1024 texture but it is causing a drop in the frame rate. I broke it up into 16 pieces of 256x256 and that is better. But it seems a lot of trouble and a waste to render this every frame when the background is never going to change. Is there a better way?

Also do you know a good program (or a way in photoshop) to break up a larger image into equal-sized pieces?


Thanks for all the help!

Share this post


Link to post
Share on other sites
Quote:
Original post by idlewire
While I'm here, what is the best way to have a static background behind my sprites? I have a 1024x1024 texture but it is causing a drop in the frame rate. I broke it up into 16 pieces of 256x256 and that is better. But it seems a lot of trouble and a waste to render this every frame when the background is never going to change. Is there a better way?


I don't know why the larger texture would cause a frame rate drop; usually single images perform better (because there are fewer calls to the drawing API, which often has expensive setup/teardown compared to the actual blitting work).

Any chance we could see the code?

Quote:
Also do you know a good program (or a way in photoshop) to break up a larger image into equal-sized pieces?


No, but it shouldn't be hard to do yourself if your Google-fu should fail you. You already can load an image onto a texture and draw subregions of a texture onto another texture, right? So all you need now is to be able to save a texture to an image file, and you should be able to figure out the rest. :)

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!