Bullet.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. speedVector: Vec2 = new Vec2(0, 0);
  9. bStand: boolean = false;
  10. target: Node = null;
  11. dieCallback: Function = null;
  12. protected onLoad(): void {
  13. this.priority = RenderPriority.Bullet;
  14. }
  15. start() {
  16. }
  17. //用自定义更新,不用系统更新
  18. battleUpdate(deltaTime: number) {
  19. this.node.position = new Vec3(this.node.position.x+this.speedVector.x*deltaTime,this.node.position.y+this.speedVector.y*deltaTime,0)
  20. }
  21. resetData(typeID:number,ID:number,pos:Vec3,life:number,lifeMax:number) {
  22. this.typeID = typeID;
  23. this.ID = ID;
  24. this.node.position = pos
  25. this.bStand = false;
  26. this.dieCallback = null;
  27. }
  28. startMove(animationName:string){
  29. this.node.active = true;
  30. // this.modelSpine.setAnimation(0, 'idle', true);
  31. }
  32. stand() {
  33. this.bStand = true;
  34. }
  35. clearData() {
  36. this.node.active = false
  37. }
  38. die(callback?:Function) {
  39. this.dieCallback = callback;
  40. tween(this.node).delay(0.5).call(() => {
  41. this.node.active = false
  42. this.dieCallback && this.dieCallback()
  43. }).start()
  44. }
  45. actionComplete(trackEntry:sp.spine.TrackEntry){
  46. // console.log("动作完成:",trackEntry.animation.name,this._posID)
  47. // if (trackEntry.animation.name && trackEntry.animation.name.includes("hurt")) {
  48. // this._bHurtAnimation = false;
  49. // this.modelSpine.addAnimation(0, 'idle', true);
  50. // this.modelSpine.color = Color.WHITE;
  51. // }
  52. }
  53. }