创建一个在碰撞iOS 8后无法移动的节点

时间:2015-08-31 20:34:57

标签: swift ios8 sprite-kit

我有节点(沙子)向下坠落。

我有其他静态的节点(墙)。

当沙子碰撞时,如何让墙壁不移动?

    let wall = SKSpriteNode(texture: chosen)

    wall.position = location

    wall.physicsBody = SKPhysicsBody(circleOfRadius: sprite.frame.width)
    wall.physicsBody?.affectedByGravity = false
    wall.physicsBody!.categoryBitMask = BLOCK

    self.addChild(wall)

//////////

    let sand = SKSpriteNode (imageNamed: img)
    var randLoc = arc4random_uniform(26)
    sand.position = CGPointMake(location.x - CGFloat(10) + CGFloat(randLoc), location.y)
    self.addChild(sand)

    //gravity
    sand.physicsBody = SKPhysicsBody(circleOfRadius: sand.frame.width)
    sand.physicsBody?.affectedByGravity = true

    //contact
    sand.physicsBody!.categoryBitMask = self.PARTICLE
    sand.physicsBody?.collisionBitMask = self.BLOCK | self.PARTICLE

1 个答案:

答案 0 :(得分:2)

如果你有wall.physicsBody?.dynamic = false& sand.physicsBody?.dynamic = true那么你应该能够在没有被沙子推动/移动墙壁的情况下检测到接触。 - Daniel Mihaila

https://stackoverflow.com/users/4963031/daniel-mihaila