-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the UIOpacity issue when the node is re-added to the scene. #17700
Conversation
fix the render.node._uiProps.localOpacity only update on native.
Interface Check ReportThis pull request does not change any public interfaces ! |
@yoki0805 thanks for the PR. As v3.8.4 is releasing, so i can't merge it to v3.8.4. |
When v3.8.4 is released, could this issue be included in the known issues list? |
It may be released tomorrow. I will add it to known list in release note if we have. |
@yoki0805 Sorry I clicked wrong. My suggestion is to add the judgment in _parentChanged.
The setEntityLocalOpacityDirtyRecursively function should not work on web platforms! |
The setEntityLocalOpacityDirtyRecursively function should not work on web platform.
Whenever the node is re-added to the scene, the _parentOpacity value needs to be updated again in the onEnable callback.
|
cocos/2d/components/ui-opacity.ts
Outdated
@@ -152,7 +154,9 @@ export class UIOpacity extends Component { | |||
// there is a just UIRenderer but no UIOpacity on the node, we should just transport the parentOpacity to the node. | |||
render.renderEntity.localOpacity = parentOpacity; | |||
} | |||
render.node._uiProps.localOpacity = render.renderEntity.localOpacity; | |||
if (JSB) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be possible to remove it here? @yoki0805
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got what you mean.
UIOpacity.setEntityLocalOpacityDirtyRecursively is only called on native platform.
I will remove the JSB checking here, thank you.
@@ -222,6 +231,10 @@ export class UIOpacity extends Component { | |||
} | |||
|
|||
public onEnable (): void { | |||
if (this._parentOpacityResetFlag) { | |||
this._parentChanged(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is recommended to change it to something like the following
this.node.on(NodeEventType.PARENT_CHANGED, this._parentChanged, this);
if (this._parentOpacityResetFlag) {
this._parentChanged();
this._parentOpacityResetFlag = false;
} else {
this.node._uiProps.localOpacity = this._parentOpacity * this._opacity / 255;
this._setEntityLocalOpacityRecursively(this.node._uiProps.localOpacity);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public onEnable (): void {
this.node.on(NodeEventType.PARENT_CHANGED, this._parentChanged, this);
if (this._parentOpacityResetFlag) {
this._parentChanged();
this._parentOpacityResetFlag = false;
} else {
this.node._uiProps.localOpacity = this._parentOpacity * this._opacity / 255;
this._setEntityLocalOpacityRecursively(this.node._uiProps.localOpacity);
}
}
I changed to that, and I got the different results in test demo.
on web platform:
The result on native platform is right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, should also need to set this.node._uiProps.localOpacity.
public onEnable (): void {
this.node.on(NodeEventType.PARENT_CHANGED, this._parentChanged, this);
this.node._uiProps.localOpacity = this._parentOpacity * this._opacity / 255;
if (this._parentOpacityResetFlag) {
this._parentChanged();
this._parentOpacityResetFlag = false;
} else {
this._setEntityLocalOpacityRecursively(this.node._uiProps.localOpacity);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good in test demo, thanks!
@qiuguohua please update release note. |
issue:
https://forum.cocos.org/t/topic/159379/745
if (JSB) { render.node._uiProps.localOpacity = render.renderEntity.localOpacity; }
'render.node._uiProps.localOpacity' still needs to be updated on native for fix another issue.
#17503
If possible, it would be great to have this fix synced to v3.8.4 as well.
@minggo
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: