Workshop › Breakout › Step 38 of 39
Particles should not vanish suddenly but fade out. ctx.globalAlpha sets the opacity of everything drawn after it.
```js
for (const p of particles) {
ctx.globalAlpha = p.life / 30
ctx.fillStyle = p.color
ctx.fillRect(p.x - 2, p.y - 2, 4, 4)
}
ctx.globalAlpha = 1
```p.life / 30 goes from 1 (just born) down toward 0 (about to die), so each particle fades out.globalAlpha goes back to 1; otherwise the paddle, ball and text would be see-through too.In the particle loop in draw, add the globalAlpha line first; under the loop's } write ctx.globalAlpha = 1.
Skills: Drawing on a canvas
← Move, fall and disappear Build it yourself: tough bricks →