So there I was, trying to place a new canvas element exactly over a Konva stage, which worked but the scaling was all wrong compared to the Konva output – what gives ?
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.
So what, you grabbed a transformer handle and stretched the rectangle and now you don’t understand what gives with the width and height – they didn’t change? You can see the freekin size changed but why are the width & height the same as before? Huh ? Stop the world, I wanna get off. Ok, lets talk about it.
This came up in a Discord discussion where someone asked why the objects on the canvas always changed regardless of the fact that one of their objects was set to be non-reactive.
How can we make a focus border around the shapes in a group whilst the group and shape are draggable? A transformer could do it, or we could add a rect to the group…
Ever needed to have a rect with alpha applied to the fill bit not the stroke – here’s how! Before I found this excellent example that Anton mentioned in an old Github issue, I would have solved this challenge with multiple rects – one for the stroke and one for the fill. But this simple solution needs only one rect.