我正在尝试构建一个Breakout游戏,我使用1个SKSpriteNode为每个级别设置砖块。这一切都有效,就像它们产生一样,但是从屏幕左下方开始。我在didMove的开头使用以下行(查看:SKView):
scene?.anchorPoint = CGPoint(x: 0.0, y: 0.0)
我用来产生砖块的代码是:
//MARK: Brick Layout Config
let widthOfTiles = 7
let heightOfTiles = 3
let widthPoints = 50
let heightPoints = 20
// Different tile arrangements (e.g. 7 tiles wide, 3 high, 7*3 = 21 total tiles)
var brickArray = [false, true, false, true, false, true, false,
false, true, true, true, false, true, false,
false, true, false, true, false, true, false] // Says 'HI' using tiles
override func didMove(to view: SKView) {
//MARK: Brick
for tile in 0..<brickArray.count {
if brickArray[tile] == true {
let brick = SKSpriteNode(imageNamed: "red_brick")
brick.position = CGPoint(x: (tile % widthOfTiles) * (widthPoints) - (widthOfTiles / 2 * (widthPoints)),
y: ((tile - (tile % widthOfTiles)) / widthOfTiles) * (heightPoints) - (heightOfTiles / 2 * (heightPoints)))
brick.size = CGSize(width: widthPoints, height: heightPoints)
brick.physicsBody = SKPhysicsBody(rectangleOf: brick.frame.size)
brick.physicsBody?.friction = 0
brick.physicsBody?.allowsRotation = false
brick.physicsBody?.friction = 0
brick.physicsBody?.isDynamic = false
brick.physicsBody?.categoryBitMask = brickCategory
self.addChild(brick)
}
}
}
我无法为我的生活让这一切成为现场的中心。也许有人可以帮我解决这个问题。数学是我的一个不好的弱点,虽然我认为我得到了正确的产卵方程,但这个位置已经过时了。
如果我遗失了你需要看的东西,请告诉我。
答案 0 :(得分:0)
除非你需要一个依赖于锚点的动画,否则我不会设置它并将其保留为默认值,否则它将改变图层位置的直观表示。