Bullet.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { _decorator, Component, Node, sp, UITransform, Vec2, Vec3 ,Animation, Color, tween} from 'cc';
  2. import { BattleNodeBase } from './BattleNodeBase';
  3. import { RenderPriority } from '../data/BattleEnum';
  4. const { ccclass, property } = _decorator;
  5. // 子弹基类
  6. @ccclass('Bullet')
  7. export class Bullet extends BattleNodeBase {
  8. @property({ type: sp.Skeleton, tooltip: '骨骼动画' })
  9. modelSpine: sp.Skeleton = null;
  10. speedVector: Vec2 = new Vec2(0, 0);
  11. bStand: boolean = false;
  12. target: Node = null;
  13. dieCallback: Function = null;
  14. protected onLoad(): void {
  15. this.priority = RenderPriority.Bullet;
  16. this.modelSpine.setCompleteListener(this.actionComplete.bind(this))
  17. }
  18. start() {
  19. }
  20. //用自定义更新,不用系统更新
  21. battleUpdate(deltaTime: number) {
  22. this.node.position = new Vec3(this.node.position.x+this.speedVector.x*deltaTime,this.node.position.y+this.speedVector.y*deltaTime,0)
  23. }
  24. resetData(typeID:number,ID:number,pos:Vec3,life:number,lifeMax:number) {
  25. this.typeID = typeID;
  26. this.ID = ID;
  27. this.node.position = pos
  28. this.bStand = false;
  29. this.dieCallback = null;
  30. }
  31. startMove(animationName:string){
  32. this.node.active = true;
  33. // this.modelSpine.setAnimation(0, 'idle', true);
  34. }
  35. stand() {
  36. this.bStand = true;
  37. if(!this.modelSpine.node.active) return;
  38. this.modelSpine.setAnimation(0, 'idle', true);
  39. this.modelSpine.color = Color.WHITE;
  40. // this._attackCallback = null;
  41. }
  42. clearData() {
  43. this.node.active = false
  44. }
  45. die(callback?:Function) {
  46. this.dieCallback = callback;
  47. tween(this.node).delay(0.5).call(() => {
  48. this.node.active = false
  49. this.modelSpine.color = Color.WHITE;
  50. this.dieCallback && this.dieCallback()
  51. }).start()
  52. }
  53. actionComplete(trackEntry:sp.spine.TrackEntry){
  54. // console.log("动作完成:",trackEntry.animation.name,this._posID)
  55. // if (trackEntry.animation.name && trackEntry.animation.name.includes("hurt")) {
  56. // this._bHurtAnimation = false;
  57. // this.modelSpine.addAnimation(0, 'idle', true);
  58. // this.modelSpine.color = Color.WHITE;
  59. // }
  60. }
  61. }