// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html import { App } from "./App"; import { SoundManager } from "./SoundManager"; const { ccclass, property } = cc._decorator; @ccclass export default class XButton extends cc.Component { onLoad() { } private onTouchDown(event) { this.playOutAnim(); App.SoundManager.playEffect(SoundManager.click); } private onTouchUp(event) { this.playBackAnim(); } //播放扩展动画 private playOutAnim() { cc.tween(this.node).set({ scale: 1 }).to(0.2, { scale: 0.9 }).start(); } //播放收缩动画 private playBackAnim() { cc.tween(this.node).stop() cc.tween(this.node).to(0.2, { scale: 1 }).call(() => { cc.tween(this.node).removeSelf() }).start(); } start() { this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchUp.bind(this), this.node); this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchUp.bind(this), this.node); this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchDown.bind(this), this.node); } // update (dt) {} }