简体   繁体   English

帆布小径叶子…小径

[英]Canvas trails leaves … trails

A common way to do trails when animating in Canvas is to overlay your entire context with a semi-transparent color or gradient. 在Canvas中进行动画制作时,进行跟踪的一种常见方法是用半透明的颜色或渐变覆盖整个上下文。 Like this: 像这样:

context.fillStyle = 'rgba(255, 255, 255, .05)';
context.fillRect(0, 0, canvas.width, canvas.height);

// ...draw your next frame

A lot of the examples available on how to create trails use this methodology (I didn't author any of these examples): 关于如何创建路径的许多示例都使用这种方法(我没有编写任何这些示例):

However, all of these seem to leave a slightly faded out trail of the "trail" , so that the trail never really goes away. 但是,所有这些似乎都留下了“足迹”稍微消失的踪迹 ,因此踪迹从未真正消失。 I know there's alternative ways to create trails , but my main question is: 我知道还有其他创建跟踪的方法 ,但是我的主要问题是:

Why doesn't the trail fade completely? 为什么足迹没有完全消失? Why does adding additional multiple layers of a faded color constitute that color in full? 为什么添加更多的褪色颜色多层会完全构成该颜色?

Thank you for helping out my confused brain. 谢谢您帮助我困惑的大脑。

You could try filling a rectangle a little while behind whatever is creating the trail every frame, just set the color to whatever the background color of your canvas is. 您可以尝试在每帧创建轨迹的内容后面填充一个矩形,只需将颜色设置为画布的背景颜色即可。 This should cover up the trail after it's reached a certain length. 到达一定长度后,这应该掩盖了踪迹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM