TouchSpecialEffComp.ts
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { ResUtils } from "simba-cc-resutils";
const { ccclass, property, menu } = cc._decorator;
@ccclass
@menu("自定义UI组件/TouchSpecialEffComp")
export default class TouchSpecialEffComp extends cc.Component {
    onLoad() {
    }
    onEnable() {
        this.node.on(cc.Node.EventType.TOUCH_START, this.callback, this, false);
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.callback, this, false);
        this.node.on(cc.Node.EventType.TOUCH_END, this.callback, this, false);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.callback, this, false);
    }
    onDestroy() {
        this.node.off(cc.Node.EventType.TOUCH_END, this.callback, this);
    }
    onDisable() {
        this.node.off(cc.Node.EventType.TOUCH_END, this.callback, this);
    }
    async callback(event) {
        if (event.type == cc.Node.EventType.TOUCH_END) {
            let spNode = new cc.Node();
            spNode.name = "touchSpNode";
            let sp = spNode.addComponent(cc.Sprite);
            sp.spriteFrame = await ResUtils.loadRes("textures/common/gift_AD", cc.SpriteFrame);
            spNode.parent = this.node;
            spNode.setPosition(this.node.convertToNodeSpaceAR(event.getLocation()));
            this.scheduleOnce(() => {
                if (cc.isValid(spNode)) {
                    spNode.destroy();
                }
            }, 0.5);
        }
    }
}