【发布时间】:2020-08-11 12:52:36
【问题描述】:
所以我制作了一个等距网格,作为游戏的世界/关卡,我想在网格周围设置边界,这样玩家就不能离开它们。由于它都是倾斜的,而且我编写的用于使网格自动放置瓷砖的函数,我无法尝试和错误 CGPoints,直到我把它们弄对。这是我用于网格的代码
func newTile(size:CGSize) -> SKShapeNode {
let shape = SKShapeNode()
let path = UIBezierPath()
path.move(to: CGPoint(x:0, y:size.height / 2.0))
path.addLine(to: CGPoint(x:size.width / 2.0, y:0))
path.addLine(to: CGPoint(x:0, y:-size.height / 2.0))
path.addLine(to: CGPoint(x:-size.width / 2.0, y:0))
path.close()
shape.path = path.cgPath
shape.lineWidth = 1.0
shape.fillColor = SKColor.gray
return shape
}
func tilePosition(col:Int, row:Int) -> CGPoint {
let x = (CGFloat(row) * tileWidth / 2.0) + (CGFloat(col) * tileWidth / 2.0)
let y = (CGFloat(col) * tileHeight / 2.0) - (CGFloat(row) * tileHeight / 2.0)
return CGPoint(x: x-2000, y: y-100)
}
let tileHeight:CGFloat = 45.0
let tileWidth:CGFloat = 90.0
let numRows = 40
let numCols = 40
let size = CGSize(width: tileWidth, height: tileHeight)
for row in 1...numRows {
for col in 1...numCols {
let tile = newTile(size: size)
tile.position = tilePosition(col: col, row: row)
self.addChild(tile)
}
}
如何在它创建的最后一个图块上设置边界?
【问题讨论】:
标签: swift xcode boundary isometric