Removing objects from a layer using KineticJS

感情迁移 提交于 2019-12-20 19:30:55

问题


I am currently working a project involving KineticJS.

I have to dynamically create and delete shapes constantly, but cannot seem to figure out how to do the latter. I've been trying to do:

 $ myLayer.remove(myShape)

because this is what most posts seem to recommend. But, the documentation says that this will remove the layer from the stage and not the shape from the layer. When I try this in project it in fact removes the layer from the stage.

So am I doing something wrong or is there some other way to remove a shape from a layer?


回答1:


There are two functions that may be helpful.

  • childContainer.remove() removes the childContainer from it's parent.
  • parentContainer.removeChildren() removes all the children from this container.

Edit: This can also apply to shapes. Simply redraw the layer.

myShape.remove();
myLayer.draw();



回答2:


Somewhere between Kinetic 4.0 and the latest version, remove(child) stopped working. removeChild(child) doesn't work either.

I resolved this problem by using child.remove();




回答3:


U can use the prototype of kinetic function

Kinetic.Node.prototype.remove.call(removed_object);

baselayer.draw();



来源:https://stackoverflow.com/questions/12757176/removing-objects-from-a-layer-using-kineticjs

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