我正在开发一个 HTML5 Runner 游戏,该对象连续运行,并且在鼠标事件“单击”时,他跳了起来。然后我在游戏中添加了一个障碍并检测到碰撞,但它不能正常工作。问题是,当障碍物与正在运行的物体发生一次碰撞并检测到碰撞时,清除所有物体,然后在画布上重新绘制障碍物,但随着障碍物一次又一次地碰撞,物体障碍物的速度变得越来越快......:(问题是如何克服它吗?这里是代码:
function clearHurdle(){
h.clearRect(100,hy,160,250);
//if(hx==paiX||hy==paiY){
bl= new Image();
bl.onload= function(){
h.drawImage(bl,100,hy-20,160,250);
};
bl.src= "blast.png";
setTimeout(function(){
h.clearRect(100,hy-20,160,250);
show_char=0;
clearAll();
//drawpai();
hurdle();
},100);
}
function hurdle(){
if(hx>(paiX-2) && hx<(paiX+2) && hy>(paiY-2) && hy<(paiY+2)){
console.log(hx +'===='+(paiX-2));
clearHurdle();
hx=1360;
}
h.clearRect(hx,hy,170,250);
var img = new Image();
img.onload= function(){
h.drawImage(img,hx,hy,170,250);
}
img.src="hurdle.png";
hx-= 4.5;
if(hx>-400){
setTimeout(hurdle,1000/60);
}
show_char=1;
}