【问题标题】:know that skspritenode has completely moved over another skspritenode知道 skspritenode 已经完全移过另一个 skspritenode
【发布时间】:2020-02-05 09:41:31
【问题描述】:

我试图找出一个 SKSpriteNode 已完全迭代另一个 SKSpriteNode这是我目前想出的代码,

if (node.frame.maxY == player.frame.minY) {
    player.physicsBody?.collisionBitMask = collisionTypes.vortex.rawValue
}

我知道这很简单,但我在这里迷路了。

【问题讨论】:

  • 你的意思是在上面吗?还是完全通过?
  • 完全通过

标签: ios swift xcode sprite-kit skspritenode


【解决方案1】:

设置两个对象的contactTestBitMask 属性。然后在 didBegin 函数中检测它们何时发生碰撞,然后在 didEnd 函数中检测它们何时停止碰撞

player.physicsBody?.contactTestBitMask = collisionTypes.bullet.rawValue
bullet.physicsBody?.contactTestBitMask = collisionTypes.player.rawValue

func didBegin(_ contact: SKPhysicsContact) {
    //detect your collision and do what you need to do
    //maybe set a bool to true if you have multiple collision types
}

func didEnd(_ contact: SKPhysicsContact) {
    //check that the above collison is the one that ended
    //run appropriate code for end collision
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多