let orig = { x: this.x, y: this.y }; var dir = 1; var tox = 0; var toy = 0; var count = 40; // if (null != _Timer) egret.clearInterval(this.m_Timer); var timer = egret.setInterval( () => { count-- dir = 0.5 < Math.random() ? -1 : 1; tox = Math.floor(8 * dir * Math.random()); dir = 0.5 < Math.random() ? -1 : 1; toy = Math.floor(8 * dir * Math.random()); console.log("-----------------x: " + tox + "----------y: " + toy); if (10 >= count) { var tw = egret.Tween.get(this); tw.to({ x: tox, y: toy }, 50) } console.log("-----------------this.x: " + this.x + "----------this.y: " + this.y); if (0 >= count) { if (null != timer) egret.clearInterval(timer); this.x = orig.x; this.y = orig.y; } }, this, 50);
思路就是控制震动启动和结束时间,在一定时间内,移动object的x,y的位置,必现控制在一定的移动范围