iPhone Cocos2D CCColorLayers

发布于 2024-09-11 16:28:44 字数 153 浏览 2 评论 0原文

我目前正在 cocos2d 中构建一个简单的游戏。我希望有一个具有透明背景的CCColorLayer,但具有可见的子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 Thanks,

nonono

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北陌 2024-09-18 16:28:44

是的当然。您像往常一样创建场景 + 图层,然后像任何其他节点一样将 CCColorLayer 添加到图层。只需确保它位于背景中即可:

// This adds a solid color background.
CCColorLayer* colorLayer = [CCColorLayer layerWithColor:ccc4(255, 0, 255, 255)];
[self addChild:colorLayer z:-1];

然后您可以将常规 480x320 大小的图像作为背景添加到 colorlayer 上方的图层中。如果背景图像是透明的,那么所有透明部分都会显示CCColorLayer的颜色。

注意:如果您不使用过渡(尤其是淡入淡出过渡,GL 颜色会干扰淡入淡出颜色),您还可以使用 OpenGL 更改背景颜色。将其添加到场景或图层的 init 方法中:

glClearColor(1, 0, 1, 1);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文