Reputation: 1883
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")
}
}
Upvotes: 1
Views: 1931
Reputation: 22939
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)
Upvotes: 5