• Bugs
  • cocos-2d gray border on texture

I use cocos-2d as my runtime engine, somehow there are gray border on textures. The same atlas works fine with libgdx. (Which means clear edge with textures.)

I'd read lots of posts similar with my problem, I think it's may related to the premultiplied-alpha setting.
So I had check my .png file is exported with premultiply-alpha option checked. Any one can help? 😢

  • libgdx (perfect!!!)
  • cocos-2d :tear:
Related Discussions
...
  • Изменено

Are you using spine-cocos2dx or spine-cocos2d-obj?

In cocos2dx you need to tell the scene graph node that it is using PMA:
https://github.com/EsotericSoftware/spine-runtimes/blob/3.8/spine-cocos2dx/src/spine/SkeletonRenderer.cpp#L879
Though that is the default:
https://github.com/EsotericSoftware/spine-runtimes/blob/3.8/spine-cocos2dx/src/spine/SkeletonRenderer.cpp#L93
You might check that is set correctly.

Some toolchains, like Xcode, apply PMA unless that is explicitly disabled. If PMA is applied twice, it will wreck your images. In that case, you can either figure out how to stop Xcode from wrecking the images, or don't use PMA on your atlas and let Xcode do it.

Thank you for your reply.

I'm using spine-cocos2d-obj. But I had tried to run the same atlas with spine-cocos2dx then still had the edges. 😢
I do use Xcode as compile tool, but I tried to disable premultipliedAlpha to the scene graph (I thought this could avoid applying twice PMA) and got the same result.

I wonder how can I disable premultipliedAlpha programely so that I can use the same atlas resource with android. For now iOS and Android have contrary result with the same exported atlas.

If you are using Xcode it's almost certainly the problem that Xcode applies PMA. This page looks like it shows the setting you need to change:
https://imageoptim.com/xcode.html

I tried, but still not working at all 🙁

  1. 1. I disabled COMPRESS_PNG_FILES flag in Xcode

    1. I set CC_ENABLE_PREMULTIPLIED_ALPHA to FALSE in cocos2d-x
    2. I also set Image::setPNGPremultipliedAlphaEnabled(false) in cocos2d-x
    3. Left OpacityModifyRGB to be TRUE with SkeletonRenderer

What I want was keep the .png file to be as the original (PMA) image data then let renderer to blend the color, but failed again...

Cocos2d-x performs a PMA conversion itself when loading images. Simply export your texture atlas without PMA.

I know, but Android needs image resource with PMA. We don't want to export the image resource twice.

(Though we do now :rofl:

The Android backend of cocos2d-x is supposed to PMA images as well. If the version you are using does not do that, that's a bug in cocos2d-x which should be reported.

Our Android team use libgdx as runtime engine. :wounded:

Oh. I'm afraid that you'll have to export the atlas twice, once for each platform, then, as we can't change the PMA behaviour in cocos2d-x ourselves.

Though there is no solution now, however, really grateful to Mario and Nate for replay.
Besides, I found there is a way to disable PMA when read png with cocos2d-x.

Image::setPNGPremultipliedAlphaEnabled(false);

and keep

CC_ENABLE_PREMULTIPLIED_ALPHA = 1

This code can do perfectly to premultiplied-alpha files, but with cocos2d-objc, I still cannot fix the border.
But I found there are some discussion about how to load image without premultiply, they used libpng to load image instead of using cgimage. (Cocos2d-x uses this library to load image as well.)

Anyway, there is no solution for now with cocos2d-objc. I will reply on this post if I find any way to solve this issue.