If the clipping stencil node has any child, it turns white. #1521
Replies: 5 comments 8 replies
-
Can you please show example images of what you actually see, and what you expect to see (even if you create them in a paint program). Having something like that makes things very clear, without having to guess what you actually expect. Also, check the clipping tests in the cpp-tests project. They all seem to work, so check what is different about your code to the test implementations. |
Beta Was this translation helpful? Give feedback.
-
I have added a sprite as child of the clipping stencil sprite. It turns the node white. I have added these lines of code `void NestedTest::setup()
}` Simulator.Screen.Recording.-.iPhone.SE.3rd.generation.-.2023-12-18.at.11.10.38.mp4 |
Beta Was this translation helpful? Give feedback.
-
It was working fine on cocos-2dx-v3. |
Beta Was this translation helpful? Give feedback.
-
@iAbdulQadirKhan What is the purpose of adding a child sprite to the stencil? Understanding the use-case for this may make things clearer. Also, why is the stencil sprite being added as a child of the clipping node? Wouldn't it have made more sense to create a separate sprite for that purpose, given that the stencil is modified by the clipping node? For example, this code results in the expected output, even with the line static int depth = 9;
Node* parent = this;
for (int i = 0; i < depth; i++)
{
int size = 225 - i * (225 / (depth * 2));
auto clipper = ClippingNode::create();
clipper->setContentSize(Size(size, size));
clipper->setAnchorPoint(Vec2(0.5f, 0.5f));
clipper->setPosition(parent->getContentSize().width / 2, parent->getContentSize().height / 2);
clipper->setAlphaThreshold(0.05f);
clipper->runAction(RepeatForever::create(RotateBy::create(i % 3 ? 1.33f : 1.66f, i % 2 ? 90.0f : -90.0f)));
parent->addChild(clipper);
auto stencil = Sprite::create("grossini.png");
stencil->setScale(2.5f - (i * (2.5f / depth)));
stencil->setAnchorPoint(Vec2(0.5f, 0.5f));
stencil->setPosition(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2);
clipper->setStencil(stencil);
auto clippedSprite = Sprite::create("grossini.png");
clippedSprite->addChild(Sprite::create()); // You can still add a blank sprite here if you need it
clippedSprite->setScale(2.5f - (i * (2.5f / depth)));
clippedSprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
clippedSprite->setPosition(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2);
clippedSprite->setVisible(false);
clippedSprite->runAction(Sequence::createWithTwoActions(DelayTime::create(i), Show::create()));
clipper->addChild(clippedSprite);
parent = clipper;
} Note that the above code is running in a new project, with the relevant graphic assets added to the project, and not just modified code in the cpp-test project. |
Beta Was this translation helpful? Give feedback.
-
We are not applying shaders to the children of the stencil. This solution is working.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
We have a background sprite and it has a sprite child. I set the clipping stencil to the background sprite. This turns the node white. This problem can also be reproduced on cpp test project. I have added this line of code
stencil->addChild(Sprite::create());
`void NestedTest::setup()
{
static int depth = 9;
}`
Beta Was this translation helpful? Give feedback.
All reactions