idle.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // 静止
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. loc: 0, // 代表方向,0为正位,1为反位
  6. },
  7. // LIFE-CYCLE CALLBACKS:
  8. onLoad () {
  9. // 配置绘制的数据
  10. // 从配置中心获取数据
  11. this.config = require ("gameconfig")
  12. // 配置绘制组件
  13. this.g = this.getComponent(cc.Graphics);
  14. // 配置方向
  15. if (this.loc == 0) {
  16. this.dir = -1;
  17. } else {
  18. this.dir = 1;
  19. }
  20. },
  21. start () {
  22. },
  23. // update (dt) {},
  24. idle:function() {
  25. this.g.clear();
  26. // 画脑袋和身体
  27. this.g.lineWidth = this.config.CIRCLE_WIDTH
  28. // 画个脑袋
  29. this.g.fillColor.fromHEX('#ffffff');
  30. this.g.circle(-1.5 * this.dir, 110, this.config.HEAD_SIZE);
  31. this.g.close();
  32. this.g.stroke();
  33. this.g.fill();
  34. // 画个身体
  35. this.g.fillColor.fromHEX('#ffffff');
  36. this.g.circle(8 * this.dir, 85, this.config.BODY_SIZE);
  37. this.g.close();
  38. this.g.stroke();
  39. this.g.fill();
  40. // 画手臂
  41. var handStart = cc.v2(-7 * this.dir, 86);
  42. var handEnd = cc.v2(handStart.x - this.dir * 10, handStart.y - 47);
  43. this.g.lineWidth = this.config.LINE_WIDTH;
  44. this.g.moveTo(handStart.x, handStart.y);
  45. this.g.bezierCurveTo(handStart.x, handStart.y, handStart.x, handStart.y - 40, handEnd.x, handEnd.y);
  46. this.g.stroke();
  47. // 画个球拍
  48. this.g.lineWidth = this.config.CIRCLE_WIDTH
  49. this.g.fillColor.fromHEX('#ffffff');
  50. this.g.circle(handEnd.x - this.dir * 3, handEnd.y + 4, this.config.BAT_SIZE);
  51. this.g.close();
  52. this.g.stroke();
  53. this.g.fill();
  54. // 画手臂
  55. var handStart = cc.v2(13 * this.dir, 99);
  56. var handEnd = cc.v2(handStart.x + this.dir * 51, handStart.y - 18);
  57. this.g.lineWidth = this.config.LINE_WIDTH;
  58. this.g.moveTo(handStart.x, handStart.y);
  59. this.g.bezierCurveTo(handStart.x, handStart.y, handStart.x + this.dir * 27, handStart.y + 10, handEnd.x, handEnd.y);
  60. this.g.stroke();
  61. // 画裤子
  62. var trousersStart = cc.v2(0, 74);
  63. var trousersEnd = cc.v2(22 * this.dir, 79);
  64. this.g.moveTo(trousersStart.x, trousersStart.y);
  65. this.g.lineTo(trousersEnd.x, trousersEnd.y);
  66. this.g.stroke();
  67. // 画腿
  68. var legStart = cc.v2(10 * this.dir, 73);
  69. var legEnd = cc.v2(0, 0)
  70. this.g.moveTo(legStart.x, legStart.y);
  71. this.g.bezierCurveTo(legStart.x, legStart.y, -10 * this.dir, 60, legEnd.x, legEnd.y);
  72. this.g.lineTo(legEnd.x - this.dir * 6, legEnd.y);
  73. this.g.stroke();
  74. legStart = cc.v2(19 * this.dir, 78);
  75. legEnd = cc.v2(62 * this.dir, 0)
  76. this.g.moveTo(legStart.x, legStart.y);
  77. this.g.lineTo(legEnd.x, legEnd.y);
  78. this.g.lineTo(legEnd.x + this.dir * 6, legEnd.y);
  79. this.g.stroke();
  80. },
  81. });