在Corona SDK中为tileset生成等距网格

时间:2017-12-18 20:02:46

标签: lua grid corona isometric tiled

我导入了一个用瓷砖制作的等轴测图到Corona SDK,现在我正在尝试覆盖一个网格图层。我已经对等距网格进行了大量阅读,但似乎它们都参考了高度为宽度一半的tilesets。 (例如128x64px)。我正在使用一个tileset,要求网格为256x149px,我想我必须编辑网格生成功能以适应变化。任何帮助将不胜感激!

问题的截图(使用原始向量):

Original Vectors: https://image.ibb.co/emXpQR/Screen_Shot_2017_12_18_at_1_35_19_PM.png

Edited Vectors (the ones commented out in code): https://image.ibb.co/ikxOkR/Screen_Shot_2017_12_18_at_1_35_54_PM.png

网格生成代码:

function drawGrid()
               for row = 0, 16  do
                  local gridRow = {}
                  for col = 0, 9 do

                    -- draw a diamond shaped tile
                    local vertices = { 0,-16, -64,16, 0,48, 64,16 }
                    -- MY EDITED VERTICES { 0,-37.25, -128,37.25, 0,111.75, 128,37.25 }
                    local tile = display.newPolygon(group, 0, 0, vertices )

                    -- outline the tile and make it transparent
                            tile.strokeWidth = 1
                            tile:setStrokeColor( 0, 1, 1 )
                            tile.alpha = .4

                            local tileWidth = 256
                            local tileHeight = 149

                    -- set the tile's x and y coordinates
                    local x = col * tileHeight
                    local y = row * tileHeight

                    tile.x = (x - y)
                    tile.y = ((tileHeight/2) + ((x + y)/2))

                    -- make a tile walkable
                    gridRow[col] = 0
                  end
                  -- add gridRow table to the map table
                  j_map[row] = gridRow
               end
            end

正如您在屏幕截图中看到的那样,瓷砖会偏离地图的一侧。如果有人知道如何解决它或需要更多信息,请告诉我!

1 个答案:

答案 0 :(得分:0)

尝试代码:

for row = 0, 16  do
      local gridRow = {}
      for col = 0, 9 do

        -- draw a diamond shaped tile
        --local vertices = { 0,-16, -64,16, 0,48, 64,16 }
        -- MY EDITED VERTICES 
        local vertices = { 0,-37.25, -128,37.25, 0,111.75, 128,37.25 }
        local tile = display.newPolygon( group, 0, 0, vertices )

        -- outline the tile and make it transparent
                tile.strokeWidth = 1
                tile:setStrokeColor( 0, 1, 1 )
                tile.alpha = .4

                local tileWidth = 256
                local tileHeight = 149

        tile.x = -(row - col) * tileWidth * 0.5 
        tile.y = (row + col) * tileHeight * 0.5 

        -- make a tile walkable
        gridRow[col] = 0
      end
      -- add gridRow table to the map table
      --j_map[row] = gridRow
   end

我从Isometric Tiles Math获得了xy位置的公式。祝你好运:)