我宣布了一个SKSpriteNode
,有一个支柱图像。图像是3000 x 50,我已经声明它是这样的:
var pairs = SKNode()
let pillar = SKSpriteNode(imageNamed: "pillar")
pillar.setScale(0.5)
pillar.physicsBody = SKPhysicsBody(rectangleOf: pillar.size)
pillar.physicsBody?.isDynamic = false
pillar.physicsBody?.affectedByGravity = false
pillar.zPosition = 1
pairs.zPosition = 1
pairs.addChild(pillar)
当我为我的支柱设置位置时,我这样做:
bottomWall.position = CGPoint(x: Int(self.frame.width) + 100, y: 0)
我已经将y设置为0,但是柱状图像大约在y轴的屏幕中间开始,而对于x轴,这个Int(self.frame.width) + 100
将柱子从中间定位100px。
为什么这个行为以及我怎样才能让y: 0
开始在y: 0
开始t x: 0
和x: 0
?
物体的position
是关于物体的中心。为了使x
和y
代表bottomWall
的左下角你应该设置
bottomWall.anchorPoint = CGPoint(x:0,y:0)
在线之前你定位bottomWall
这将使用对象的左下角作为x
和y
相对于屏幕。