Stretching sprite from sprite sheet renders badly

Stretching sprite from sprite sheet renders badly
0.0 0


Hi everyone,
I just finished migrating my game from Cocos2d-x 2 to 3.0rc. I love the new version. Much more C+±ish. Thanks!
I had a problem while using v2 which I was hoping would be resolved in v3. Unfortunately it didn’t.
I’m trying to build an object that will be composed of 3 image: left and right are fixed sizes, and center is resized based on the desired object size. This worked flawlessly for a while, when I was using separate image files for each of them (left.png, right.png, center.png). Later on, when I switched to spritesheets (sprite frames? not sure what’s the right term) the center image started misbehaving.
The edges of the center frame are becoming transparent as I stretch it wider. I don’t know why, but I really need to resolve this.

I uploaded an illustration image. I’d really appreciate any tip here!

cocos-image.png (41.5 KB)


2 things to try,

  • set the texture parameter
  • increase the size of the middle texture

This happens because while you are defining the rect on the sprite sheet by Pixels, in OpenGL, it defines the texture coordinate from 0.0 to 1.0, therefore, it is impossible for that rect to match pixel perfectly.

setting it to nearest might solve the issue, as nearest does not try to blend the colors between pixels


Thanks Wuhao!
using the setTexParameters() method solved my issue. I couldn’t find sufficient documentation for the possible parameters available here. Do you happen to know where I could learn more about this?
Thanks again!