如何设置边界到场景物理正常弹跳?

我实现了一个简单的物理来反弹一个sprite node ,除了节点之外的所有东西都在顶部和底部的屏幕上反弹。对于边来说它是好的,但是从顶部和底部的视angular来看,它们是离开屏幕的。

这是观点:

在这里输入图像说明

正如你所看到的那样,我的球从底部的屏幕上掉下来,在那里它碰到了其他三面。

这是因为我改变了:

  self.physicsBody=[SKPhysicsBody bodyWithEdgeLoopFromRect:CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, self.frame.size.height-100)]; 

如果我使用scene frame ,那么球在顶部和底部都会离开屏幕,但是它会弹跳。

  self.physicsBody=[SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame]; 

我的问题是为什么self.frame不足以为self.frame设置界限?

当我设置这样的边界时,唯一的条件适用于我:

  self.physicsBody=[SKPhysicsBody bodyWithEdgeLoopFromRect:CGRectMake(self.frame.origin.x, self.frame.origin.y+100, self.frame.size.width, self.frame.size.height-200)]; 

这是因为场景的大小和视图的大小不一样。

在GameViewController.m文件中添加这一行:

scene.size = skView.bounds.size

它在这里:

/* Set the scale mode to scale to fit the window */ scene.scaleMode = .AspectFill scene.size = skView.bounds.size

当然,你需要正常定位视图(删除你添加的+100等)。