run() { //绘制背景 this.dataStore.get('background').draw(); //绘制铅笔前判断 const pencils = this.dataStore.get('pencils'); //此时铅笔的右边界恰好移除canvas左边界 if (pencils[0].x + pencils[0].width <= 0 && pencils.length === 4) { //将数组中的铅笔移除 pencils.shift();//上 pencils.shift();//下 } if (pencils[0].x <= (window.innerWidth - pencils[0].width) / 2 && pencils.length === 2) { this.createPencil(); } //绘制铅笔 this.dataStore.get('pencils').forEach(function (value) { value.draw(); }); //绘制地面 this.dataStore.get('land').draw(); let timer = requestAnimationFrame(() => this.run()); this.dataStore.put('timer',timer); //cancelAnimationFrame(this.dataStore.get('timer')); }