BlockSkillSwitcherView.ts
2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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');
}
}
}