swift - 操作 alpha 属性与添加/删除节点

标签 swift sprite-kit alpha addchild

如果我想要一个或多个节点(在本例中是一个带有两个“按钮”的“面板”——例如:一个节点代表面板,该面板上的另外两个节点代表按钮)出现并可供使用调用操作(按钮使用 touchesBegan()),我似乎可以通过在我的 .sks 场景中创建节点(颜色 Sprite )并使用 alpha = 0/1 来完成。我还可以通过在 .swift 类中创建节点并使用 .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

关于swift - 操作 alpha 属性与添加/删除节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43575447/

相关文章:

ios - 如何从 SKScene 到 UIViewController?

c - X11 : Cannot draw an image on transparent window created with XCreateWindow

ruby-on-rails - imagemagick 检测透明区域的坐标

ios - 在 xCode 中使用多个 Assets 文件夹

ios - 隐藏时淡入

xcode - 如何在调试器中查看值?

swift 3 : Converting Data to String returns a nil value

ios - 删除图像中的 alpha channel

swift - 未调用 WatchKit didReceiveApplicationContext

swift - iOS - Swift 蓝牙 - 未发现 Android 设备