77f6830a-26ee-4b84-8293-064a84753aa9.js 6.09 KB
"use strict";
cc._RF.push(module, '77f68MKJu5LhIKTBkqEdTqp', 'LaserView');
// scripts/prefabs/LaserView.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 BattleConst_1 = require("../kernel/battle/BattleConst");
var BattleManager_1 = require("../kernel/battle/BattleManager");
var ObjBaseView_1 = require("./ObjBaseView");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var LaserView = /** @class */ (function (_super) {
    __extends(LaserView, _super);
    function LaserView() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    //#region interface
    LaserView.prototype.onHit = function () {
        var ani = this._effect.getComponent(cc.Animation);
        !ani.getAnimationState('ani_yxz_tsfk_jg02').isPlaying && ani.play('ani_yxz_tsfk_jg02', 0);
        if (this._laser) {
            !this._laser.active && (this._laser.active = true);
            var laserAni = this._laser.getComponent(cc.Animation);
            !laserAni.getAnimationState('fx_laser_02').isPlaying && laserAni.play('fx_laser_02', 0);
        }
        if (this._vLaser) {
            !this._vLaser.active && (this._vLaser.active = true);
            var laserAni = this._vLaser.getComponent(cc.Animation);
            !laserAni.getAnimationState('fx_laser_02').isPlaying && laserAni.play('fx_laser_02', 0);
        }
    };
    //#endregion
    //#region  LIFE-CYCLE CALLBACKS:
    LaserView.prototype.init = function (owner, mapView) {
        var _this = this;
        var laserObj = owner;
        if (laserObj.dir == BattleConst_1.LASER_DIR.HORIZEN || laserObj.dir == BattleConst_1.LASER_DIR.COMBINE) {
            this._laser = cc.instantiate(mapView.prefabCollection.getChildByName('skillSpine').getChildByName('laser'));
            this._laser.scaleX = mapView.width / this._laser.width;
            this._laser.active = false;
            var laserAni = this._laser.getComponent(cc.Animation);
            laserAni.on('finished', function () { _this._laser.active = false; }, this);
        }
        if (laserObj.dir == BattleConst_1.LASER_DIR.VERTICAL || laserObj.dir == BattleConst_1.LASER_DIR.COMBINE) {
            this._vLaser = cc.instantiate(mapView.prefabCollection.getChildByName('skillSpine').getChildByName('laser'));
            this._vLaser.scaleX = mapView.height / this._vLaser.width;
            this._vLaser.angle = 90;
            this._vLaser.active = false;
            var vlaserAni = this._vLaser.getComponent(cc.Animation);
            vlaserAni.on('finished', function () { _this._vLaser.active = false; }, this);
        }
        this._effect = this.node.getChildByName('UI_yxz_tsfk_jg2');
        this._effect.removeFromParent();
        _super.prototype.init.call(this, owner, mapView);
        this._img.active = false;
        mapView.effectLayer.addChild(this._effect);
        this._laser && mapView.effectLayer.addChild(this._laser);
        this._vLaser && mapView.effectLayer.addChild(this._vLaser);
        BattleManager_1.BattleManager.ins.eventNode.on(BattleConst_1.BattleEvent.BATTLE_START, this.onBattleStart, this);
    };
    LaserView.prototype.onPositionChange = function (x, y) {
        _super.prototype.onPositionChange.call(this, x, y);
        this._effect.setPosition(x, y);
        this._laser && this._laser.setPosition(0, y);
        this._vLaser && this._vLaser.setPosition(x, 0);
    };
    LaserView.prototype.onVisibleChange = function () {
        this._img.active = false; //图片一直隐藏
    };
    LaserView.prototype.onDestroy = function () {
        BattleManager_1.BattleManager.ins.eventNode.off(BattleConst_1.BattleEvent.BATTLE_START, this.onBattleStart, this);
        this._effect.destroy();
        this._laser && this._laser.destroy();
        this._vLaser && this._vLaser.destroy();
    };
    LaserView.prototype.onImageLoaded = function () {
        var _this = this;
        //更新特效的图片
        this._effect.getChildByName('UI_yxz_tsfk_jg2').getComponent(cc.Sprite).spriteFrame = this._img.getComponent(cc.Sprite).spriteFrame;
        cc.resources.load('battle/' + this.owner.imgName + 'a', cc.SpriteFrame, function (error, asset) {
            if (!_this._destroyed) {
                _this._effect.getChildByName('UI_yxz_tsfk_jg2a').getComponent(cc.Sprite).spriteFrame = asset;
            }
        });
    };
    // update (dt) {}
    //#endregion
    LaserView.prototype.onBattleStart = function () {
        var ani = this._effect.getComponent(cc.Animation);
        ani.play("ani_yxz_tsfk_jg01", 0);
    };
    LaserView = __decorate([
        ccclass
    ], LaserView);
    return LaserView;
}(ObjBaseView_1.default));
exports.default = LaserView;

cc._RF.pop();