jumpPrefab.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * 预制类型
  3. */
  4. const { ccclass, property } = cc._decorator;
  5. import { JumpType } from '../game/enumConfig';
  6. @ccclass
  7. export default class jumpPrefab extends cc.Component {
  8. @property(cc.SpriteFrame)
  9. directionJump: cc.SpriteFrame = null;
  10. @property(cc.SpriteFrame)
  11. midJump: cc.SpriteFrame = null;
  12. @property(cc.SpriteFrame)
  13. rotateJump: cc.SpriteFrame = null;
  14. @property(cc.Sprite)
  15. showSprite: cc.Sprite = null;
  16. //当前跳的类型
  17. @property({ type: cc.Enum(JumpType) })
  18. currentJumpType: JumpType = JumpType.LEFT;
  19. bTrigger: Boolean = false;
  20. index: number = 0;
  21. // onLoad () {}
  22. start() {
  23. if (this.currentJumpType == JumpType.NORMAL) {
  24. this.showSprite.spriteFrame = this.midJump;
  25. } else if (this.currentJumpType == JumpType.LEFT) {
  26. this.showSprite.spriteFrame = this.directionJump;
  27. this.showSprite.node.scaleX = -1;
  28. } else if (this.currentJumpType == JumpType.RIGHT) {
  29. this.showSprite.spriteFrame = this.directionJump;
  30. } else if (this.currentJumpType == JumpType.LEFT_ROTATE) {
  31. this.showSprite.spriteFrame = this.rotateJump;
  32. } else if (this.currentJumpType == JumpType.RIGHT_ROTATE) {
  33. this.showSprite.spriteFrame = this.rotateJump;
  34. this.showSprite.node.scaleX = -1;
  35. }
  36. }
  37. setBTrigger() {
  38. this.bTrigger = !this.bTrigger;
  39. let _opacity = this.bTrigger ? 125 : 255;
  40. this.node.opacity = _opacity;
  41. }
  42. // update (dt) {}
  43. }