How to let a user delete a group of objects in kineticjs?

天大地大妈咪最大 提交于 2019-12-08 12:46:16

问题


I have various draggable groups on a kinetic canvas. I need to let a user delete some of these groups.

The first problem is how to actually delete the group (with all its parts) from the canvas.

The second is what kind of UI interaction to use to allow the user to do so. I was thinking to bind dragend, check some condition (eg the position of the object, or some modal variable), and delete the group if the condition is met. Any better suggestions?


回答1:


Hi for removing all the elemnts of a group I think you can do

yourGroup.removeChildren();

and after(or before ) you can do :

yourGroup.getParent().remove(yourGroup);

to remove the group from is parent.strong text.

For the interaction it really depend of what you are doing, have a trash icon and drag the element in look like the interface in android. you can also have a 'edit mode'. when you are in edit mode you select the group you went work on and after select an action in some button. Like delete, copy... this type of interface will look like a ipad one...




回答2:


Regarding your question about 'deleting' -- yes, nodes are actually removed. If you want to check for yourself, console.dir(stage) before and after using remove() or destroy() -- either one does the same thing -- then you'll see the node is completely gone. If instead, you intend to keep it for later use, use hide() instead.

Regarding the 'method to test drag and drop on a trash can' check this post: Dragging collisions



来源:https://stackoverflow.com/questions/10587498/how-to-let-a-user-delete-a-group-of-objects-in-kineticjs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!