@property(cc.Node)
startButton: cc.Node = null;
@property(cc.Node)
buttonHover: cc.Node = null;
onLoad () {
this.startButton.on(cc.Node.EventType.MOUSE_ENTER, this.enterBtn, this);
this.startButton.on(cc.Node.EventType.MOUSE_LEAVE, this.leaveBtn, this);
}
/**进入按钮范围*/
enterBtn() {
this.buttonHover.stopAllActions();
this.buttonHover.active = true;
cc.tween(this.buttonHover).parallel(
cc.tween().to(0, { scale: 1, opacity: 0 }).to(1, { scale: 1.5 }),
cc.tween().to(0.5, { opacity: 255 }).to(0.5, { opacity: 0 })
).union().repeatForever().start();
console.log("进入按钮范围")
}
/**离开按钮范围*/
leaveBtn() {
this.buttonHover.stopAllActions();
this.buttonHover.scale = 1;
this.buttonHover.opacity = 0;
this.buttonHover.active = false;
console.log("退出按钮范围")
}
鼠标移动到按钮范围的时候,超大概率同时触发这两个事件。
难道这么写是有问题的?