import { getGlobalNode } from "../kernel/battle/BattleConst"; import { BlockSkillSwitcher } from "../kernel/battle/map/blockSkill/BlockSkillSwitcher"; import { MapView } from "../kernel/battle/map/MapView"; import GlobalNode from "../kernel/GlobalNode"; import { BlcokSkillViewBase } from "./BlockSkillViewBase"; import BlockView from "./BlockView"; export class BlockSkillSwitcherView extends BlcokSkillViewBase { private _aniNode: cc.Node; private _open: boolean = false; private _callbackBind; constructor(owner: BlockView, mapView: MapView) { super(owner, mapView); this._aniNode = cc.instantiate(mapView.prefabCollection.getChildByName('switcher')); this._aniNode.active = true; this._aniNode.setPosition(this._owner.owner.pixelPos); mapView.txtUpLayer.addChild(this._aniNode); this._callbackBind = this.onLazyUpdate.bind(this); getGlobalNode().getComponent(GlobalNode).schedule(this._callbackBind, 0.1); } onPositionChange(x: number, y: number): void { super.onPositionChange(x, y); this._aniNode.setPosition(x, y); } onDead(): void { super.onDead(); getGlobalNode().getComponent(GlobalNode).unschedule(this._callbackBind); this._aniNode.destroy(); this._aniNode = null; } onDestroy(): void { super.onDestroy(); getGlobalNode().getComponent(GlobalNode).unschedule(this._callbackBind); } private onLazyUpdate() { let skill: BlockSkillSwitcher = this._owner.owner.skill as BlockSkillSwitcher; if (skill.isOpen != this._open) { this._open = skill.isOpen; let ani = this._aniNode.getComponent(cc.Animation); let state = ani.getAnimationState('ani_switcher'); state.stop(); // state.time = (this._open ? 0 : state.clip.duration); state.wrapMode = (this._open ? cc.WrapMode.Normal : cc.WrapMode.Reverse); state.play(); // ani.play('ani_switcher'); } } }