Skip to content
Advertisement

How to position Path2D SVG element in canvas?

I’m drawing a path2D SVG shape on canvas. The problem is that the moveTo function does not seem to work when using SVG data.

The problem is illustrated in this codepen. https://codepen.io/grasmachien/pen/rNaJeBN

JavaScript

Is there a way to move the path without moving the canvas?

Advertisement

Answer

Use the transform to move the path

Using CanvasRenderingContext2D.translate

JavaScript

or using CanvasRenderingContext2D.setTransform

JavaScript

or using CanvasRenderingContext2D.transform

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement