[英]How to make border for a scene in SpriteKit
I am trying to make border for the two sides in a scene but there is some kind of error the here is the code i used 我试图在一个场景中为双方制作边框但是有一些错误,这里是我使用的代码
let leftEdge : SKNode = SKNode()
leftEdge.physicsBody = SKPhysicsBody(edgeFromPoint: CGPointZero, toPoint: CGPointMake(0.0, self.size.height + 100))
leftEdge.position = CGPointZero;
self.addChild(leftEdge)
let rightEdge : SKNode = SKNode()
rightEdge.physicsBody = SKPhysicsBody(edgeFromPoint: CGPointZero, toPoint: CGPointMake(0.0, self.size.height + 100))
rightEdge.position = CGPointMake(self.size.width, 0.0);
self.addChild(rightEdge)
but the top border and bottom border get the borders and the two sides its seems like they have border outside the the scene cause i shoot object toward them it goes out of the scene and get back so the question how i make borders only for the two sides the left and the right 但顶部边框和底部边框得到边框和两边看起来它们在场景之外有边框因为我向它们拍摄物体它离开场景然后回来所以问题我如何只为两个边界做边框左右两侧
try this 尝试这个
let border = SKPhysicsBody(edgeLoopFrom: self.frame)
border.friction = 0
border.restitution = 1
self.physicsBody = border
obviously you can add your own physics to your border. 很明显,你可以将自己的物理添加到边框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.