123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class EventButton extends cc.Component {
- @property(cc.Sprite)
- mIcon: cc.Sprite = null;
- private callback:()=>void;
- private startCallback:()=>void;
- private endCallback:()=>void;
- public setCallback(callback:()=>void){
- this.callback = callback;
- }
-
- public onclick(){
- if(this.callback){
- this.callback();
- }
- }
-
- public onTouchEvent(startCallback:()=>void,endCallback:()=>void){
- this.startCallback = startCallback;
- this.endCallback = endCallback;
- this.node.on(cc.Node.EventType.TOUCH_START, this._touchShootStartEvent, this);
- this.node.on(cc.Node.EventType.TOUCH_END, this._touchShootEndEvent, this);
- this.node.on(cc.Node.EventType.TOUCH_CANCEL, this._touchShootEndEvent, this);
- }
-
- public offTouchEvent(){
- this.startCallback = null;
- this.endCallback = null;
- this.node.off(cc.Node.EventType.TOUCH_START)
- this.node.off(cc.Node.EventType.TOUCH_END)
- this.node.off(cc.Node.EventType.TOUCH_CANCEL)
- }
- private _touchShootStartEvent() {
- if(this.startCallback){
- this.startCallback();
- }
- }
- private _touchShootEndEvent() {
- if(this.endCallback){
- this.endCallback();
- }
- }
- }
|