rivalpeelrtor.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // 对手削球,从右侧到右侧
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. },
  6. // LIFE-CYCLE CALLBACKS:
  7. onLoad () {
  8. this.initValues();
  9. this.initNodes();
  10. },
  11. start () {
  12. this.initActions();
  13. },
  14. // 初始化
  15. initValues:function () {
  16. // 配置绘制的数据
  17. // 从配置中心获取数据
  18. this.config = require ("gameconfig")
  19. // 配置绘制组件
  20. this.g = this.getComponent(cc.Graphics);
  21. // 记录下节点
  22. this.poses = new Array();
  23. this.beginPos = cc.v2(-95, 263);
  24. this.centerPos = cc.v2(-75, 58);
  25. this.endPos = cc.v2(-66, -163);
  26. },
  27. // 初始化子节点
  28. initNodes:function() {
  29. this.head = new cc.Node("");
  30. this.head.setPosition(this.beginPos);
  31. this.head.parent = this.node;
  32. },
  33. // 初始化头部节点的运动
  34. initActions:function() {
  35. var bezier_01 = [this.beginPos, cc.v2(-230, 410), this.centerPos];
  36. var move_01 = cc.bezierTo(1, bezier_01);
  37. var move_01_End = cc.callFunc(this.move_01_End, this);
  38. var bezier_02 = [this.centerPos, cc.v2(-125, 40), this.endPos];
  39. var move_02 = cc.bezierTo(1, bezier_02);
  40. var move_02_End = cc.callFunc(this.move_02_End, this);
  41. this.head.runAction(cc.sequence(move_01, move_01_End, move_02, move_02_End));
  42. },
  43. // 第一步动作结束
  44. move_01_End:function() {
  45. cc.log ("Move 01 End ... ")
  46. },
  47. // 第二部动作结束
  48. move_02_End:function() {
  49. cc.log ("Move 02 End ... ")
  50. },
  51. // 外部调用
  52. ballStop:function() {
  53. },
  54. //
  55. // 绘图
  56. draw:function() {
  57. this.g.clear();
  58. // 画脑袋和身体
  59. this.g.lineWidth = this.config.CIRCLE_WIDTH
  60. // 画个头部
  61. this.g.fillColor.fromHEX('#ff00000');
  62. this.g.circle(this.head.x, this.head.y, this.config.HEAD_SIZE);
  63. this.g.close();
  64. this.g.stroke();
  65. this.g.fill();
  66. var pos = this.poses[0];
  67. this.g.lineWidth = 3;
  68. this.g.moveTo(pos.x, pos.y)
  69. for (var i = 0; i < this.poses.length; i++) {
  70. var getPos = this.poses[i];
  71. this.g.lineTo(getPos.x, getPos.y);
  72. }
  73. this.g.stroke();
  74. },
  75. update (dt) {
  76. // 记录当前的位置
  77. var news = [this.head.position];
  78. // 在结合当前的数组
  79. this.poses = news.concat(this.poses);
  80. // 如果数组长度大于20,则将最后一个删除
  81. if (this.poses.length > 20) {
  82. this.poses.pop();
  83. }
  84. this.draw();
  85. },
  86. });