Strange scaling issue

Strange scaling issue
0.0 0

#1

I have a strange issue which relates to scaling. I am really confused and would really hope someone can shed some light on this one.

I have this asset which is a 256x256 image.
temp

When I scale it down via any graphics editor I am getting this. (Scaled it down to 200x200 image)
200

As you can see it is perfectly scaled.

however this is how it looks when I scaled it down using cocos2dx
bad

Notice how it looks ugly now. completely different then what you have seen. btw I have used windows paint to scaled down , so this is no photoshop or complicated graphical tools.

Any idea ?


#2

It’s down to the interpolation. The badly scaled image looks like nearest neighbour to me. If you’re using the default shaders, then you’ve got the choice of nearest neighbour and linear interpolation. You can set the interpolation for a texture with something like:

auto sprite = Sprite::create(...);
auto tex = sprite->getTexture();
tex->setAntiAliasTexParameters(); // Anti-alias -- linear filter
// tex->setAliasTexParameters(); // Alias -- nearest neighbour filter

If you want something else, like bi-cubic, you’d have to write a custom shader. I had a play around, and didn’t find bi-cubic to look any better than linear. In this example, the upper row is scaled down, and the lower row is scaled up.

57


#3

After further investigation, this is because OP is using TMXLayer which sets nearest neighbour by default.

From the source of setupTiles in CCTMXLayer.cpp:

// By default all the tiles are aliased
// pros:
//  - easier to render
// cons:
//  - difficult to scale / rotate / etc.
_textureAtlas->getTexture()->setAliasTexParameters();