Javascript 如何停止';下降';提速?

Javascript 如何停止';下降';提速?,javascript,canvas,constructor,Javascript,Canvas,Constructor,问题是,每次按“空格”键添加新的水滴时,所有水滴的速度都会增加,速度由水滴构造函数中的movepi函数决定。任何帮助都将不胜感激。谢谢 按下空格键可以测试下面的代码段 //随机获取// 函数随机数(最小值、最大值){ “严格使用”; 返回Math.floor((Math.random()*max)+min); } //设置画布// var canvas=document.querySelector(“#make”), ctx=canvas.getContext(“2d”); //创建下降//

问题是,每次按“空格”键添加新的水滴时,所有水滴的速度都会增加,速度由水滴构造函数中的movepi函数决定。任何帮助都将不胜感激。谢谢 按下空格键可以测试下面的代码段

//随机获取//
函数随机数(最小值、最大值){
“严格使用”;
返回Math.floor((Math.random()*max)+min);
}
//设置画布//
var canvas=document.querySelector(“#make”),
ctx=canvas.getContext(“2d”);
//创建下降//
函数下降(x,y){
"严格使用",;
//设置X和Y位置//
这个.x=x;
这个。y=y;
//显示下降//
this.showpi=函数(){
ctx.fillStyle='红色';
ctx.fillRect(x,y,10,10);
};
//移动下降//
this.movepi=函数(){
y=y-3;
};
}
//设置画布大小//
函数setCanvasWidth(){
“严格使用”;
ctx.canvas.width=window.innerWidth;
ctx.canvas.height=window.innerHeight;
}
//在画布上绘制动画效果//
函数paintover(){
"严格使用",;
ctx.fillStyle=“rgba(0,0,0,0.4)”;
ctx.fillRect(0,0,canvas.width,canvas.height);
window.requestAnimationFrame(画外画);
}
//变数//
var-dropi=[];
//var drop=新的drop(window.innerWidth/2,window.innerHeight);
//获得新的滴剂//
函数drop(){
"严格使用",;
var newdrops=newdrops(window.innerWidth/2,window.innerHeight);
返回newdrops;
}
//画//
函数绘图(){
"严格使用",;
var i;
对于(i=0;i
画布{
位置:绝对位置;
宽度:100%;
身高:100%;
排名:0;
左:0;
z指数:-1;
}

我的朋友帮了我的忙,我犯了一个错误,每次按下空格键时都调用draw()。他把它放在一个条件语句中,所以我只需要调用它一次。谢谢大家

//随机获取//
函数随机数(最小值、最大值){
“严格使用”;
返回Math.floor((Math.random()*max)+min);
}
//设置画布//
var canvas=document.querySelector(“#make”),
ctx=canvas.getContext(“2d”);
//创建下降//
函数下降(x,y){
"严格使用",;
//设置X和Y位置//
这个.x=x;
这个。y=y;
//显示下降//
this.showpi=函数(){
ctx.fillStyle='红色';
ctx.fillRect(x,y,10,10);
};
//移动下降//
this.movepi=函数(){
y=y-3;
};
}
//设置画布大小//
函数setCanvasWidth(){
“严格使用”;
ctx.canvas.width=window.innerWidth;
ctx.canvas.height=window.innerHeight;
}
//在画布上绘制动画效果//
函数paintover(){
"严格使用",;
ctx.fillStyle=“rgba(0,0,0,0.4)”;
ctx.fillRect(0,0,canvas.width,canvas.height);
window.requestAnimationFrame(画外画);
}
//变数//
var-dropi=[];
//var drop=新的drop(window.innerWidth/2,window.innerHeight);
//获得新的滴剂//
函数drop(){
"严格使用",;
var newdrops=newdrops(window.innerWidth/2,window.innerHeight);
返回newdrops;
}
//画//
函数绘图(){
"严格使用",;
var i;
对于(i=0;i
画布{
位置:绝对位置;
宽度:100%;
身高:100%;
排名:0;
左:0;
z指数:-1;
}