bump.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // 球碰到桌子
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. g: {
  6. default: null,
  7. type: cc.Graphics,
  8. },
  9. },
  10. // LIFE-CYCLE CALLBACKS:
  11. // onLoad () {},
  12. start () {
  13. },
  14. // 球磕碰
  15. bump:function(loc) {
  16. this.bumpLoc = loc;
  17. this.bumpTime = 0;
  18. this.schedule(this.bumpUpdate, 1 / 60.0);
  19. },
  20. // 磕碰动画
  21. bumpUpdate:function(delay) {
  22. this.g.clear();
  23. this.bumpTime += delay;
  24. var timeScale = 15;
  25. var space = 1;
  26. var low = 2.5;
  27. var high = 10;
  28. // 右上
  29. this.g.lineWidth = 3;
  30. this.g.moveTo(this.bumpLoc.x + space + this.bumpTime * timeScale * low, this.bumpLoc.y + space + this.bumpTime * timeScale * low);
  31. this.g.lineTo(this.bumpLoc.x + space + this.bumpTime * timeScale * high, this.bumpLoc.y + space + this.bumpTime * timeScale * high)
  32. this.g.stroke();
  33. // 右下
  34. this.g.lineWidth = 3;
  35. this.g.moveTo(this.bumpLoc.x + space + this.bumpTime * timeScale * low, this.bumpLoc.y - space - this.bumpTime * timeScale * low);
  36. this.g.lineTo(this.bumpLoc.x + space + this.bumpTime * timeScale * high, this.bumpLoc.y - space - this.bumpTime * timeScale * high)
  37. this.g.stroke();
  38. // 左上
  39. this.g.lineWidth = 3;
  40. this.g.moveTo(this.bumpLoc.x - space - this.bumpTime * timeScale * low, this.bumpLoc.y + space + this.bumpTime * timeScale * low);
  41. this.g.lineTo(this.bumpLoc.x - space - this.bumpTime * timeScale * high, this.bumpLoc.y + space + this.bumpTime * timeScale * high)
  42. this.g.stroke();
  43. // 右下
  44. this.g.lineWidth = 3;
  45. this.g.moveTo(this.bumpLoc.x - space - this.bumpTime * timeScale * low, this.bumpLoc.y - space - this.bumpTime * timeScale * low);
  46. this.g.lineTo(this.bumpLoc.x - space - this.bumpTime * timeScale * high, this.bumpLoc.y - space - this.bumpTime * timeScale * high)
  47. this.g.stroke();
  48. if (this.bumpTime > 0.1) {
  49. this.unschedule(this.bumpUpdate);
  50. }
  51. },
  52. });