完善圆角裁剪

This commit is contained in:
caizhitao
2020-01-09 10:01:28 +08:00
parent 9e3ca8fce6
commit 7380cf3292
7 changed files with 213 additions and 89 deletions

View File

@@ -8,6 +8,9 @@ export default class RoundCornerCropEffectScene extends cc.Component {
private _examplesParentNode: cc.Node = null;
onLoad() {
// 关闭动态合图
cc.dynamicAtlasManager.enabled = false;
this._roundCornerRadiuSlider = cc.find("Canvas/Content/Sliders/RoundCornerRadiusSlider/Slider").getComponent(cc.Slider);
this._roundCornerRadiuLabel = cc.find("Canvas/Content/Sliders/RoundCornerRadiusSlider/ValueLabel").getComponent(cc.Label);
@@ -29,31 +32,31 @@ export default class RoundCornerCropEffectScene extends cc.Component {
private _onSliderChanged() {
this._roundCornerRadiuLabel.string = `${this._roundCornerRadiuSlider.progress.toFixed(2)}`;
// // 更新材质
// this._updateRenderComponentMaterial({
// oldLevel: this._roundCornerRadiuSlider.progress
// });
// 更新材质
this._updateRenderComponentMaterial({
roundCornerRadius: this._roundCornerRadiuSlider.progress
});
}
// /**
// * 更新渲染组件的材质
// *
// * 1. 获取材质
// * 2. 给材质的 unitform 变量赋值
// * 3. 重新将材质赋值回去
// */
// private _updateRenderComponentMaterial(param: {
// /**
// * 老化程度 [0.0, 1.0] 1.0 表示完全老化
// */
// oldLevel: number;
// }) {
// this._examplesParentNode.children.forEach(childNode => {
// childNode.getComponents(cc.RenderComponent).forEach(renderComponent => {
// let material: cc.Material = renderComponent.getMaterial(0);
// material.setProperty("oldLevel", param.oldLevel);
// renderComponent.setMaterial(0, material);
// });
// });
// }
/**
* 更新渲染组件的材质
*
* 1. 获取材质
* 2. 给材质的 unitform 变量赋值
* 3. 重新将材质赋值回去
*/
private _updateRenderComponentMaterial(param: {
/**
* 圆角半径 [0.0, 0.5] 0.5 表示圆形裁剪
*/
roundCornerRadius: number;
}) {
this._examplesParentNode.children.forEach(childNode => {
childNode.getComponents(cc.RenderComponent).forEach(renderComponent => {
let material: cc.Material = renderComponent.getMaterial(0);
material.setProperty("roundCornerRadius", param.roundCornerRadius);
renderComponent.setMaterial(0, material);
});
});
}
}