FStoenRoll.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import FF from "../../FF";
  2. import FSprite from "../../object/FSprite";
  3. /**
  4. * 滚动的石头
  5. */
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class FStoenRoll extends cc.Component {
  9. @property({
  10. displayName: '数值(怪物id)'
  11. })
  12. public monsterId = 1001;
  13. @property({
  14. displayName: '起点到终点时间(秒)'
  15. })
  16. public time = 2;
  17. @property({
  18. displayName: '每次滚动停留时间(秒)'
  19. })
  20. public interval = 2;
  21. @property({
  22. type: cc.Node,
  23. displayName: '滚动目的地'
  24. })
  25. public target: cc.Node = null;
  26. @property({
  27. type: sp.Skeleton,
  28. displayName: '滚动动画'
  29. })
  30. public spine: sp.Skeleton = null;
  31. @property({
  32. displayName: "警告",
  33. type: cc.Node
  34. })
  35. warnNode: cc.Node = null;
  36. private initPos: cc.Vec2;
  37. private targetPos: cc.Vec2;
  38. private ff: FF;
  39. private isRoll = false;
  40. onLoad() {
  41. this.initPos = this.node.getPosition();
  42. this.targetPos = this.target.getPosition();
  43. cc.tween(this.node).sequence(
  44. cc.delayTime(this.interval),
  45. cc.callFunc(() => {
  46. this.node.getComponent(cc.RigidBody).enabledContactListener = true;
  47. this.node.getComponent(cc.RigidBody).allowSleep = false;
  48. this.node.opacity = 255;
  49. this.node.setPosition(this.initPos);
  50. this.isRoll = true;
  51. this.warnAction();
  52. }),
  53. cc.moveBy(this.time, this.targetPos),
  54. cc.callFunc(() => {
  55. this.node.getComponent(cc.RigidBody).allowSleep = true;
  56. this.isRoll = false;
  57. if(this.warnNode){
  58. this.warnNode.stopAllActions();
  59. this.warnNode.opacity = 0;
  60. }
  61. }),
  62. cc.fadeOut(0.5),
  63. cc.callFunc(() => {
  64. this.node.getComponent(cc.RigidBody).enabledContactListener = false;
  65. }),
  66. ).repeatForever().start();
  67. }
  68. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  69. // if(!this.isRoll){
  70. // return;
  71. // }
  72. if (other.node.group == 'A'&& other.tag == 1) {
  73. let obj = other.node.getComponent(FSprite);
  74. if (obj.hp > 0) {
  75. this.ff = obj.ff;
  76. let main = this.ff.main;
  77. let attrData = main.sManage.getMonsterData(this.monsterId);
  78. // this.sprite.atkjs(target);
  79. obj.bAtkjs(attrData);
  80. }
  81. }
  82. }
  83. warnAction() {
  84. if(this.warnNode){
  85. this.warnNode.opacity = 0;
  86. cc.tween(this.warnNode).sequence(
  87. cc.fadeTo(0.2, 120),
  88. cc.fadeTo(0.2, 0),
  89. ).repeatForever().start();
  90. }
  91. }
  92. }