Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我如何让球在短时间内沿着画布向下移动?_Javascript - Fatal编程技术网

Javascript 我如何让球在短时间内沿着画布向下移动?

Javascript 我如何让球在短时间内沿着画布向下移动?,javascript,Javascript,我试着让我的球,在数组中,在短时间后直接向下移动,一个接一个地正好等于掉了100个球。我包含了我所有的代码,试图展示更多我想要程序做的事情。 事实上,每次击球时,球都会生成,并且由用户控制球拍得分点。它们是单选按钮,可以通过检查使球落得更快或更慢。 我只是想让球一次一个地在画布上移动 var posY = 0; var spawnRateOfDescent = 2; var spawnRate = 500; var lastSpawn = -1; var balls = [100]; var s

我试着让我的球,在数组中,在短时间后直接向下移动,一个接一个地正好等于掉了100个球。我包含了我所有的代码,试图展示更多我想要程序做的事情。 事实上,每次击球时,球都会生成,并且由用户控制球拍得分点。它们是单选按钮,可以通过检查使球落得更快或更慢。 我只是想让球一次一个地在画布上移动

var posY = 0;
var spawnRateOfDescent = 2;
var spawnRate = 500;
var lastSpawn = -1;
var balls = [100];
var startTime = Date.now();
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");

function checkRadio() {
    if (document.getElementById("moderate").checked == true) {
        spawnRate = 250;
    } else if (document.getElementById("hard").checked == true) {
        spawnRate = 100;
    } else if (document.getElementById("easy").checked == true) {
        spawnRate = 500;
    }
}

function startGame() {
    var canvas = document.getElementById("myCanvas");
    var ctx = canvas.getContext("2d");
    baton = new batonPiece(50, 10, "28E060", 210, 250)
}

function ball() {
    this.x = Math.random() * (canvas.width - 30) + 15;
    this.y = 0;
    this.radius = 10;
    this.color = randomColor();
    this.draw = function () {
        ctx.beginPath();
        ctx.arc(this.x, this.y, this.radius, 0, 2 * Math.PI, false);
        ctx.fillStyle = randomColor();
        ctx.fill();
        ctx.closePath();
    }
}

var balls = [];
for (var i = 0; i < 100; i++) {
    balls[i] = new ball();
    balls[i].draw();
}

function batonPiece(width, height, color, x, y) {
    this.width = width;
    this.height = height;
    this.x = x;
    this.y = y;
    ctx.fillStyle = color;
    ctx.fillRect(this.x, this.y, this.width, this.height);
}

function randomColor() {
    var letter = "0123456789ABCDEF".split("");
    var color = "#";

    for (var i = 0; i < 6; i = i + 1) {
        color += letter[Math.round(Math.random() * 15)];
    }

    return color;
}

function moveLeft() {
    batonPiece.x -= 1;
}

function moveRight() {
    baton.x += 1;
}

function stopMove() {
    baton.x = 0;
}
var posY=0;
var-spawnRateOfDescent=2;
var产卵率=500;
var lastpawn=-1;
var balls=[100];
var startTime=Date.now();
var canvas=document.getElementById(“myCanvas”);
var ctx=canvas.getContext(“2d”);
函数checkRadio(){
if(document.getElementById(“mediate”).checked==true){
产卵率=250;
}else if(document.getElementById(“硬”).checked==true){
产卵率=100;
}else if(document.getElementById(“easy”).checked==true){
产卵率=500;
}
}
函数startName(){
var canvas=document.getElementById(“myCanvas”);
var ctx=canvas.getContext(“2d”);
指挥棒=新的指挥棒(50,10,“28E060”,210250)
}
函数球(){
this.x=Math.random()*(canvas.width-30)+15;
这个。y=0;
这个半径=10;
this.color=randomColor();
this.draw=函数(){
ctx.beginPath();
ctx.arc(this.x,this.y,this.radius,0,2*Math.PI,false);
ctx.fillStyle=randomColor();
ctx.fill();
ctx.closePath();
}
}
var=[];
对于(变量i=0;i<100;i++){
balls[i]=新的ball();
球[i].draw();
}
功能指挥棒(宽度、高度、颜色、x、y){
这个。宽度=宽度;
高度=高度;
这个.x=x;
这个。y=y;
ctx.fillStyle=颜色;
ctx.fillRect(this.x,this.y,this.width,this.height);
}
函数randomColor(){
var letter=“0123456789ABCDEF”。拆分(“”);
var color=“#”;
对于(变量i=0;i<6;i=i+1){
颜色+=字母[Math.round(Math.random()*15)];
}
返回颜色;
}
函数moveLeft(){
接力棒x-=1;
}
函数moveRight(){
baton.x+=1;
}
函数stopMove(){
baton.x=0;
}

这是一个非常有趣的标题……很抱歉,这是我的第一篇博文。我不是很精通画布,所以我不能在这方面提供帮助,但标题太有趣了,所以我不得不评论,我也是,哈哈,很遗憾