1

I am attempting to get the child sprites position in the view based on the answer here and this

for child in platformGroupNode.children {
    CGPoint p = [child.superview convertPoint:child.center toNode:self.view ]
    println(p)
}

However I am unsure how to use this with SKSpriteNode Children and SKNode Parents.

I have also tried this with no luck

for child in platformGroupNode.children {
    var pos = child.position
    var viewPos = convertPoint(pos, toNode: self.parent!)
    if viewPos.x < 0 {
        println("Out of screen")
    }
}
Community
  • 1
  • 1
Yonkee
  • 1,221
  • 3
  • 21
  • 43

1 Answers1

5

You're nearly there, what you need to use is:

let positionInScene = self.convertPoint(child.position, fromNode: platformGroupNode)
// self in this case is your SKScene, you don't need self here but, IMO, it 
// makes it easier to understand what's converting what.

Or an equivalent would be:

let positionInScene = platformGroupNode.convertPoint(child.position, toNode: self)
ABakerSmith
  • 21,863
  • 9
  • 66
  • 77