【问题标题】:How to get a child sprite position in the view如何在视图中获取子精灵位置
【发布时间】:2015-06-07 23:59:42
【问题描述】:

我正在尝试根据答案 herethis 获取子精灵在视图中的位置

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

但是我不确定如何将它与 SKSpriteNode Children 和 SKNode Parents 一起使用。

我也试过了,没有运气

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

【问题讨论】:

    标签: swift sprite-kit skspritenode sknode


    【解决方案1】:

    你快到了,你需要使用的是:

    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)
    

    【讨论】:

    • 好东西。再次感谢队友
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-15
    • 1970-01-01
    • 2012-07-02
    • 1970-01-01
    相关资源
    最近更新 更多