"use strict"; cc._RF.push(module, 'bcbd5UwI81JAqDJwTXtPRoq', 'Ball'); // Script/Ball.ts "use strict"; // 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 var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; var Ball = /** @class */ (function (_super) { __extends(Ball, _super); function Ball() { return _super !== null && _super.apply(this, arguments) || this; } // LIFE-CYCLE CALLBACKS: Ball.prototype.onLoad = function () { // this.init(); this._touch = false; this.node.on(cc.Node.EventType.TOUCH_START, this.touchStart, this); this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove, this); this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd, this); this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd, this); }; Ball.prototype.init = function (type, id) { this.GameManager = this.node.parent.getComponent("GameManager"); this.tube_Array = this.GameManager.tube_Array; this._posX = this.node.x; this._posY = this.node.y; this.size = cc.winSize; this._touch = type; this._id = id; }; Ball.prototype.start = function () { }; //开始点击,提高层级 Ball.prototype.touchStart = function (event) { if (this._touch) { return true; } else { return false; } }; //移动小球,跟随手指移动 Ball.prototype.touchMove = function (event) { if (this._touch) { var touchTemp = cc.v2(event.touch._point.x - this.size.width / 2, event.touch._point.y - this.size.height / 2); this.node.x = touchTemp.x; this.node.y = touchTemp.y; } }; //松手,还原层级,判断是否落到玻璃管内 Ball.prototype.touchEnd = function (event) { //先判断是否是回收 if (this._touch) { var jg = this.getPos(cc.v2(this.node.x, this.node.y)); if (jg == 0) { this.node.x = this._posX; this.node.y = this._posY; } else { this.runEnter(jg); } this._posX = this.node.x; this._posY = this.node.y; } // this.node.zIndex = 1; }; //执行进管子动画 Ball.prototype.runEnter = function (jg) { var _this = this; if (jg == 1 && this.tube_Array[0].length < 3) { var height = 50 + this.tube_Array[0].length * 100; cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 0, pos: cc.v2(this._posX, this._posY) }); cc.tween(this.node) .to(0.2, { x: -210 }) .to(0.25, { y: height }) .call(function () { _this._posX = _this.node.x; _this._posY = _this.node.y; }) .start(); } else if (jg == 3 && this.tube_Array[1].length < 2) { var height = 50 + this.tube_Array[1].length * 100; cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 1, pos: cc.v2(this._posX, this._posY) }); cc.tween(this.node) .to(0.2, { x: 0 }) .to(0.25, { y: height }) .call(function () { _this._posX = _this.node.x; _this._posY = _this.node.y; }) .start(); } else if (jg == 5 && this.tube_Array[2].length < 1) { var height = 50 + this.tube_Array[2].length * 100; cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 2, pos: cc.v2(this._posX, this._posY) }); cc.tween(this.node) .to(0.2, { x: 210 }) .to(0.25, { y: height }) .call(function () { _this._posX = _this.node.x; _this._posY = _this.node.y; }) .start(); } }; Ball.prototype.getPos = function (point) { var jg = 0; var rect = this.GameManager.tube1.getBoundingBox(); if (rect.contains(point)) { jg = 1; return jg; } rect = this.GameManager.tube3.getBoundingBox(); if (rect.contains(point)) { jg = 3; return jg; } rect = this.GameManager.tube5.getBoundingBox(); if (rect.contains(point)) { jg = 5; return jg; } return jg; }; Ball = __decorate([ ccclass ], Ball); return Ball; }(cc.Component)); exports.default = Ball; cc._RF.pop();