【问题标题】:Cocos2D - remove layer opacity on regionCocos2D - 删除区域上的图层不透明度
【发布时间】:2012-09-18 23:57:06
【问题描述】:

我得到了一个带有顶部 z-index 图层的场景,它为整个场景添加了暗色效果,设置了它的不透明度。我现在要做的是去除图像显示的混凝土区域(圆锥体/三角形内)中的阴影/黑暗效果(红色多边形内)。换句话说,我希望三角形内的“亮度”(不透明度为零)与屏幕左侧相同。

代码:

-(id) init
{
if( (self=[super initWithColor:ccc4(0,0,0,128)] )) {
    CGSize winSize = [[CCDirector sharedDirector] winSize];

    CCLayerColor* layer1 = [CCLayerColor layerWithColor: ccc4(0, 0, 0, 180) width: winSize.width height: winSize.height];
    layer1.position = ccp(50,0);
    [self addChild: layer1 z:2];

    CCSprite *background = [CCSprite spriteWithFile:@"background.png"];
    background.position = ccp(background.contentSize.width/2, background.contentSize.height/2);
    [self addChild:background];

    CCSprite *player = [CCSprite spriteWithFile:@"Player.png"rect:CGRectMake(0, 0, 27, 40)];
    player.position = ccp(player.contentSize.width/2, winSize.height/2);
    [self addChild:player];     
}
return self;
}

关于如何做到这一点的任何想法?也许我应该尝试另一种方式而不是使用 CCLayer 来添加黑暗效果??

提前致谢

【问题讨论】:

    标签: cocos2d-iphone opacity layer region cut


    【解决方案1】:

    最简单的方法是使用带有背景大小的黑色图像的 CCSprite。然后在图像程序中剪下您需要的整体,并在背景上绘制该精灵并降低不透明度。

    【讨论】:

    • 这个想法是模拟一盏灯的光,因此将使用代码和坐标创建切割三角形以将效果放置在场景中,所以据我所知,您的想法是用切割区域静态。也许通过某种渲染这是可能的??
    猜你喜欢
    • 2012-06-08
    • 1970-01-01
    • 2013-04-28
    • 1970-01-01
    • 2011-04-22
    • 2017-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多