How to completely remove a path in paper.js

1,617 views
Skip to first unread message

mowgli mecha

unread,
Apr 7, 2016, 8:16:26 AM4/7/16
to Paper.js
i need to create an undo button for my app . 

Jürg Lehni

unread,
Apr 7, 2016, 2:44:14 PM4/7/16
to pap...@googlegroups.com
All it takes is:

path.remove(); 

On Apr 7, 2016, at 05:16 , mowgli mecha <mowgl...@gmail.com> wrote:

i need to create an undo button for my app . 

--
You received this message because you are subscribed to the Google Groups "Paper.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to paperjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mowgli mecha

unread,
Apr 7, 2016, 3:08:05 PM4/7/16
to Paper.js
what if i have an array of paths created? and everytime i click undo it will remove them 1 by one

Oscar Prom

unread,
Apr 8, 2016, 8:51:59 AM4/8/16
to Paper.js
var paths = [path1, path2, ... ]; // this is your array of paths

// define your undo function
function undo() {
  var path = paths.pop();
  path.remove();
}

// connect your undo function and button
document.getElementById('undo-button').onclick = undo;

mowgli mecha

unread,
Apr 8, 2016, 9:02:10 AM4/8/16
to Paper.js
thanks i will try this

mowgli mecha

unread,
Apr 8, 2016, 10:35:06 AM4/8/16
to Paper.js
Hi! It worked perfectly! Thank you for this . may i know what is pop() it think it's not on paper js


On Friday, April 8, 2016 at 8:51:59 PM UTC+8, Oscar Prom wrote:

Oscar Prom

unread,
Apr 8, 2016, 10:52:27 AM4/8/16
to Paper.js
.pop() is a standard function of arrays in JavaScript that removes and returns the last item of that array. You can read more about it in the MDN docs.
Reply all
Reply to author
Forward
0 new messages