Sign in to follow this  

Maths question

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

Question for you maths experts: I had a sprite sheet of 52 cards. It was bigger than I needed so I shrunk it by 75% more or less. That was all good except I forgot it would mess up the size of my individual sprite cards. Now each card (sprite) is 88.888888889 wide by 122.33333333 height. My graphics engine will only take a float value for width, height.. So I thought simplest solution is resize my total sprite sheet till each sprite is a whole number again. I just wondered if there is some formula I can use to work out what percentage to multiply by so that BOTH height and width are whole numbers again but still close as possible to their present size. Original size of each card was 189 by 260. Sprite sheet is 9 frames long by 6 high. Does that make any sense? m0ng00se

Share this post


Link to post
Share on other sites
The GCD of 189 and 260 is 1. This means that they share no common factors, so there is no single percentage that you can multiply each by to get a whole number for both.

Share this post


Link to post
Share on other sites
Why use such arbitrary numbers in the first place? They only cause headaches. Most game graphics come in a power-of-two or some nice factor/multiple thereof.

Choose image sizes that are convenient for you, not some willy-nilly 75% of 189 pixels or something equally foolish and useless. For your example, I'd take the original-sized images (or higher resolution source images, if you have them) and resize them to 96x128; its just barely bigger than what you've got, and those numbers are much nicer to work with.

If its an issue of the resources taking too much RAM at the original size, rather than their dimensions, you could just create a texture of the glyphs on the card, and then model each card as a composition of glyphs -- The heart always looks the same, whether there's 3 or 7 of them, the numerals all look the same, but may be colored differently. This could all be done programatically, and would probably reduce your texture requirements by 75%.

Share this post


Link to post
Share on other sites
As SiCrane mentioned, there is no set of dimensions which will solve your resizing problem precisely because the two numbers have no common denominator, so your best bet is to find a pair of numbers that come extremely close.

The best method with which to accomplish this would probably be trial and error; 96x128 is great, because only stretches the cards by about 3%, which would probably be an imperceptible distortion.

If you find yourself noticing the stretching, then you could experiment with different sizes until you find one that suits your purposes. For example, 96x132 would produce a nearly undistorted image, but at the price of giving up 128, which is usually a very easy number to deal with.

There's no one solution to this problem; just consider the options you have, and pick whichever one suits you.

Share this post


Link to post
Share on other sites
Thanx guys.

Yes I realise the cards were a stupid size to start with but I was kindly given the *.png card graphics already done. I also agree that power of two would be preferable so I can animate the whole sprite sheet if I want.

I was just trying to work with them as they were given to me. It is correct that unfortunately the GCD is one so I'm stufed unless I re-size the original cards as I should have done in the first place.

I rushed into getting them up on screen and rashly posted my question without properly thinking about it. I'm always looking for the highest resolution so I didn't want to resize the cards more one way than the other which would of course cause some distortion.

Thinking aout it though I can change the background of the sprite sheet to match the animation screen background or set a transparent (alpha?) channel and then make each sprite frame any size I like without affecting the cards.

Sorry for asking such a stupid question. I don't know what I was thinking.

m0ng00se

Share this post


Link to post
Share on other sites

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