html5 canvas - animating an object following a path

前端 未结 3 946
情话喂你
情话喂你 2021-01-31 05:12

I\'m a bit new to canvas and such so forgive if it\'s a trivial question.

I\'d like to be able to animate an object following a path (defined as bezier path) but I\'m no

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 06:09

    I wouldn't use Canvas for this unless you really have to. SVG has animation along a path built in. Canvas requires quite a bit of math to get it working.

    Here's one example of SVG animating along a path.

    Here's some discussion about it for raphael: SVG animation along path with Raphael

    Please note that Raphael uses SVG and not HTML5 Canvas.


    One way to animate along a bezier path in Canvas is to continuously bisect the bezier curve, recoring the midpoints until you have a lot of points (say, 50 points per curve) that you can animate the object along that list of points. Search for bisecting beziers and similar queries for the related math on that.

提交回复
热议问题