Search code examples
c++cocos2d-xcocos2d-x-2.x

CCLayerGradient is not fading colors smoothly. How to make it smooth?


Here is the link where it teaches how to create a gradient layer: http://www.pawapps.com/2011/09/01/quick-code-cclayercolor-and-cclayergradient/

As you can see the gradient in not smooth. You can see stripes of colors. Even the author mentions it:

"So the above gives a nice but not very smooth fade from one color (in this case black) to another color (in this case white) along a particular vector."

Here is how bad it looks:

ugly stripes of gradient

How to achieve smooth gradient? I use cocos2d-x 2.2.5.


Solution

  • This is normal in the Simulator, it only renders with 16-bit color depth. It should look good on a device even though it also defaults to a 16-bit framebuffer. I think that's due to display size and quality, specifically due to higher ppi (pixels per inch).

    If it does look undesirable on the device you can increase framebuffer color bit depth to 32-bit at the expense of rendering performance (usually a bad tradeoff on mobile devices).