DrawNode setOpacity doesn't work

DrawNode setOpacity doesn't work
0.0 0

#1

I have this

this->mDrawNode =DrawNode::create();
this->mDrawNode->retain();
this->mNode->addChild(this->mDrawNode,0,MAP_DRAWNODE_TAG);

this->mDrawNode->drawSegment(Vec2(p1.x,p1.y), Vec2(p2.x,p2.y), 3, this->mDrawNodeColor);

… blablabla

-> all is ok color… opacity (1 in this case)… segment

void CEffect::Update(float dt)
{

this->mDrawNode->setOpacity(128); // opacity doesn’t change

}
i tried
this->mNode->setCascadeOpacityEnabled(true);
this->mDrawNode->setCascadeOpacityEnabled(true);
-> it changes nothing

Impossible to make a fade effect on my drawing node…
What I’m missing?

Any idea?


#2

please help :slight_smile:


#3

Please Reply, I’m wasting a lot of time on something who is perhaps “normal”
Can we change the color or a opacity of a drawing node in a the update with a different value of its parent? In my case it doesn’t work, so what I missing?

Sorry for my poor english.


#4

It looks the same problem I Have


#5

Hello @fabrice, i have a solution, look my code

rectWithBorder = DrawNode::create();
    Vec2 vertices[] =
    {
        Vec2(origin.x,origin.y),
        Vec2(origin.x,visibleSize.height),
        Vec2((origin.x - visibleSize.width/2),visibleSize.height),
        Vec2((origin.x - visibleSize.width/2),origin.y)
    };
    rectWithBorder->drawPolygon(vertices, 4,Color4F(0.2f,0.2f,0.2f,0.5), 0, Color4F(0.2f,0.2f,0.2f,1));
    this->addChild(rectWithBorder,7);

Especially this line
rectWithBorder->drawPolygon(vertices, 4,Color4F(0.2f,0.2f,0.2f,0.5), 0, Color4F(0.2f,0.2f,0.2f,1));

for Color4F(r,g,b,a), i put 0.5 to get alpha opacity and its working, i hope this work for you (sorry for my bad english)


#6

It should be fixed with https://github.com/cocos2d/cocos2d-x/pull/17248


#7

At what version of the engine It should work?
I tested with 3-13 and it doesen’t work…


#8

3.15 supposedly. https://github.com/cocos2d/cocos2d-x/blob/v3/CHANGELOG line 43 at this point in time.


#9

Cool! Thanks! A will use it soon =)