86510959-3ac0-4227-95f8-b94c622ad69b.js 5.27 KB
"use strict";
cc._RF.push(module, '86510lZOsBCJ5X4uUxiKtab', 'SurroundMotionStreakAction');
// script/game/ui/SurroundMotionStreakAction.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 __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 });
const { ccclass, property } = cc._decorator;
var MoveDirection;
(function (MoveDirection) {
    MoveDirection[MoveDirection["Clockwise"] = 0] = "Clockwise";
    MoveDirection[MoveDirection["Anticlockwise"] = 1] = "Anticlockwise";
})(MoveDirection || (MoveDirection = {}));
let SurroundMotionStreakAction = /** @class */ (() => {
    let SurroundMotionStreakAction = class SurroundMotionStreakAction extends cc.Component {
        constructor() {
            // LIFE-CYCLE CALLBACKS:
            super(...arguments);
            this.moveSpeed = 1;
            this.fadeTime = 1;
            this.minSeg = 1;
            this.stroke = 10;
            this.direction = MoveDirection.Clockwise;
            this.actNode = new cc.Node;
            this.motionStreakTexture = new cc.Texture2D;
            this._baseTime = 1;
        }
        onLoad() { }
        start() {
        }
        onEnable() {
            let lt = cc.v2(this.node.width * (-1) / 2, this.node.height / 2);
            let rt = cc.v2(this.node.width / 2, this.node.height / 2);
            let rb = cc.v2(this.node.width / 2, this.node.height * (-1) / 2);
            let lb = cc.v2(this.node.width * (-1) / 2, this.node.height * (-1) / 2);
            let actTime = this._baseTime / this.moveSpeed;
            let max = Math.max(this.node.width, this.node.height);
            let wTime = this.node.width / max * actTime;
            let hTime = this.node.height / max * actTime;
            let ltAct = cc.moveTo(hTime, lt);
            let rtAct = cc.moveTo(wTime, rt);
            let rbAct = cc.moveTo(hTime, rb);
            let lbAct = cc.moveTo(wTime, lb);
            if (this.direction === MoveDirection.Anticlockwise) {
                ltAct = cc.moveTo(wTime, lt);
                rtAct = cc.moveTo(hTime, rt);
                rbAct = cc.moveTo(wTime, rb);
                lbAct = cc.moveTo(hTime, lb);
            }
            let seqClockwise = cc.sequence(ltAct, rtAct, rbAct, lbAct);
            let seqAnticlockwise = cc.sequence(rtAct, ltAct, lbAct, rbAct);
            let motionStreak = this.actNode.getComponent(cc.MotionStreak);
            if (!motionStreak) {
                motionStreak = this.actNode.addComponent(cc.MotionStreak);
                motionStreak.texture = this.motionStreakTexture;
                motionStreak.fadeTime = this.fadeTime;
                motionStreak.minSeg = this.minSeg;
                motionStreak.stroke = this.stroke;
            }
            motionStreak.enabled = true;
            this.actNode.stopAllActions();
            if (this.direction === MoveDirection.Clockwise) {
                this.actNode.x = this.node.width * (-1) / 2;
                this.actNode.y = this.node.height / 2;
                this.actNode.runAction(cc.repeatForever(seqClockwise));
            }
            else if (this.direction === MoveDirection.Anticlockwise) {
                this.actNode.x = this.node.width / 2;
                this.actNode.y = this.node.height / 2;
                this.actNode.runAction(cc.repeatForever(seqAnticlockwise));
            }
        }
        onDisable() {
            let motionStreak = this.actNode.getComponent(cc.MotionStreak);
            if (motionStreak) {
                motionStreak.enabled = false;
            }
            this.node.stopAllActions();
        }
    };
    __decorate([
        property
    ], SurroundMotionStreakAction.prototype, "moveSpeed", void 0);
    __decorate([
        property
    ], SurroundMotionStreakAction.prototype, "fadeTime", void 0);
    __decorate([
        property
    ], SurroundMotionStreakAction.prototype, "minSeg", void 0);
    __decorate([
        property
    ], SurroundMotionStreakAction.prototype, "stroke", void 0);
    __decorate([
        property
    ], SurroundMotionStreakAction.prototype, "direction", void 0);
    __decorate([
        property({ type: cc.Node })
    ], SurroundMotionStreakAction.prototype, "actNode", void 0);
    __decorate([
        property({ type: cc.Texture2D })
    ], SurroundMotionStreakAction.prototype, "motionStreakTexture", void 0);
    SurroundMotionStreakAction = __decorate([
        ccclass
    ], SurroundMotionStreakAction);
    return SurroundMotionStreakAction;
})();
exports.default = SurroundMotionStreakAction;

cc._RF.pop();