import BaseEvent from "../fight/evnet/base/BaseEvent"; import { SpriteActionType } from "../fight/object/FSprite"; const { ccclass, property } = cc._decorator; // 加速带方向 export enum SpeedUpDirection { Left = "zuo", Right = "you", Up = "shang", Down = "xia", } @ccclass export default class NewClass extends BaseEvent { @property({ type: sp.Skeleton, displayName: "动画" }) spine: sp.Skeleton = null; @property({ displayName: "方向", }) speedUpDirection: SpeedUpDirection = SpeedUpDirection.Left; @property({ displayName: "加速时间", }) speedUpTime: number = 0.5; @property({ displayName: "加速倍数", }) speedUpMul: number = 2; @property({ displayName: "加速距离", }) speedUpDis: number = 320; onLoad() { super.onLoad(); this.node.zIndex = -9999; this.spine.setAnimation(0, this.speedUpDirection, true); } onBegin() { // this.ff.mainSprite.setSpeedUpInfo(this.direction, this.speedUpTime, this.speedUpMul); this.ff.mainSprite.speedUp = this.speedUpDirection; let sprite = this.ff.mainSprite; let moveX = 1; let moveY = 0; let scaleX = 1; if (this.speedUpDirection == SpeedUpDirection.Left) { moveX = -1; moveY = 0; scaleX = -1; } else if (this.speedUpDirection == SpeedUpDirection.Right) { moveX = 1; moveY = 0; } else if (this.speedUpDirection == SpeedUpDirection.Up) { moveX = 0; moveY = 1; } else if (this.speedUpDirection == SpeedUpDirection.Down) { moveX = 0; moveY = -1; } if (this.speedUpDirection == SpeedUpDirection.Left) { sprite.node.scaleX = -Math.abs(sprite.node.scaleX); } else { sprite.node.scaleX = Math.abs(sprite.node.scaleX); } sprite.spine.setAnimation(0, SpriteActionType.move, true); cc.tween(sprite.node).sequence( cc.moveTo(this.speedUpTime, cc.v2(sprite.node.x + this.speedUpDis * moveX, sprite.node.y + this.speedUpDis * moveY)), cc.callFunc(() => { if (!sprite.isWalk) { sprite.spine.setAnimation(0, SpriteActionType.stand, true); } this.ff.mainSprite.speedUp = ""; }) ).start(); } }