【发布时间】:2018-04-22 23:09:40
【问题描述】:
所以我是一个画布新手,我编写了一些代码来尝试创建动画。我想用抛物线方程让球移动,一切都很好,除了没有动画,我基本上得到了一个由弧线组成的抛物线。
这是我用于动画的一段代码:
// a b c are calculated in another function and they are used to calculate the parabola, x1 and y1 are the coordinates of the ball
function drawball(a,b,c,x1,y1){
canvas=document.getElementById("mycanvas");
ctx=canvas.getContext("2d");
ctx.beginPath();
ctx.arc(x1,y1,25,0,2*Math.PI);
ctx.stroke();
//stop when i get to the final point (x3 is a const)
if(x1<x3){
y1=a*(x1*x1)+b*x1+c; //parabola formula
x1++;
window.requestAnimationFrame(drawball(a,b,c,x1,y1));
}
}
在 chrome 的控制台中我收到此错误:
Failed to execute 'requestAnimationFrame' on 'Window': The callback
provided as parameter 1 is not a function.
感谢您的帮助!
【问题讨论】:
标签: javascript html animation canvas