123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- var t = require;
- var e = module;
- var i = exports;
- var s =
- (this && this.__decorate) ||
- function(t, e, i, s) {
- var o,
- a = arguments.length,
- n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
- if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
- else
- for (var r = t.length - 1; 0 <= r; r--)
- (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
- return 3 < a && n && Object.defineProperty(e, i, n), n;
- };
- Object.defineProperty(i, "__esModule", { value: !0 });
- const { ccclass: o, property: a, menu: n, executeInEditMode: r } = cc._decorator;
- e = class extends cc.Component {
- constructor() {
- super(...arguments),
- (this.mask = null),
- (this.invokeEvent = []),
- (this.scrapteRadius = 35),
- (this.scrapteArea = 0.5),
- (this.achieveNum = 0),
- (this.pixelNum = 0);
- }
- onLoad() {
- this.maskGraphics = this.mask._graphics;
- }
- onEnable() {
- this.getInitNum(),
- (this.pixelNum = 0),
- (this.achieveNum = 0),
- (this.achieveNum = this.scrapteArea * this.initPixel()),
- this.node.on(cc.Node.EventType.TOUCH_START, this.onEventStart, this),
- this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onEventMove, this),
- this.node.on(cc.Node.EventType.TOUCH_END, this.onEventEnd, this);
- }
- onDisable() {
- this.node.off(cc.Node.EventType.TOUCH_START, this.onEventStart, this),
- this.node.off(cc.Node.EventType.TOUCH_MOVE, this.onEventMove, this),
- this.node.off(cc.Node.EventType.TOUCH_END, this.onEventEnd, this);
- }
- onEventStart(t) {
- this.comFun(this.node.convertToNodeSpaceAR(t.touch.getLocation())), this.checkScrape();
- }
- onEventMove(t) {
- this.comFun(this.node.convertToNodeSpaceAR(t.touch.getLocation())), this.checkScrape();
- }
- onEventEnd(t) {
- this.comFun(this.node.convertToNodeSpaceAR(t.touch.getLocation())), this.checkScrape();
- }
- addCircle(t) {
- var e = this.maskGraphics,
- i = cc.color(0, 0, 0, 255);
- e.ellipse(t.x, t.y, this.scrapteRadius + 10, this.scrapteRadius + 10),
- (e.lineWidth = 2),
- (e.fillColor = i),
- e.fill();
- }
- checkScrape() {
- this.achieveNum < this.pixelNum &&
- (cc.Component.EventHandler.emitEvents(this.invokeEvent, this),
- cc.log("已经刮完图层"),
- (this.mask.enabled = !1));
- }
- comFun(t) {
- this.checkPixelPiont(t), this.addCircle(t);
- }
- getInitNum() {
- (this.pixelNum = 0), (this.achieveNum = this.scrapteArea * this.initPixel());
- }
- initPixel() {
- var t = this.node.width,
- e = this.node.height;
- let i = (this.node.width = t) / 2,
- s = (this.node.height = e) / 2,
- o = -s,
- a = o;
- var n = [],
- r = 2 * this.scrapteRadius,
- l = 2 * this.scrapteRadius;
- for (let t = -i; t <= i; t += r)
- for (o = a; o <= s; o += l) {
- var h = [t, o];
- (h.isTouch = !0), n.push(h);
- }
- return (this.pixelPiont = n).length;
- }
- checkPixelPiont(t) {
- var e,
- i,
- s,
- o = this.pixelPiont;
- for (s in o)
- if (
- ((e = Math.abs(t.x - o[s][0])),
- (i = Math.abs(t.y - o[s][1])),
- e <= this.scrapteRadius && i <= this.scrapteRadius && o[s].isTouch)
- )
- return (o[s].isTouch = !1), void this.pixelNum++;
- }
- };
- s([a(cc.Mask)], e.prototype, "mask", void 0),
- s([a({ type: cc.Component.EventHandler })], e.prototype, "invokeEvent", void 0),
- s([a({})], e.prototype, "scrapteRadius", void 0),
- s([a({})], e.prototype, "scrapteArea", void 0),
- (e = s([o, r], e)),
- (i.default = e);
|