// 拍球的动作 cc.Class({ extends: cc.Component, properties: { loc: 0, // 代表方向,0为正位,1为反位 }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start () { // 配置绘制的数据 // 从配置中心获取数据 this.config = require ("gameconfig") // 配置绘制组件 this.g = this.getComponent(cc.Graphics); // 配置方向 if (this.loc == 0) { this.dir = -1; } else { this.dir = 1; } // this.dir = -1; // this.pat_001(); this.index = 1; }, // update (dt) {}, pat:function() { this.schedule(this.patUpdate, 1.0 / 15); }, // 停止 stop:function() { this.index = 1; this.unschedule(this.patUpdate); }, patUpdate:function(delay) { this.g.clear(); if (this.index > 7) { this.index = 1; this.unschedule(this.patUpdate); if (this.actionEnd != null) { this.actionEnd(); } return; } if (this.index == 1) { this.pat_001(); } else if (this.index == 2) { this.pat_002(); } else if (this.index == 3) { this.pat_003(); } else if (this.index == 4) { this.pat_004(); } else if (this.index == 5) { this.pat_005(); } else if (this.index == 6) { this.pat_006(); } else if (this.index == 7) { this.pat_007(); } this.index++; }, pat_001:function() { // 画脑袋 this.g.lineWidth = this.config.LINE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); this.g.arc(this.dir * 1, 112, this.config.HEAD_SIZE + 2, Math.PI / 2 - this.dir * Math.PI / 12, Math.PI * 1.5 - this.dir * Math.PI / 12, this.dir == 1); this.g.lineTo(this.dir *12, 105); this.g.arc(this.dir *13, 111, this.config.HEAD_SIZE + 2, Math.PI * 1.5 - this.dir * Math.PI / 12, Math.PI / 2 - this.dir * Math.PI / 12, this.dir == 1); this.g.lineTo(this.dir *2, 118); // 画个身体 this.g.lineWidth = this.config.CIRCLE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); this.g.circle(this.dir * 21, 81, this.config.BODY_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画手臂 var handStart = cc.v2(this.dir * 9, 89); var handEnd = cc.v2(handStart.x - this.dir * 52, handStart.y + 7); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, handStart.x - this.dir * 30, handStart.y + 28, handEnd.x, handEnd.y); this.g.stroke(); // 画个球拍 this.g.lineWidth = this.config.LINE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); if (this.loc == 0) { this.g.arc(this.dir * -41, 105, this.config.BAT_SIZE + 2, 0 + Math.PI / 12, Math.PI + Math.PI / 12, true); } else { this.g.arc(this.dir * -41, 105, this.config.BAT_SIZE + 2, Math.PI - Math.PI / 12, 0 - Math.PI / 12, false); } this.g.bezierCurveTo(this.dir * -37, 104, this.dir * -47, 80, this.dir * -24, 53); if (this.loc == 0) { this.g.arc(this.dir * -28, 51, this.config.BAT_SIZE + 2, Math.PI - Math.PI / 12, Math.PI * 1.5 + Math.PI / 12, true); } else { this.g.arc(this.dir * -28, 51, this.config.BAT_SIZE + 2, 0 + Math.PI / 12, Math.PI * 1.5 - Math.PI / 12, false); } this.g.bezierCurveTo(this.dir * -30, 46, this.dir * -60, 75, this.dir * -45, 106); // this.g.close(); this.g.stroke(); // 画手臂 var handStart = cc.v2(this.dir * 35, 84); var handEnd = cc.v2(this.dir * 76, 61); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * 58, 55, handEnd.x, handEnd.y); this.g.stroke(); // 画裤子 var trousersStart = cc.v2(this.dir * 11, 73); var trousersEnd = cc.v2(this.dir * 33, 73); this.g.moveTo(trousersStart.x, trousersStart.y); this.g.lineTo(trousersEnd.x, trousersEnd.y); this.g.stroke(); // 画腿 var legStart = cc.v2(this.dir * 12, 70); var legEnd = cc.v2(0, 0) this.g.moveTo(legStart.x, legStart.y); this.g.bezierCurveTo(legStart.x, legStart.y, this.dir * -15, 60, legEnd.x, legEnd.y); this.g.lineTo(legEnd.x - this.dir * 10, legEnd.y); this.g.stroke(); legStart = cc.v2(this.dir * 31, 69); legEnd = cc.v2(this.dir * 64, 2) this.g.moveTo(legStart.x, legStart.y); this.g.bezierCurveTo(legStart.x, legStart.y, legStart.x + this.dir * 20, legStart.y - 10, legEnd.x, legEnd.y); this.g.lineTo(legEnd.x + this.dir * 10, legEnd.y); this.g.stroke(); }, pat_002:function() { // 画脑袋 this.g.lineWidth = this.config.LINE_WIDTH; // 画手臂 var handStart = cc.v2(this.dir * 32, 89); var handEnd = cc.v2(this.dir * 39, 139); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * 10, 125, handEnd.x, handEnd.y); this.g.stroke(); this.g.fillColor.fromHEX('#ffffff'); this.g.arc(this.dir * 27, 109, this.config.HEAD_SIZE, Math.PI / 2 - this.dir * Math.PI / 12, Math.PI * 1.5 - this.dir * Math.PI / 12, this.dir == 1); this.g.lineTo(this.dir * 45, 102); this.g.arc(this.dir * 45, 106, this.config.HEAD_SIZE, Math.PI * 1.5 - this.dir * Math.PI / 12, Math.PI / 2 - this.dir * Math.PI / 12, this.dir == 1); this.g.lineTo(this.dir * 27, 113); // 画个身体 this.g.lineWidth = this.config.CIRCLE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); this.g.circle(this.dir * 41, 82, this.config.BODY_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画个球拍 this.g.lineWidth = this.config.LINE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); if (this.loc == 0) { this.g.arc(32, 124, this.config.BAT_SIZE + 2, Math.PI / 2, Math.PI * 1.5, false); } else { this.g.arc(-32, 124, this.config.BAT_SIZE + 2, Math.PI - Math.PI / 4, Math.PI * 1.5 + Math.PI / 8, true); } this.g.bezierCurveTo(this.dir * -31, 123, 0, 155, this.dir * 40, 134); if (this.loc == 0) { this.g.arc(-40, 138, this.config.BAT_SIZE + 2, Math.PI * 1.5 + Math.PI / 8, Math.PI / 2 + Math.PI / 4, false); } else { this.g.arc(42, 138, this.config.BAT_SIZE + 2, Math.PI * 1.5 - Math.PI / 8, Math.PI / 2 + Math.PI / 8, true); } this.g.bezierCurveTo(this.dir * 45, 142, 0, 162, this.dir * -37, 128); // // this.g.close(); this.g.stroke(); // 画手臂 var handStart = cc.v2(this.dir * 52, 72); var handEnd = cc.v2(this.dir * 53, 25); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * 45, 55, handEnd.x, handEnd.y); this.g.stroke(); // 画裤子 var trousersStart = cc.v2(this.dir * 29, 78); var trousersEnd = cc.v2(this.dir * 51, 69); this.g.moveTo(trousersStart.x, trousersStart.y); this.g.lineTo(trousersEnd.x, trousersEnd.y); this.g.stroke(); // 画腿 var legStart = cc.v2(this.dir * 32, 71); var legEnd = cc.v2(0, 0) this.g.moveTo(legStart.x, legStart.y); this.g.bezierCurveTo(legStart.x, legStart.y, this.dir * 10, 38, legEnd.x, legEnd.y); this.g.lineTo(legEnd.x - this.dir * 6, legEnd.y); this.g.stroke(); legStart = cc.v2(this.dir * 43, 67); legEnd = cc.v2(this.dir * 64, 2) this.g.moveTo(legStart.x, legStart.y); this.g.bezierCurveTo(legStart.x, legStart.y, this.dir * 62, 55, legEnd.x, legEnd.y); this.g.lineTo(legEnd.x + this.dir * 6, legEnd.y); this.g.stroke(); }, pat_003:function() { // 画脑袋 this.g.lineWidth = this.config.LINE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); // this.g.ellipse(18, 116, 15, 5); this.g.arc(this.dir * 53, 104, this.config.HEAD_SIZE + 1, Math.PI / 2 - this.dir * Math.PI / 12, Math.PI * 1.5 - this.dir * Math.PI / 8, this.dir == 1); this.g.lineTo(this.dir * 65, 96); this.g.arc(this.dir * 66, 101, this.config.HEAD_SIZE + 1, Math.PI * 1.5 - this.dir * Math.PI / 8, Math.PI / 2 - this.dir * Math.PI / 8, this.dir == 1); this.g.lineTo(this.dir * 49, 110);; // 画个身体 this.g.lineWidth = this.config.CIRCLE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); this.g.circle(this.dir * 54, 78, this.config.BODY_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画手臂 var handStart = cc.v2(this.dir * 45, 89); var handEnd = cc.v2(this.dir * 70, 135); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * 20, 128, handEnd.x, handEnd.y); this.g.stroke(); // 画个球 this.g.lineWidth = this.config.CIRCLE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); this.g.circle(handEnd.x - this.dir * 1, handEnd.y - 5, this.config.BAT_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画手臂 var handStart = cc.v2(this.dir * 55, 63); var handEnd = cc.v2(this.dir * 56, 30); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * 40, 40, handEnd.x, handEnd.y); // this.g.lineTo(handEnd.x, handEnd.y); this.g.stroke(); // 画裤子 var trousersStart = cc.v2(this.dir * 41, 73); var trousersEnd = cc.v2(this.dir * 63, 66); this.g.moveTo(trousersStart.x, trousersStart.y); this.g.lineTo(trousersEnd.x, trousersEnd.y); this.g.stroke(); // 画腿 var legStart = cc.v2(this.dir * 44, 67); var legEnd = cc.v2(0, 0) this.g.moveTo(legStart.x, legStart.y); this.g.bezierCurveTo(legStart.x, legStart.y, this.dir * 30, 52, legEnd.x, legEnd.y); this.g.lineTo(legEnd.x - this.dir * 6, legEnd.y); this.g.stroke(); legStart = cc.v2(this.dir * 57, 64); legEnd = cc.v2(this.dir * 63, 1) this.g.moveTo(legStart.x, legStart.y); this.g.bezierCurveTo(legStart.x, legStart.y, legStart.x + this.dir * 40, legStart.y - 15, legEnd.x, legEnd.y); this.g.lineTo(legEnd.x + this.dir * 6, legEnd.y); this.g.stroke(); }, pat_004:function() { // 画脑袋 this.g.lineWidth = this.config.CIRCLE_WIDTH; // 画个脑袋 this.g.fillColor.fromHEX('#ffffff'); this.g.circle(this.dir * 84, 92, this.config.HEAD_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画个身体 this.g.lineWidth = this.config.CIRCLE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); this.g.circle(this.dir * 66, 73, this.config.BODY_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画手臂 var handStart = cc.v2(this.dir * 67, 88); var handEnd = cc.v2(this.dir * 105, 90); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * 94, 125, handEnd.x, handEnd.y); this.g.stroke(); // 画个球拍 this.g.lineWidth = this.config.CIRCLE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); this.g.circle(handEnd.x - this.dir * 4, handEnd.y - 5, this.config.BAT_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画手臂 var handStart = cc.v2(this.dir * 68, 59); var handEnd = cc.v2(this.dir * 60, 33); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * 50, 40, handEnd.x, handEnd.y); // this.g.lineTo(handEnd.x, handEnd.y); this.g.stroke(); // 画裤子 var trousersStart = cc.v2(this.dir * 51, 72); var trousersEnd = cc.v2(this.dir * 70, 60); this.g.moveTo(trousersStart.x, trousersStart.y); this.g.lineTo(trousersEnd.x, trousersEnd.y); this.g.stroke(); // 画腿 var legStart = cc.v2(this.dir * 53, 66); var legEnd = cc.v2(0, 0) this.g.moveTo(legStart.x, legStart.y); this.g.lineTo(legEnd.x, legEnd.y); this.g.stroke(); legStart = cc.v2(this.dir * 68, 57); legEnd = cc.v2(this.dir * 63, 1) this.g.moveTo(legStart.x, legStart.y); this.g.bezierCurveTo(legStart.x, legStart.y, legStart.x + this.dir * 38, legStart.y - 18, legEnd.x, legEnd.y); this.g.lineTo(legEnd.x + this.dir * 6, legEnd.y); this.g.stroke(); }, pat_005:function() { // 画脑袋 this.g.lineWidth = this.config.CIRCLE_WIDTH; // 画个脑袋 this.g.fillColor.fromHEX('#ffffff'); this.g.circle(this.dir * 60, 86, this.config.HEAD_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画个身体 this.g.lineWidth = this.config.CIRCLE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); this.g.circle(this.dir * 43, 66, this.config.BODY_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画手臂 var handStart = cc.v2(this.dir * 37, 78); var handEnd = cc.v2(this.dir * 62, 110); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * 20, 120, handEnd.x, handEnd.y); this.g.stroke(); // 画个球拍 this.g.lineWidth = this.config.CIRCLE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); this.g.circle(handEnd.x - this.dir * 4, handEnd.y - 5, this.config.BAT_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画手臂 var handStart = cc.v2(this.dir * 56, 61); var handEnd = cc.v2(this.dir * 80, 25); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * 70, 32, handEnd.x, handEnd.y); // this.g.lineTo(handEnd.x, handEnd.y); this.g.stroke(); // 画裤子 var trousersStart = cc.v2(this.dir * 28, 61); var trousersEnd = cc.v2(this.dir * 53, 55); this.g.moveTo(trousersStart.x, trousersStart.y); this.g.lineTo(trousersEnd.x, trousersEnd.y); this.g.stroke(); // 画腿 var legStart = cc.v2(this.dir * 33, 54); var legEnd = cc.v2(this.dir * 6, 0) this.g.moveTo(legStart.x, legStart.y); this.g.bezierCurveTo(legStart.x, legStart.y, this.dir * -15, 52, legEnd.x, legEnd.y); this.g.lineTo(0, 0); this.g.stroke(); legStart = cc.v2(this.dir * 51, 52); legEnd = cc.v2(this.dir * 68, 1) this.g.moveTo(legStart.x, legStart.y); this.g.bezierCurveTo(legStart.x, legStart.y, legStart.x + this.dir * 38, legStart.y - 18, legEnd.x, legEnd.y); this.g.lineTo(legEnd.x + this.dir * 6, legEnd.y); this.g.stroke(); }, pat_006:function() { // 画脑袋 this.g.lineWidth = this.config.LINE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); // this.g.ellipse(18, 116, 15, 5); this.g.arc(this.dir * 37, 104, this.config.HEAD_SIZE + 2, Math.PI / 2 - this.dir * Math.PI / 8, Math.PI * 1.5 - this.dir * Math.PI / 8, this.dir == 1); this.g.lineTo(this.dir * 44, 96); this.g.arc(this.dir * 46, 101, this.config.HEAD_SIZE + 2, Math.PI * 1.5 - this.dir * Math.PI / 8, Math.PI / 2 - this.dir * Math.PI / 8, this.dir == 1); this.g.lineTo(this.dir * 38, 110); // // this.g.close(); // // this.g.stroke(); // // this.g.fill(); // 画个身体 this.g.lineWidth = this.config.CIRCLE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); this.g.circle(this.dir * 32, 78, this.config.BODY_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画手臂 var handStart = cc.v2(this.dir * 23, 88); var handEnd = cc.v2(this.dir * -12, 127); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * -23, 95, handEnd.x, handEnd.y); this.g.stroke(); // 画个球拍 this.g.lineWidth = this.config.CIRCLE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); this.g.circle(handEnd.x + this.dir * 5, handEnd.y - 1, this.config.BAT_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画手臂 var handStart = cc.v2(this.dir * 46, 81); var handEnd = cc.v2(this.dir * 76, 49); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * 75, 82, handEnd.x, handEnd.y); // this.g.lineTo(handEnd.x, handEnd.y); this.g.stroke(); // 画裤子 var trousersStart = cc.v2(this.dir * 19, 71); var trousersEnd = cc.v2(this.dir * 42, 67); this.g.moveTo(trousersStart.x, trousersStart.y); this.g.lineTo(trousersEnd.x, trousersEnd.y); this.g.stroke(); // 画腿 var legStart = cc.v2(this.dir * 22, 66); var legEnd = cc.v2(this.dir * 6, 0) this.g.moveTo(legStart.x, legStart.y); this.g.bezierCurveTo(legStart.x, legStart.y, this.dir * -10, 52, legEnd.x, legEnd.y); this.g.lineTo(0, 0); this.g.stroke(); legStart = cc.v2(this.dir * 38, 64); legEnd = cc.v2(this.dir * 68, 1) this.g.moveTo(legStart.x, legStart.y); this.g.bezierCurveTo(legStart.x, legStart.y, this.dir * 65, 55, legEnd.x, legEnd.y); this.g.lineTo(legEnd.x + this.dir * 6, legEnd.y); this.g.stroke(); }, pat_007:function() { // 画脑袋 this.g.lineWidth = this.config.LINE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); this.g.arc(this.dir * -4, 111.5, this.config.HEAD_SIZE, Math.PI / 2, Math.PI * 1.5, this.dir == 1); this.g.lineTo(this.dir * 8, 106.5); this.g.arc(this.dir * 7, 111.5, this.config.HEAD_SIZE, Math.PI * 1.5 , Math.PI / 2, this.dir == 1); this.g.lineTo(this.dir * -4, 116); // 画个身体 this.g.lineWidth = this.config.CIRCLE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); this.g.circle(this.dir * 7, 87, this.config.BODY_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画手臂 var handStart = cc.v2(this.dir * -8, 87); var handEnd = cc.v2(this.dir * -32, 45); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * -15, 55, handEnd.x, handEnd.y); this.g.stroke(); // 画个球拍 this.g.lineWidth = this.config.CIRCLE_WIDTH; this.g.fillColor.fromHEX('#ffffff'); this.g.circle(handEnd.x + this.dir * 1, handEnd.y + 6, this.config.BAT_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画手臂 var handStart = cc.v2(this.dir * 16, 99); var handEnd = cc.v2(this.dir * 65, 83); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * 45, 110, handEnd.x, handEnd.y); // this.g.lineTo(handEnd.x, handEnd.y); this.g.stroke(); // 画裤子 var trousersStart = cc.v2(this.dir * -3, 75); var trousersEnd = cc.v2(this.dir * 23, 85); this.g.moveTo(trousersStart.x, trousersStart.y); this.g.lineTo(trousersEnd.x, trousersEnd.y); this.g.stroke(); // 画腿 var legStart = cc.v2(this.dir * 8, 72); var legEnd = cc.v2(0, 0) this.g.moveTo(legStart.x, legStart.y); this.g.bezierCurveTo(legStart.x, legStart.y, this.dir * -15, 56, legEnd.x, legEnd.y); this.g.lineTo(this.dir * -6, 0); this.g.stroke(); legStart = cc.v2(this.dir * 18, 77); legEnd = cc.v2(this.dir * 63, 1) this.g.moveTo(legStart.x, legStart.y); this.g.lineTo(legEnd.x, legEnd.y) this.g.lineTo(legEnd.x + this.dir * 6, legEnd.y); this.g.stroke(); }, });