Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Loss of resolution on sprites

Author
Message
Qoheleth
12
Years of Service
User Offline
Joined: 11th Jun 2011
Location:
Posted: 7th May 2013 12:47
Why do I lose resolution on a sprite when I scale it (making it smaller), and how can I avoid the loss?
I load an image and use it to create the sprite. At this stage, the resolution (quality) still seems fine. But the moment I scale it down to fit on the screen, I lose quality and it becomes blurry.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 7th May 2013 13:04
It depends on what language your using, but they tend to have something called min and mag filters, for scaling the image up or down. If you scale down, you might want a different style to when you scale up. Like, if you want a zoomed in view to be pixelated, but zoomed out you might prefer to have it soften the pixels to reduce the jaggies and flicker that often comes with image scaling.

In AppGameKit, you would use:
SetImageMinFilter(img,0)
SetImageMagFilter(img,0)

In DBPro, you would use:
Set object filter obj,0
or
Set sprite spr,0,1

I think - can't be 100% sure - but you will find a way to change the filter mode in most languages.

One thing to keep in mind, is that it can be really difficult for 2D images to rotate neatly at native resolution. What I mean is, if you have a sprite and are rotating it and scaling it even - because it's the same resolution as the screen, pixels can take on an almost binary behavior - like either visible or not, because it can't interpolate between pixels.
To counter-act this, I would draw at double the resolution I need. It would allow for much neater rotation and scaling, because the rendered pixels have more data to go by - so edges that might be jagged at native resolution might have 3 more pixels to calculate, and provide a much nicer result, less jarring differences between small rotations etc.

I guess, what I'm really saying is that if you want to scale your image by half and not loose half the quality... draw it at double the resolution you'll be displaying it at usually

I got a fever, and the only prescription, is more memes.
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th May 2013 13:08 Edited at: 7th May 2013 13:10
What language, DB? AKG? GDK? Are you resizing the image or the sprite?

Sounds like the filtering method used for the resizing. You can try setting the texture flag when you load the image and see if that makes a difference. Set it to 1.


Van beat me while I was writing.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Qoheleth
12
Years of Service
User Offline
Joined: 11th Jun 2011
Location:
Posted: 7th May 2013 14:12
Thanks for the answers so far. I still have to test the suggestions.
I am using DB Pro. I am scaling the sprite, not the image, because I do not know how to scale an image (nothing about that in the help file). If it is possible to scale an image, please tell me how as I would prefer to do that.
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th May 2013 14:26
I suggested the image before I knew which language, so it was just a guess.

How much are you trying to scale the sprite?

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Qoheleth
12
Years of Service
User Offline
Joined: 11th Jun 2011
Location:
Posted: 7th May 2013 18:14
Quote: "How much are you trying to scale the sprite?
"


It depends on the size of the original image. I want to be able to use different images supplied by the user and then scale them down to fit on the screen (the display is set to 1024x768), but usually it probably will be around 30%.
Qoheleth
12
Years of Service
User Offline
Joined: 11th Jun 2011
Location:
Posted: 7th May 2013 22:36
@ Van B
Quote: "I guess, what I'm really saying is that if you want to scale your image by half and not loose half the quality... draw it at double the resolution you'll be displaying it at usually"


What you say makes sense, but I can't think of a way to draw the sprite at double the resolution in DB Pro while keeping it the same size. Will you please explain?
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th May 2013 11:20
Well if you have a sprite that you want to display at a size of 64x64, draw it at 128x128 in your art package, then set the sprite size to 64x64 in DBPro. So that sprite will be at double the resolution, but it can also scale up to twice the size without looking bad, and it can rotate much smoother than a 64x64 image. Remember your not doubling the output quality by doubling the resolution, your quadrupling it! - those extra 3 pixels can make a lot of difference.

I'm not sure what graphical style your going for, but often you can just scale your sprite up in an art package and spend a few minutes tidying it up - like fixing lines so they are smoother at the new resolution. I find it's always best to draw at double or quadruple the resolution you need, because you can always go back if you need to and get higher resolution versions.

For example, my iOS game was started a long time ago, when the iPod Touch 2nd Gen was just out with a 480x320 screen - by the time I release it, the standard is 2048x1536 - any graphics I did at the native resolution would look terrible at the new resolution. I was glad I had higher res versions of everything.

I got a fever, and the only prescription, is more memes.
Qoheleth
12
Years of Service
User Offline
Joined: 11th Jun 2011
Location:
Posted: 8th May 2013 13:59
@ Van B
Yes, I see what you mean with the higher resolution. But...
In my test runs, I used a jpeg image with 2480x3508 resolution. The original's quality is good and clear. I then use it to create a sprite, which I scale to fit my display. So, it becomes 542x768 - that is 21.89%. And then it looks terrible.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th May 2013 14:46
Ahh, I wonder if it's the unusual resolution that's causing problems as well. Typically power of 2 sizes work best, in fact some engines don't even support non power-2 sizes. Try and stick to sizes like 128x128, 256x256, 512x512, 1024x1024 etc etc - even if that means you have blank areas in your image - they'd be compressed to practically nothing anyway, so it's not like they will take up too much space. Like for a 542x768 sprite, I'd use 1536x1536 and scale to 768x768, and then just offset the sprite position so it shows the area you need it to.

I got a fever, and the only prescription, is more memes.
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th May 2013 23:16
Keep in mind that's also a massive reduction in size and you're going to lose a lot of data in the image.

If the system doesn't like image dimensions that aren't a power of 2 (which is completely possible), you could make a memblock from the image and resize it with your own method manually if you don't plan on resizing the image constantly.

I've resized images using sprites before in DB and I didn't have any problems:
http://forum.thegamecreators.com/?m=forum_view&t=182948&b=8

"You're all wrong. You're all idiots." ~Fluffy Rabbit

Login to post a reply

Server time is: 2024-03-02 07:12:43
Your offset time is: 2024-03-02 07:12:43