AnchroPoint x:0、y:0 无法使用等式
AnchroPoint x:0, y:0 not working with equation
我正在尝试构建一个 Breakout 游戏,我在其中使用 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)
}
}
}
我这辈子都不能让它出现在场景的中心。也许有人可以帮我解决这个问题。数学是我的一个弱点,虽然我认为我得到了产卵的正确方程式,但位置还差得远。
如果我遗漏了您需要查看的内容,请告诉我。
除非您需要依赖于锚点的动画,否则我不会设置它并将其保留为默认值,否则它会改变图层位置的视觉表示。
我正在尝试构建一个 Breakout 游戏,我在其中使用 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)
}
}
}
我这辈子都不能让它出现在场景的中心。也许有人可以帮我解决这个问题。数学是我的一个弱点,虽然我认为我得到了产卵的正确方程式,但位置还差得远。
如果我遗漏了您需要查看的内容,请告诉我。
除非您需要依赖于锚点的动画,否则我不会设置它并将其保留为默认值,否则它会改变图层位置的视觉表示。