http://example.com/code123/
After taking into account your recent input, it appears that creating layers is essential, as explained in detail here:
http://example.com/tutorial123/
Once you have set up the layers, you can then proceed to add your paths to a specific layer and execute the following code snippet:
// Insert image as a background in the project
// ... insert your code here ...
var newLayer = new Layer();
Each time you create a new Layer, it automatically becomes the active layer of the project, allowing you to freely draw on the new layer.
If you are interested in incorporating a basic 'undo' feature, you can implement the following:
function onMouseDown(event) {
if (window.mode == "draw") {
myPath = new Path();
myPath.strokeColor = 'black';
}
else if (window.mode == "undo") {
myPath.opacity = '0'; // This action makes the previously used path completely transparent
// Alternatively, myPath.remove(); // This option deletes the path.
// If you require a functionality that enables drawing and erasing, you could explore other alternatives.
}
}
However, if your goal is to achieve something like this:
function onMouseDrag(event) {
if (window.mode == "draw") {
myPath.add(event.point);
}
else if (window.mode == "erase") {
myPath.removeSegment(0);
}
}
This function specifically erases segments of the path from the start to the end. To fully utilize this, you will need a method to identify a path upon clicking (possibly using layer.getChildren() to select a child). Subsequently, by utilizing the mouse movement point, you must determine the segment index to remove it from the path using .removeSegment(index).
http://example.com/reference/erase-segment/