JG0115.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import BaseEvent from "../fight/evnet/base/BaseEvent";
  2. import { SpriteActionType } from "../fight/object/FSprite";
  3. const { ccclass, property } = cc._decorator;
  4. // 加速带方向
  5. export enum SpeedUpDirection {
  6. Left = "zuo",
  7. Right = "you",
  8. Up = "shang",
  9. Down = "xia",
  10. }
  11. @ccclass
  12. export default class NewClass extends BaseEvent {
  13. @property({
  14. type: sp.Skeleton,
  15. displayName: "动画"
  16. })
  17. spine: sp.Skeleton = null;
  18. @property({
  19. displayName: "方向",
  20. })
  21. speedUpDirection: SpeedUpDirection = SpeedUpDirection.Left;
  22. @property({
  23. displayName: "加速时间",
  24. })
  25. speedUpTime: number = 0.5;
  26. @property({
  27. displayName: "加速倍数",
  28. })
  29. speedUpMul: number = 2;
  30. @property({
  31. displayName: "加速距离",
  32. })
  33. speedUpDis: number = 320;
  34. onLoad() {
  35. super.onLoad();
  36. this.node.zIndex = -9999;
  37. this.spine.setAnimation(0, this.speedUpDirection, true);
  38. }
  39. onBegin() {
  40. // this.ff.mainSprite.setSpeedUpInfo(this.direction, this.speedUpTime, this.speedUpMul);
  41. this.ff.mainSprite.speedUp = this.speedUpDirection;
  42. let sprite = this.ff.mainSprite;
  43. let moveX = 1;
  44. let moveY = 0;
  45. let scaleX = 1;
  46. if (this.speedUpDirection == SpeedUpDirection.Left) {
  47. moveX = -1;
  48. moveY = 0;
  49. scaleX = -1;
  50. } else if (this.speedUpDirection == SpeedUpDirection.Right) {
  51. moveX = 1;
  52. moveY = 0;
  53. } else if (this.speedUpDirection == SpeedUpDirection.Up) {
  54. moveX = 0;
  55. moveY = 1;
  56. } else if (this.speedUpDirection == SpeedUpDirection.Down) {
  57. moveX = 0;
  58. moveY = -1;
  59. }
  60. if (this.speedUpDirection == SpeedUpDirection.Left) {
  61. sprite.node.scaleX = -Math.abs(sprite.node.scaleX);
  62. } else {
  63. sprite.node.scaleX = Math.abs(sprite.node.scaleX);
  64. }
  65. sprite.spine.setAnimation(0, SpriteActionType.move, true);
  66. cc.tween(sprite.node).sequence(
  67. cc.moveTo(this.speedUpTime, cc.v2(sprite.node.x + this.speedUpDis * moveX, sprite.node.y + this.speedUpDis * moveY)),
  68. cc.callFunc(() => {
  69. if (!sprite.isWalk) {
  70. sprite.spine.setAnimation(0, SpriteActionType.stand, true);
  71. }
  72. this.ff.mainSprite.speedUp = "";
  73. })
  74. ).start();
  75. }
  76. }