PatrolView.ts 1.91 KB
// 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

import { MapView } from "../kernel/battle/map/MapView";
import { ObjData } from "../kernel/battle/map/ObjData";
import { PatrolObj } from "../kernel/battle/map/PatrolObj";
import ObjBaseView from "./ObjBaseView";

const { ccclass, property } = cc._decorator;

@ccclass
export default class PatrolView extends ObjBaseView {

    get owner(): PatrolObj { return this._owner as PatrolObj; }

    //#region lifecycle 

    init(owner: ObjData, mapView: MapView): void {
        super.init(owner, mapView);

        this.node.getChildByName('aninode').getChildByName('particle').active = this.owner.patrolType == 0;
        this.node.getChildByName('aninode').getComponent(cc.Animation).play(this.owner.patrolType ? "ani_yxz_tsfk_csm01" : "ani_yxz_tsfk_csm02");

        cc.resources.load('battle/UI_yxz_tsfk_csm' + this.owner.patrolIndex.toString(), cc.SpriteFrame, (error, asset: cc.SpriteFrame) => {
            if (!error) {
                cc.find('aninode/UI_yxz_tsfk_csm01', this.node).getComponent(cc.Sprite).spriteFrame = asset;
                cc.find('aninode/UI_yxz_tsfk_csm01a', this.node).getComponent(cc.Sprite).spriteFrame = asset;
            }
        })
    }

    //#endregion

    //#region public method

    //#endregion

    //#region event

    onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.Collider, otherCollider: cc.Collider): void {

        if (otherCollider.node.name == "ball" && this.owner.patrolType == 0) {
            //入口才触发碰撞
            super.onBeginContact(contact, selfCollider, otherCollider);
        }
    }

    //#endregion

    //#region private method

    //#endregion
}