从 SpriteKit/Swift 中的数组中删除元素

Removing Elements From Arrays in SpriteKit/Swift

当您在 SpriteKit 中从 Parent 中删除 SpriteNode 时,它​​会自动从它所在的任何数组中删除它吗?此外,当您从数组中删除一个元素时,其他所有元素是否都会移动,或者该元素曾经所在的位置是否存在间隙?

是的,当一个节点从父节点中移除时,它会以各种方式从父节点中移除。没有为父项及其子项自动创建的数组。如果您手动创建数组,则还必须手动删除该元素。当一个元素被移除时,它不会在两者之间留下空隙。它之后的所有元素只向下移动一个位置。

var array = [0,1,2,3] //A new array
array.removeAtIndex(1) //The 1 would remove the element in the second place which is a 1 in this case
//Now the array should look like [0,2,3] instead of [0,,2,3]//The one is not nil. No gap in between.