操纵 alpha 属性 与 adding/removing 节点

Manipulating alpha property vs adding/removing node

如果我想要一个或多个节点(在这种情况下,一个 "panel" 和两个 "buttons" - 例如:一个节点代表面板,该面板上的另外两个节点代表按钮)出现并可用于调用操作(按钮使用 touchesBegan()),我似乎可以通过在我的 .sks 场景中创建节点(颜色精灵)并使用 alpha = 0/1 来实现。我也可以通过在 .swift class 中创建节点并使用 .addChild()/.removeFromParent() 函数以编程方式完成。

这些方法是可互换的吗?还是存在使用 alpha 的危险,因为节点仍然存在,虽然没有看到?

在 Spritekit 中,hiddenalpha 属性等于 0 作为默认值。

来自 Apple 关于隐藏对象

objects are not rendered. However the still exist in the scene and continue to interact with it in other ways

所以这与创建对象但未将其添加到父对象相同

刚刚 运行 对在 touchesBegan 函数中检测到的对象进行了测试。

当对象有 .alpha = 0 时,它仍然在 touchesBegan

中被检测到

创建对象但未添加到父对象时,仍会在 touchesBegan

中检测到它

所以我觉得这两种方法是可以比较的

Edit> I stand corrected they are not comparable, please feel free to unselect my answer. Please comments to see pitfalls of using alpha = 0