跟老师代码一样,但是只能绘制出一组铅笔是哪出错了呢
来源:4-12 小游戏上下铅笔形管道的创建-3
千与千寻1234
2018-05-03
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'));
}写回答
3回答
-
Echolulu
2018-08-17
我解决了,楼主你log下pencils[0]看下里面的属性有没有写错的,然后再log下pencils[0].x <= (window.innerWidth - pencils[0].width) / 2,看是不是有true
122018-09-13 -
Echolulu
2018-08-16
我也是这个问题,楼主解决了吗0.0
10 -
傅猿猿
2018-05-04
你看看初始化铅笔那块,如果刚刚开始没有正确的初始化,这块代码就算一模一样,也没有判断的必要条件,就是在导演类里初始化铅笔创建那块,对一下
10
相似问题