Hello,
I am currently building a simple game in cocos2d. I wish to have a CCColorLayer
which has a transparent background, but has visible children CCSprites
.
Is this possible, and if so how?
Many Thanks,
nonono
Hello,
I am currently building a simple game in cocos2d. I wish to have a CCColorLayer
which has a transparent background, but has visible children CCSprites
.
Is this possible, and if so how?
Many Thanks,
nonono
Yes of course. You create your scene + layer as usual, and add a CCColorLayer to the layer like any other node. Just make sure it is in the very background:
// This adds a solid color background.
CCColorLayer* colorLayer = [CCColorLayer layerWithColor:ccc4(255, 0, 255, 255)];
[self addChild:colorLayer z:-1];
Then you can add a regular 480x320 size image as background to your layer above the colorlayer. If the background image is transparent, then all transparent parts will show the color of the CCColorLayer.
Note: if you don't use transitions (especially fade transitions, the GL color will interfere with the fade color) you can also change the background color using OpenGL. Add this to your scene's or layer's init method:
glClearColor(1, 0, 1, 1);