我试图建立一个突破性的游戏,我设置砖块确切地说,我希望他们为每个级别使用1 SKSpriteNode。这一切工作,因为他们在产卵,但远离屏幕左下角。我在didMove的开头使用了下面的一行(to view: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)
        }
    }
}

我一辈子都没法把这个放在场景的中心。也许有人能帮我弄清楚。数学是我的一个很差的弱点,虽然我认为我得到了产卵的正确方程式,但这个位置还差得很远。
如果我遗漏了你需要看的东西,请告诉我。

最佳答案

除非需要依赖于定位点的动画,否则我不会将其设置为默认值,否则将更改层位置的视觉表示。

关于ios - AnchroPoint x:0,y:0不适用于方程式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49991010/

10-13 06:59