2017-06-05 1 views
0
var canvas = document.getElementById("mycanvas"); 

var ctx = canvas.getContext("2d"); 


var ball = function() { 

this.x = Math.floor((Math.random() * 10) + 1); 
this.y = Math.floor((Math.random() * 10) + 1); 
this.xSpeed = Math.floor((Math.random() * 10) + 1); 
this.ySpeed = Math.floor((Math.random() * 10) + 1); 

}; 


    var balls =[]; 

for(i = 0 ; i < 10 ; i++) { 

balls[i] = new ball(); 

} 



    function draw() { 
for(i = 0; i < 10 ; i++) { 

var ball = balls[i] 

ctx.beginPath() 

if(ball.x < 0 || ball.x > 400) { 

ball.xSpeed = -ball.xSpeed; 
} 

if(ball.y < 0 || ball.y > 400) { 

ball.ySpeed = -ball.ySpeed; 
} 

ball.x += ball.xSpeed; 

ball.y += ball.ySpeed; 

ctx.arc(ball.x , ball.y , 2 , 0 , Math.PI * 2 , false); 
ctx.stroke(); 

ctx.fill(); 
} 
} 

    function bounce() { 

setInterval(draw , 10); 

} 

Es sollte mehr als einen Ball zeichnen, aber es ist keine Zeichnung. bitte hilfe. Ich kann HTML bei Bedarf zur Verfügung stellen. Ich habe dieses Problem gerade jetzt. Bitte helfen Sie mir jetzt. Ich zeichne keine Bälle. Das ist unglücklichLeinwand funktioniert nicht

Antwort

0

Rufen Sie Ihre Zeichenfunktion auf. Hinzufügen: bounce(); an der Unterseite.