LaserView.ts
4.43 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// 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 { BattleEvent, LASER_DIR } from "../kernel/battle/BattleConst";
import { BattleManager } from "../kernel/battle/BattleManager";
import { LaserObj } from "../kernel/battle/map/LaserObj";
import { MapView } from "../kernel/battle/map/MapView";
import { ObjData } from "../kernel/battle/map/ObjData";
import ObjBaseView from "./ObjBaseView";
const { ccclass, property } = cc._decorator;
@ccclass
export default class LaserView extends ObjBaseView {
private _effect: cc.Node;
private _laser: cc.Node;
private _vLaser: cc.Node;
//#region interface
onHit(): void {
let 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);
let 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);
let laserAni = this._vLaser.getComponent(cc.Animation);
!laserAni.getAnimationState('fx_laser_02').isPlaying && laserAni.play('fx_laser_02', 0);
}
}
//#endregion
//#region LIFE-CYCLE CALLBACKS:
init(owner: ObjData, mapView: MapView): void {
let laserObj = owner as LaserObj;
if (laserObj.dir == LASER_DIR.HORIZEN || laserObj.dir == 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;
let laserAni = this._laser.getComponent(cc.Animation);
laserAni.on('finished', () => { this._laser.active = false; }, this);
}
if (laserObj.dir == LASER_DIR.VERTICAL || laserObj.dir == 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;
let vlaserAni = this._vLaser.getComponent(cc.Animation);
vlaserAni.on('finished', () => { this._vLaser.active = false; }, this);
}
this._effect = this.node.getChildByName('UI_yxz_tsfk_jg2');
this._effect.removeFromParent();
super.init(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.ins.eventNode.on(BattleEvent.BATTLE_START, this.onBattleStart, this);
}
protected onPositionChange(x: number, y: number): void {
super.onPositionChange(x, y);
this._effect.setPosition(x, y);
this._laser && this._laser.setPosition(0, y);
this._vLaser && this._vLaser.setPosition(x, 0);
}
protected onVisibleChange(): void {
this._img.active = false; //图片一直隐藏
}
protected onDestroy(): void {
BattleManager.ins.eventNode.off(BattleEvent.BATTLE_START, this.onBattleStart, this);
this._effect.destroy();
this._laser && this._laser.destroy();
this._vLaser && this._vLaser.destroy();
}
protected onImageLoaded(): void {
//更新特效的图片
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, (error, asset) => {
if (!this._destroyed) {
this._effect.getChildByName('UI_yxz_tsfk_jg2a').getComponent(cc.Sprite).spriteFrame = asset as cc.SpriteFrame;
}
})
}
// update (dt) {}
//#endregion
private onBattleStart() {
let ani = this._effect.getComponent(cc.Animation);
ani.play("ani_yxz_tsfk_jg01", 0);
}
}