我会尽量准确地解释我的问题。
我的项目有 2 个组([Group1]、[Group2])我想要 [Button],它可以切换 [Group1] 的可见性。(setOpacity 为 1 或 0)我希望 [Group1],[Group2] 可以拖动并相互锚定。
I've tried this way:
I've created 2 layers [Layer1] and [Layer2].
I've added [Group1] to [Layer1]
I've added [Group2] to [Layer2]
When i click [Button], i toggle Opacity of [Layer1]
I've created [MainGroup] and set it to draggable.
I've added [Group1,2] to [MainGroup]. To make them anchored to each other, and i could drag them.
但是如果我使用 [Group1].getParent() 我得到 [Layer1],而不是 MainGroup,这是为什么呢?我应该使用不同的逻辑吗?我需要 [Group1].getParent() 来返回 [MainGroup],所以我可以在其中找到另一个组,即 [Group2] 并为其添加一些形状。
我的 KineticJS 版本是:4.7.2