【问题标题】:How would I set a boundary around an isometric grid?如何在等距网格周围设置边界?
【发布时间】: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


    【解决方案1】:

    想法... -

    尝试从玩家和网格的角度来考虑,然后我们通过玩家和网格之外的碰撞(交叉点)来分配边界。例如,在 grid.x

    看来你有grid nxm,所以你可以试试看是否可以在grid[][]中分配玩家,否则它应该无法走开(如果它是基于回合的......)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-03
      • 1970-01-01
      • 1970-01-01
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多