2015-06-07 50 views
1

我试图得到一个基于答案herethis如何获得视图中的孩子精灵位置

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

但是我不能确定如何与SKSpriteNode儿童使用此视图孩子精灵位置和SKNode父母。

我也试过这个没有运气

for child in platformGroupNode.children { 
    var pos = child.position 
    var viewPos = convertPoint(pos, toNode: self.parent!) 
    if viewPos.x < 0 { 
     println("Out of screen") 
    } 
} 

回答

3

你就要成功了,你需要使用的是:

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. 

或等效的是:

let positionInScene = platformGroupNode.convertPoint(child.position, toNode: self) 
+0

好东西。再次感谢伴侣 – Yonkee