swift - how to filter out/exclude some indexes from a CGPoint array -
i have array of cgpoints (spritepositions
) , create skspritenode's selected number of positions (leaving specific indexes of out). please see code below:
createsprite(missingindexes: [int]) { //for (index, value) in enumerate(spritepositions) filtering out/excluding missingindexes array { var sprite = skspritenode(imagenamed: "spriteimage") sprite.position = value addchild(sprite) } }
you can use contains function on missingindexes array filter out indices. if index not contained in missingindexes process normal. if index containted in missingindexes, nothing.
swift 1.2:
for (index, value) in enumerate(spritepositions) { if !contains(missingindexes, index) { var sprite = skspritenode(imagenamed: "spriteimage") sprite.position = value addchild(sprite) } }
swift 2.0
for (index, value) in spritepositions.enumerate() { if !missingindexes.contains(index) { var sprite = skspritenode(imagenamed: "spriteimage") sprite.position = value addchild(sprite) } }
Comments
Post a Comment