简体   繁体   中英

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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