// 胜利的动作 cc.Class({ extends: cc.Component, properties: { loc: 0, // 代表方向,0为正位,1为反位 }, // LIFE-CYCLE CALLBACKS: onLoad () { // 配置绘制的数据 // 从配置中心获取数据 this.config = require ("gameconfig") // 配置绘制组件 this.g = this.getComponent(cc.Graphics); // 配置方向 if (this.loc == 0) { this.dir = 1; } else { this.dir = -1; } }, start () { }, win:function() { this.g.clear(); // 画脑袋和身体 this.g.lineWidth = this.config.CIRCLE_WIDTH // 画个脑袋 this.g.fillColor.fromHEX('#ffffff'); this.g.circle(this.dir * -42, 77, this.config.HEAD_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画个身体 this.g.fillColor.fromHEX('#ffffff'); this.g.circle(this.dir * -31, 51, this.config.BODY_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画手臂 var handStart = cc.v2(this.dir * -21, 63); var handEnd = cc.v2(this.dir * -23, 109); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * -7, 82, handEnd.x, handEnd.y); this.g.stroke(); // 画个球拍 this.g.lineWidth = this.config.CIRCLE_WIDTH this.g.fillColor.fromHEX('#ffffff'); this.g.circle(this.dir * -28, 105, this.config.BAT_SIZE); this.g.close(); this.g.stroke(); this.g.fill(); // 画手臂 var handStart = cc.v2(this.dir * -45, 56); var handEnd = cc.v2(this.dir * -65, 102); this.g.lineWidth = this.config.LINE_WIDTH; this.g.moveTo(handStart.x, handStart.y); this.g.bezierCurveTo(handStart.x, handStart.y, this.dir * -70, 65, handEnd.x, handEnd.y); this.g.stroke(); // 画裤子 var trousersStart = cc.v2(this.dir * -41, 41); var trousersEnd = cc.v2(this.dir * -19, 45); this.g.moveTo(trousersStart.x, trousersStart.y); this.g.lineTo(trousersEnd.x, trousersEnd.y); this.g.stroke(); // 画腿 var legStart = cc.v2(this.dir * -39, 40); var legEnd = cc.v2(this.dir * -61, 0) this.g.moveTo(legStart.x, legStart.y); this.g.bezierCurveTo(legStart.x, legStart.y, this.dir * -95, 50, legEnd.x, legEnd.y); this.g.lineTo(this.dir * -67, 0); this.g.stroke(); legStart = cc.v2(this.dir * -20, 42); legEnd = cc.v2(this.dir * 8, 0) this.g.moveTo(legStart.x, legStart.y); this.g.bezierCurveTo(legStart.x, legStart.y, this.dir * 12, 45, legEnd.x, legEnd.y); this.g.lineTo(this.dir * 18, 0); this.g.stroke(); // 再跳动两下 var jump = cc.jumpBy(0.5, cc.v2(0, 0), 20, 3); this.node.runAction(jump); }, });