觉醒时刻
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
juexingshike/assets/Scripts/WenZiRes/WenZiCommon/NameplateAnimation.ts

57 lines
1.6 KiB

const { ccclass, property } = cc._decorator;
enum AnimationType {
AUTO = 0,
CLICK = 1
}
@ccclass
export default class NameplateAnimation extends cc.Component {
@property({
type: cc.Enum(AnimationType),
displayName: '触发类型',
})
animationType: AnimationType = AnimationType.AUTO;
@property({
displayName: '停留时间',
visible() { return this.animationType == AnimationType.AUTO },
})
stopTime: number = 3;
@property({
type: cc.Node,
displayName: '点击节点',
visible() { return this.animationType == AnimationType.CLICK },
})
touchNode: cc.Node = null;
start() {
if (this.animationType == AnimationType.AUTO) {
cc.tween(this.node)
// .set({ active: true, opacity: 0 })
.to(0.5, { opacity: 255 })
.delay(this.stopTime)
.to(0.5, { opacity: 0 })
.hide()
.start();
} else if (this.animationType == AnimationType.CLICK) {
if (!this.touchNode) {
this.touchNode = this.node;
}
this.touchNode.on(cc.Node.EventType.TOUCH_START, () => {
this.node['_touchListener'].setSwallowTouches(false);
cc.tween(this.node)
.to(0.5, { opacity: 0 })
.hide()
.start();
}, this);
cc.tween(this.node)
.set({ active: true, opacity: 0 })
.to(0.5, { opacity: 255 })
.start();
}
}
}