Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios SKSpriteNode与边墙碰撞_Ios_Swift - Fatal编程技术网

Ios SKSpriteNode与边墙碰撞

Ios SKSpriteNode与边墙碰撞,ios,swift,Ios,Swift,我有一些对象(SKSpriteNode)从上到下移动,当它们在底部屏幕的末端时,它们消失了。 问题是,有时对象会离开屏幕(左边缘或右边缘),我应该添加一些“墙”来阻止这一点。 我不知道怎么做 物理学结构: struct PhysicsCategory { static let None : UInt32 = 0 static let All : UInt32 = UInt32.max static let PhysicsSweet: UInt32 =

我有一些对象(SKSpriteNode)从上到下移动,当它们在底部屏幕的末端时,它们消失了。 问题是,有时对象会离开屏幕(左边缘或右边缘),我应该添加一些“墙”来阻止这一点。 我不知道怎么做

物理学结构:

struct PhysicsCategory {
    static let None      : UInt32 = 0
    static let All       : UInt32 = UInt32.max
    static let PhysicsSweet: UInt32 = 0b1
}
生成对象的代码:

    let randomSweetPosition = Int(arc4random_uniform(UInt32(400))+300)
    let sweet = SKSpriteNode(imageNamed: "cake0")
    sweet.xScale = 0.4
    sweet.yScale = 0.4
    sweet.position = CGPoint(x : randomSweetPosition, y : 768)
    self.addChild(sweet)

    sweet.physicsBody = SKPhysicsBody(circleOfRadius: sweet.size.height/2)
    sweet.physicsBody?.isDynamic = true
    sweet.physicsBody?.categoryBitMask = PhysicsCategory.PhysicsSweet
    sweet.physicsBody?.collisionBitMask = PhysicsCategory.None