aniList.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { LQCollide } from "../../Collide/lq_collide_system/lq_collide";
  2. import { LevelMgr } from "../../levelMgr";
  3. import { EditorSet } from "../common/editorSet";
  4. import { GameLogic } from "../update/GameLogic";
  5. const {ccclass, property, executeInEditMode, playOnFocus} = cc._decorator;
  6. ccclass
  7. class AniData{
  8. loop: boolean;
  9. }
  10. @ccclass
  11. @executeInEditMode
  12. @playOnFocus
  13. export default class AniList extends GameLogic {
  14. @property(cc.Prefab) monster: cc.Prefab = null;
  15. @property([cc.AnimationClip]) aniClip = [];
  16. monsterNode: cc.Node;
  17. protected onLoad(): void {
  18. let monsterNode = new cc.Node('monsterGroup');
  19. this.monsterNode = monsterNode;
  20. EditorSet.DontShow(monsterNode);
  21. this.node.addChild(monsterNode);
  22. if(CC_EDITOR){
  23. let node = new cc.Node('Collide');
  24. this.node.addChild(node);
  25. node.zIndex = cc.macro.MAX_ZINDEX;
  26. EditorSet.DontShow(node);
  27. let debugDrawer = node.addComponent(cc.Graphics);
  28. debugDrawer.lineWidth = 5;
  29. debugDrawer.strokeColor = new cc.Color(255, 0, 0);
  30. debugDrawer.fillColor = new cc.Color(255, 0, 0);
  31. debugDrawer.circle(0, 0, 20);
  32. debugDrawer.stroke();
  33. }
  34. else{
  35. this.play();
  36. }
  37. }
  38. // protected onFocusInEditor(): void {
  39. // this.play();
  40. // }
  41. // protected onLostFocusInEditor(): void {
  42. // this.end();
  43. // }
  44. end(){
  45. this.monsterNode.destroyAllChildren();
  46. }
  47. play(): void {
  48. this.monsterNode.destroyAllChildren();
  49. if(!this.monster) {
  50. cc.log('设置怪物资源');
  51. return;
  52. }
  53. // let node = cc.instantiate(this.monster);
  54. // let ani = node.addComponent(cc.Animation);
  55. // this.monsterNode.addChild(node);
  56. // EditorSet.DontShow(node);
  57. // this.aniClip.forEach((v,k)=>{
  58. // ani.addClip(v, `path${k}`)
  59. // });
  60. // let cnt = 0;
  61. // let callAni = ()=>{
  62. // ani.play(`path${cnt}`);
  63. // ani.once(cc.Animation.EventType.FINISHED, ()=>{
  64. // cnt++;
  65. // if(cnt < this.aniClip.length){
  66. // callAni();
  67. // }
  68. // });
  69. // }
  70. // callAni();
  71. let monsterNode = cc.instantiate(this.monster);
  72. let cnt = 0;
  73. let callAni = ()=>{
  74. let aniNode = new cc.Node('AniItem');
  75. let parent = monsterNode.parent ? monsterNode.parent : this.monsterNode;
  76. monsterNode.removeFromParent(false);
  77. aniNode.addChild(monsterNode);
  78. parent.addChild(aniNode);
  79. let ani = aniNode.addComponent(cc.Animation);
  80. ani.addClip(this.aniClip[cnt], 'path')
  81. ani.play('path');
  82. ani.once(cc.Animation.EventType.FINISHED, ()=>{
  83. cnt++;
  84. if(cnt < this.aniClip.length){
  85. callAni();
  86. }
  87. });
  88. }
  89. callAni();
  90. }
  91. gameUpdate(dt: number): void {
  92. // if(CC_EDITOR) return;
  93. // if(this.monsterNode.getComponentsInChildren(LQCollide).length > 0) return;
  94. // LevelMgr.inst.next();
  95. // 结束
  96. }
  97. }