Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.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 以编程方式为精灵在帧内创建区域_Ios_Swift_Sprite Kit - Fatal编程技术网

Ios 以编程方式为精灵在帧内创建区域

Ios 以编程方式为精灵在帧内创建区域,ios,swift,sprite-kit,Ios,Swift,Sprite Kit,我有一个精灵球,我只想在一个正方形区域内反弹 如何在主框架内以渐进方式创建此方形区域,而不是像代码片段中那样约束整个框架: let borderBody = SKPhysicsBody(edgeLoopFromRect: self.frame) borderBody.friction = 0 self.physicsBody = borderBody 请尝试此代码段。它使用SKPhysicsBody创建一个SKNode。然后可以将精灵放置在此节点中: // Create a bound

我有一个精灵球,我只想在一个正方形区域内反弹

如何在主框架内以渐进方式创建此方形区域,而不是像代码片段中那样约束整个框架:

let borderBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
borderBody.friction = 0
self.physicsBody = borderBody

请尝试此代码段。它使用SKPhysicsBody创建一个SKNode。然后可以将精灵放置在此节点中:

    // Create a boundary rectangle. Adjust with your size:
    let boundary = CGRect(x: 100, y: 100, width: 100, height: 100)

    // Create a boundary node
    let boundaryNode = SKNode()

    // Create the PhysicsBody and assign it to the node
    let borderBody = SKPhysicsBody(edgeLoopFromRect: boundary)
    borderBody.friction = 0
    boundaryNode.physicsBody = borderBody

    // Add boundary node to the scene
    self.addChild(boundaryNode)

    // Add your Sprite to the boundaryNode
    boundaryNode.addChild(yoursprite)

请尝试此代码段。它使用SKPhysicsBody创建一个SKNode。然后可以将精灵放置在此节点中:

    // Create a boundary rectangle. Adjust with your size:
    let boundary = CGRect(x: 100, y: 100, width: 100, height: 100)

    // Create a boundary node
    let boundaryNode = SKNode()

    // Create the PhysicsBody and assign it to the node
    let borderBody = SKPhysicsBody(edgeLoopFromRect: boundary)
    borderBody.friction = 0
    boundaryNode.physicsBody = borderBody

    // Add boundary node to the scene
    self.addChild(boundaryNode)

    // Add your Sprite to the boundaryNode
    boundaryNode.addChild(yoursprite)