在Pixi.js中绘制一条线的动画
Animate the drawing of a line in Pixi.js
是否可以在Pixi.js中设置线条的动画?(Canvas,WebGL,随便什么。)
我完全理解如何为已经渲染的线或对象设置动画,但如何使其为线本身的绘制设置动画,就像使用TweenMax一样?我已经详尽地搜索了示例和代码,但我感到震惊的是,我找不到一个参考点来做这件事。
Fiddle。
var stage = new PIXI.Container();
var graphics = new PIXI.Graphics();
graphics.lineStyle(20, 0x33FF00);
graphics.moveTo(30,30);
graphics.lineTo(600, 300);
stage.addChild(graphics);
animate();
function animate() {
renderer.render(stage);
requestAnimationFrame( animate );
}
你需要自己制作动画——先把它画短,然后把它画得越来越长。
例如,在这里我添加了一个变量"p"(表示百分比),它从0(完全没有绘制)到1(完全绘制)。在渲染循环中,将增加p,直到它变为1。
var p = 0; // Percentage
function animate() {
if (p < 1.00) // while we didn't fully draw the line
p += 0.01; // increase the "progress" of the animation
graphics.clear();
graphics.lineStyle(20, 0x33FF00);
graphics.moveTo(30,30);
// This is the length of the line. For the x-position, that's 600-30 pixels - so your line was 570 pixels long.
// Multiply that by p, making it longer and longer. Finally, it's offset by the 30 pixels from your moveTo above. So, when p is 0, the line moves to 30 (not drawn at all), and when p is 1, the line moves to 600 (where it was for you). For y, it's the same, but with your y values.
graphics.lineTo(30 + (600 - 30)*p, 30 + (300 - 30)*p);
renderer.render(stage);
requestAnimationFrame( animate );
}
相关文章:
- 在地图上画一条路线
- 在d3中拖动一条线
- 我确实有一个表单,如果用户输入了输入,它应该检查否定或空的输入框,并抛出一条警告消息
- 我正在创建一个聊天,但每次我发送消息时,它都不会让我再发送另一条消息,就像表格一样;不起作用
- 当我的条件为true时,显示一条弹出消息
- 如何在javascript中的if或else块中运行一条jsp语句
- 加载页面每10秒显示一条不同的消息
- 更改路线时,在react.js中得到一条非常crypric的消息
- 当用户单击保存按钮时,标签会显示一条消息
- 仅显示一条通用消息,而不是每个输入显示一条
- 在检索到最后一条记录后从 PostgreSQL 中提取记录
- 有没有一条清晰的路径,我可以实现一个在 ScalaJS + React 中广泛使用上下文的 React 组件
- 如果用户的浏览器早于以下版本,则显示一条消息:IE 10、Firefox 39、Chrome 39、Opera 8
- 将一条线动画化为多个点
- 操作方法:将鼠标悬停在图像上并制作动画绘制一条线,说明淡出
- 在Pixi.js中绘制一条线的动画
- 在BonsaiJS中沿着一条路径制作电影动画
- 如何在d3.js中为一条路径上的多个圆设置动画
- Createjs 和 easlejs - 用多个点为一条线制作动画
- 使用fabric.js在画布上绘制一条线的动画