mirror of
https://github.com/ifengzp/cocos-awesome.git
synced 2024-12-26 03:39:22 +00:00
ca81a027d3
一个借助shader渐变的相册demo
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
const { ccclass, property } = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class Scene_transition extends cc.Component {
|
|
@property([cc.Node])
|
|
switchNodeList: cc.Node[] = [];
|
|
fadeRadius: number = 0.1;
|
|
|
|
onLoad() {
|
|
this.switchNodeList.forEach((node, idx) => {
|
|
node.zIndex = this.switchNodeList.length - idx;
|
|
})
|
|
}
|
|
|
|
isTransforming: boolean = false;
|
|
bgTramsform() {
|
|
if (this.isTransforming) return;
|
|
this.isTransforming = true;
|
|
|
|
let time = 0.0;
|
|
let node = this.switchNodeList[0];
|
|
let material = node.getComponent(cc.Sprite).getMaterial(0);
|
|
material.setProperty('u_fade_radius', this.fadeRadius);
|
|
material.setProperty('u_time', time);
|
|
material.define('USE_TRAMSFORM', true, 0, true);
|
|
|
|
let timer = setInterval(() => {
|
|
time += 0.03;
|
|
material.setProperty('u_time', time);
|
|
if (time > 1.0 + this.fadeRadius) {
|
|
this.switchNodeList.shift();
|
|
this.switchNodeList.push(node);
|
|
this.switchNodeList.forEach((node, idx) => {
|
|
node.zIndex = this.switchNodeList.length - idx;
|
|
})
|
|
material.define('USE_TRAMSFORM', false, 0, true);
|
|
this.isTransforming = false;
|
|
timer && clearInterval(timer);
|
|
}
|
|
}, 30);
|
|
}
|
|
}
|