用easeljs复制对象 [英] duplicating objects with easeljs
问题描述
我一直在尝试使用easeljs库重用元素时遇到问题。我是否使用 clone()方法,我只能获得一个实例,然后像onPress这样的事件将停止为新元素工作。
I keep having problems trying to reuse elements using the easeljs library. Whether I use the clone() method, where I can only get one instance and then events like onPress will stop working for the new elements.
在多个容器上添加相同的对象将使对象在任何地方消失。
我一直在寻找解决方法,弄乱我的代码并浪费资源。
Adding the same object on more than one container will make the object to disappear everywhere. I keep having to find workarounds around this, messing up my code and wasting resources.
提前感谢您的任何帮助或提示。
Thanks in advance for any help or tip.
推荐答案
如果您使用 Shape的图形,您可能需要考虑将 true 作为传递参数。
if you are using Shape's Graphics, you might want to consider passing true as a parameter.
var boxClone = box.clone(true);
:
http://www.createjs.com/Docs/EaselJS/classes/Shape.html#method_clone
克隆(递归)
返回这个Shape的克隆。某些特定于此实例的当前上下文的属性将还原为其默认值(例如.parent)。
Returns a clone of this Shape. Some properties that are specific to this instance's current context are reverted to their defaults (for example .parent).
参数:递归
如果为true,此Shape的Graphics实例也将是克隆。如果为false,则Graphics实例将与新Shape共享。
If true, this Shape's Graphics instance will also be cloned. If false, the Graphics instance will be shared with the new Shape.
这篇关于用easeljs复制对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!