0
我是canvas.js.please的新手,幫我減少框的移動速度。 我想嘗試框根據x軸和y軸陣列values.It運行,但速度太快。我需要降低速度,並希望縮放軸。我們這樣做??請幫助我。畫布中動畫的速度有多慢
<canvas width="2500" height="1500"></canvas>
body{ background-color: ivory; }
#canvas{border:1px solid red; margin:0 auto; }
var canvas = document.getElementsByTagName("canvas")[0]; //get the canvas dom object
var ctx=canvas.getContext("2d");
var cw=canvas.width;
var ch=canvas.height;
// define a rect using a javascript object
var rect1={
x:20,
y:20,
width:40,
height:40,
}
var xval=[1,2,3,4,5];
var yval=[1,2,3,4,5];
// start the animation loop
requestAnimationFrame(animate);
//setInterval(requestAnimationFrame, 100);
function animate(time){
for(var i=0;i<xval.length;i++){
rect1.x+=xval[i];
rect1.y+=yval[i];
}
// draw the rects in their new positions
//setInterval(draw, 1000);
draw();
// request another frame in the animation loop
requestAnimationFrame(animate);
}
function draw(){
ctx.clearRect(0,0,cw,ch);
var r=rect1;
ctx.strokeRect(r.x,r.y,r.width,r.height);
}
謝謝@jonas w .i試過https://jsfiddle.net/6yah8dth/41/ here.its不working.pls幫我 – dhanu