Spritekit - 创建"墙"

use*_*149 3 xcode ios sprite-kit

我想知道如何用spritekit创建一个墙.物体上的物体无法移动过去.我知道我可以使用这段代码:

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

...但是当我使用该代码时,我基本上也得到了"底线".我希望物体能够通过屏幕底部但不能离开侧面.

在此先感谢您的帮助!

最好的问候,路易斯.

Guy*_*gus 5

听起来你需要2个物理体,屏幕的每一面都有一个.尝试类似的东西.

// Left Wall
SKNode *node = [SKNode node];
node.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:CGRectMake(0.0f, 0.0f, 1.0f, CGRectGetHeight(self.frame))];
[self addChild:node];

// Right wall
node = [SKNode node];
node.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:CGRectMake(CGRectGetWidth(self.frame) - 1.0f, 0.0f, 1.0f, CGRectGetHeight(self.view.frame))];
[self addChild:node];
Run Code Online (Sandbox Code Playgroud)