Skip to content
Advertisement

How to solve this canvas fillStyle problem?

JavaScript
JavaScript

As far as I know it should print big black circle in the middle of the canvas and on top of that a red small circle. But it just prints a big red circle. I just can’t figure it out.

Advertisement

Answer

Just like @Teemu points out in the comment “Begin the paths” you must use the ctx.beginPath() between your arcs when you are changing colors

https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/beginPath#examples

I simplified a lot of your code to show just the problem, you should do the same when you are troubleshooting class Entity was just a distraction and we can reproduce without it

JavaScript
JavaScript
Advertisement