Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken remove on two #15

Closed
xixixao opened this issue May 10, 2013 · 5 comments
Closed

Broken remove on two #15

xixixao opened this issue May 10, 2013 · 5 comments

Comments

@xixixao
Copy link
Contributor

xixixao commented May 10, 2013

Adding

two.remove(circle);

on line 15 of the first example and pressing enter couple times breaks havoc (rectangle is rendered without fill and on each redraw the scene is shifted to the right).

Secondly, is there any way to completely wipe Two's instance and start anew? Unfortunately, now Two is unusable in situations when I want to draw dynamically, different objects into the same location. Or something like two.clear().

@jonobr1
Copy link
Owner

jonobr1 commented May 10, 2013

Thanks for mentioning this. Remove was one of the latest things I've put in and as such is probably the buggiest. I'll look into this right away.

@jonobr1
Copy link
Owner

jonobr1 commented May 10, 2013

So on further inspection.two.remove(circle); doesn't exist in the API. The way to remove the circle would be to circle.remove();. I will add a two.remove method so that you can do what you'd like. If you'd like to remove all shapes on a page I suggest:

_.each(two.scene.children, function(child) {
  child.remove();
});

Be mindful of removing any references in your own code to shapes and groups in order for the browser to properly garbage collect these.

@xixixao
Copy link
Contributor Author

xixixao commented May 10, 2013

Would be good to document this use somewhere in the API, the two descriptions of group.remove() are not very clear to me. Thanks for the snippet, I think this could be result of two.scene.clear().

@jonobr1
Copy link
Owner

jonobr1 commented May 10, 2013

No problem. Indeed — I think I'm gonna craft the api like that. I can update this on the documentation, but yes, remove is odd and takes lineage from backbone's bind and unbind. i.e:

group.remove(circle); // Removes the circle
group.remove(circle, rect); // Removes circle and rect
group.remove([circle, rect]); // Removes circle and rect
group.remove(); // Removes the group itself

@jonobr1
Copy link
Owner

jonobr1 commented May 14, 2013

Added and in the latest build: a5c08c4

@jonobr1 jonobr1 closed this as completed May 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants