开发者

iPhone Cocos2D CCColorLayers

开发者 https://www.devze.com 2023-01-09 17:10 出处:网络
I am currently building a simple game in cocos2d. I wish to have a CCColorLayer which has atransparent background, but has visible children CCSprites.

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 T开发者_如何学JAVAhanks,

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号