123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- // 球碰到桌子
- cc.Class({
- extends: cc.Component,
- properties: {
- g: {
- default: null,
- type: cc.Graphics,
- },
- },
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {},
- start () {
- },
- // 球磕碰
- bump:function(loc) {
- this.bumpLoc = loc;
- this.bumpTime = 0;
- this.schedule(this.bumpUpdate, 1 / 60.0);
- },
- // 磕碰动画
- bumpUpdate:function(delay) {
- this.g.clear();
- this.bumpTime += delay;
- var timeScale = 15;
- var space = 1;
- var low = 2.5;
- var high = 10;
- // 右上
- this.g.lineWidth = 3;
- this.g.moveTo(this.bumpLoc.x + space + this.bumpTime * timeScale * low, this.bumpLoc.y + space + this.bumpTime * timeScale * low);
- this.g.lineTo(this.bumpLoc.x + space + this.bumpTime * timeScale * high, this.bumpLoc.y + space + this.bumpTime * timeScale * high)
- this.g.stroke();
- // 右下
- this.g.lineWidth = 3;
- this.g.moveTo(this.bumpLoc.x + space + this.bumpTime * timeScale * low, this.bumpLoc.y - space - this.bumpTime * timeScale * low);
- this.g.lineTo(this.bumpLoc.x + space + this.bumpTime * timeScale * high, this.bumpLoc.y - space - this.bumpTime * timeScale * high)
- this.g.stroke();
- // 左上
- this.g.lineWidth = 3;
- this.g.moveTo(this.bumpLoc.x - space - this.bumpTime * timeScale * low, this.bumpLoc.y + space + this.bumpTime * timeScale * low);
- this.g.lineTo(this.bumpLoc.x - space - this.bumpTime * timeScale * high, this.bumpLoc.y + space + this.bumpTime * timeScale * high)
- this.g.stroke();
- // 右下
- this.g.lineWidth = 3;
- this.g.moveTo(this.bumpLoc.x - space - this.bumpTime * timeScale * low, this.bumpLoc.y - space - this.bumpTime * timeScale * low);
- this.g.lineTo(this.bumpLoc.x - space - this.bumpTime * timeScale * high, this.bumpLoc.y - space - this.bumpTime * timeScale * high)
- this.g.stroke();
- if (this.bumpTime > 0.1) {
- this.unschedule(this.bumpUpdate);
- }
- },
- });
|