PotView.ts
1.69 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
62
63
64
65
66
// 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 { PotObj } from "../kernel/battle/map/PotObj";
import ObjBaseView from "./ObjBaseView";
const { ccclass, property } = cc._decorator;
@ccclass
export default class PotView extends ObjBaseView {
private _effect: cc.Node;
//#region life cycle
init(owner: ObjData, mapView: MapView): void {
this._effect = this.node.getChildByName("UI_yxz_tsfk_ph");
this._effect.removeFromParent();
mapView.effectLayer.addChild(this._effect);
super.init(owner, mapView);
this._img.active = false;
}
protected update(dt: number): void {
super.update(dt);
this._effect.angle = (this.owner as PotObj).angle;
}
onDead(): void {
super.onDead();
this._effect.destroy();
}
//#endregion
//#region event
onHit(): void {
super.onHit();
let ani = this._effect.getComponent(cc.Animation);
ani && !ani.getAnimationState('fx_yxz_tsfk_ph_001').isPlaying && ani.play('fx_yxz_tsfk_ph_001', 0);
}
protected onVisibleChange(): void {
this._img.active = false; //图片一直隐藏
}
protected onPositionChange(x: number, y: number): void {
super.onPositionChange(x, y);
this._effect.setPosition(x, y);
}
//#endregion
}