I’ve seen a few questions asking how to know when a layer gets redrawn. But first I’m going to tell you why you don’t generally need to do it:…
I’ve seen experienced devs crash and burn on the differences between working with the HTML5 canvas element and the HTML DOM. Here’s some short-cut learnings to help you refactor your brain the canvas way and keep you moving.
I was curious about how to close Konva lines, and I wanted to explore what we can do with lines and animation – here’s where it ended up.
A user recently had a query regarding how to get the pixel color data for a point on the stage. This is quite easy, but there’s a catch on high pixel density devices – think Apple devices like the MacBook and iPad. Here’s the solution… TLDR: Here’s the sample code – try it on yourContinue reading “Konva – Mouse position + pixelRatio will mess up your day”
Writing drag bound functions is easy with rectangular shapes like Konva.Rects and Konva.Images- but Konva.Groups have a few more unexpected challenges. Lets take a look at some of the assumption traps around the Konva.Group and see what we can do.
Someone asked about shape-point collision detection for the point under the mouse in a case where there are many shapes on the stage, and how to improve performance in relation to the Stage.getAllIntesections(), Stage.getIntersection() and Shape.intersects() methods. Here’s my explanation of those functions and an approach to improving hit detection. Just to be clear –Continue reading “Konva – Point & shape collision detection”
The topic of how to get a shape to the front and center of the canvas view often arises. Here is my approach…
Someone on Discord asked it it was possible to make a star rating widget thing with Konva – the holes in the stars sounded like an interesting challenge. Here we go… TLDR: See the demo and code. This is a Vanilla JS solution, but @ivor adapted it for React here. The key technique for makingContinue reading “Konva – Star rating control”
I wondered how to edit the points on a path or line – here’s an answer. Both the Konva Line and Path use a list of points to draw themselves. The Line takes a simple array of x & y values whilst the Path wants a data definition composed of SVG drawing commands. I choseContinue reading “Konva – editing path points”
Re-drawing a hand drawn line with too many points can hit performance. Using a lib like simplify.js we can reduce the points considerably to get a performance boost.