123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- // 对手削球,从右侧到右侧
- cc.Class({
- extends: cc.Component,
- properties: {
-
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.initValues();
- this.initNodes();
- },
- start () {
- this.initActions();
- },
- // 初始化
- initValues:function () {
- // 配置绘制的数据
- // 从配置中心获取数据
- this.config = require ("gameconfig")
- // 配置绘制组件
- this.g = this.getComponent(cc.Graphics);
- // 记录下节点
- this.poses = new Array();
- this.beginPos = cc.v2(-95, 263);
- this.centerPos = cc.v2(-75, 58);
- this.endPos = cc.v2(-66, -163);
- },
- // 初始化子节点
- initNodes:function() {
- this.head = new cc.Node("");
- this.head.setPosition(this.beginPos);
- this.head.parent = this.node;
- },
- // 初始化头部节点的运动
- initActions:function() {
- var bezier_01 = [this.beginPos, cc.v2(-230, 410), this.centerPos];
- var move_01 = cc.bezierTo(1, bezier_01);
- var move_01_End = cc.callFunc(this.move_01_End, this);
- var bezier_02 = [this.centerPos, cc.v2(-125, 40), this.endPos];
- var move_02 = cc.bezierTo(1, bezier_02);
- var move_02_End = cc.callFunc(this.move_02_End, this);
- this.head.runAction(cc.sequence(move_01, move_01_End, move_02, move_02_End));
- },
- // 第一步动作结束
- move_01_End:function() {
- cc.log ("Move 01 End ... ")
- },
- // 第二部动作结束
- move_02_End:function() {
- cc.log ("Move 02 End ... ")
- },
- // 外部调用
- ballStop:function() {
- },
- //
- // 绘图
- draw:function() {
- this.g.clear();
- // 画脑袋和身体
- this.g.lineWidth = this.config.CIRCLE_WIDTH
- // 画个头部
- this.g.fillColor.fromHEX('#ff00000');
- this.g.circle(this.head.x, this.head.y, this.config.HEAD_SIZE);
- this.g.close();
- this.g.stroke();
- this.g.fill();
-
- var pos = this.poses[0];
- this.g.lineWidth = 3;
- this.g.moveTo(pos.x, pos.y)
- for (var i = 0; i < this.poses.length; i++) {
- var getPos = this.poses[i];
- this.g.lineTo(getPos.x, getPos.y);
- }
- this.g.stroke();
- },
- update (dt) {
- // 记录当前的位置
- var news = [this.head.position];
- // 在结合当前的数组
- this.poses = news.concat(this.poses);
- // 如果数组长度大于20,则将最后一个删除
- if (this.poses.length > 20) {
- this.poses.pop();
- }
- this.draw();
- },
- });
|