Spritekit - 创建“墙" [英] Spritekit - Create a "wall"
本文介绍了Spritekit - 创建“墙"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何使用 spritekit 创建一堵墙.物体上的东西不能移动过去.我知道我可以使用此代码:
I am wondering how it is possible to create a wall with spritekit. Something at an object cannot move past. I know that I can use this code:
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
...但是当我使用该代码时,我基本上也得到了一个地板".我希望物体能够穿过屏幕底部但不能离开屏幕.
...but when I use that code I basically get a "floor" as well. I want objects to be able to pass through the bottom of the screen but not be able to leave the side.
在此先感谢您的帮助!
最好的问候,路易斯.
推荐答案
听起来您需要 2 个物理体,一个用于屏幕的每一侧.尝试使用类似的东西.
It sounds like you need 2 physics body, one for each side of the screen. Try having something like.
// 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];
这篇关于Spritekit - 创建“墙"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文