aniList.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 cc.Component {
  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 monsterNode = cc.instantiate(this.monster);
  54. let cnt = 0;
  55. let callAni = ()=>{
  56. let aniNode = new cc.Node('AniItem');
  57. let parent = monsterNode.parent ? monsterNode.parent : this.monsterNode;
  58. monsterNode.removeFromParent(false);
  59. aniNode.addChild(monsterNode);
  60. parent.addChild(aniNode);
  61. let ani = aniNode.addComponent(cc.Animation);
  62. ani.addClip(this.aniClip[cnt], 'path')
  63. ani.play('path');
  64. ani.once(cc.Animation.EventType.FINISHED, ()=>{
  65. cnt++;
  66. if(cnt < this.aniClip.length){
  67. aniNode.angle = 0;
  68. callAni();
  69. }
  70. });
  71. }
  72. callAni();
  73. }
  74. }