我在GameScene中正确定位两个SKSpriteNodes有点麻烦。我的节点出现在场景中,但它们被放大并占据整个场景的大部分。我希望输出类似于:
这是我目前的代码:
let size = CGRect(x: 100, y:98, width:200, hight:271)
bottomRectangle = SKSpriteNode(imageNamed: "bottomRectangle")
bottomRectangle.zPosition = 3
bottomRectangle.size.height = self.size.height
bottomRectangle.size.width = self.size.width
bottomRectangle.position = CGPoint(x: 200, y:271)
bottomRectangle.physicsBody = SKPhysicsBody(edgeLoopFromRect: size)
self.addChild(bottomRectangle)
topRectangle = SKSpriteNode(imageNamed: "topRectangle")
topRectangle.physicsBody = SKPhysicsBody(edgeLoopFromRect: size)
topRectangle.zPosition = 4
topRectangle.size.height = self.size.height
topRectangle.size.width = self.size.width
topRectangle.position = CGPoint(x: 100, y: 98)
self.addChild(topRectangle)
答案 0 :(得分:0)
您正在使用场景的大小,因为:
self.size.height
您必须使用本地变量:
size.height