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