Saturn
Saturn

Reputation: 18159

Sprite scaling issue

I got a CCSprite.

I scale it to 1.89, and it seems I need a bit more to get my desired result. Therefore I scale it to 1.9 (0.01 more than before). How come that now the sprite is much bigger by far now?

In fact, I tried to add some precision (I make it like 1.895 or something, but the difference is minimal or even inexistent).

Upvotes: 1

Views: 212

Answers (1)

CodeSmile
CodeSmile

Reputation: 64477

To avoid any external influences you should run a test with a new project with two images side by side using slightly different scale factors.

You should also know that eventually the sprite's texture pixels need to be mapped to the screen pixels which can lead to reduced precision of scaling. If you have a texture that is 10x10 pixels in size it will occupy 10x10 pixels on the screen with scale factor 1.0. That texture will only increase to 11x11 pixels when you use a scale factor of 1.05 or higher. It is likely that the texture's size on screen remains unchanged with scale factors ranging from 0.95 through 1.04.

Depending on rounding algorithm and subpixel rendering the end result can slightly differ. But it explains the basic principle that ultimately you can't scale a texture with infinite precision because eventually one pixel is either displaying a texture pixel (texel), or it isn't.

Turning off subpixel rendering in ccConfig.h may lead to better results.

Upvotes: 1

Related Questions