在 Corona SDK 中为 tileset 生成等距网格
Generating isometric grid for tileset in Corona SDK
我将一个用平铺制作的等轴测图导入到 Corona SDK,现在我试图覆盖一个网格层。我已经对等轴测网格做了很多阅读,但它们似乎都参考了高度是宽度一半的图块集。 (例如 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
正如您在屏幕截图中看到的那样,图块有些偏离地图的一侧。如果有人知道如何修复它或需要有关该信息的更多信息,请告诉我!
尝试代码:
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 得到 x
和 y
方块位置的公式。祝你好运:)
我将一个用平铺制作的等轴测图导入到 Corona SDK,现在我试图覆盖一个网格层。我已经对等轴测网格做了很多阅读,但它们似乎都参考了高度是宽度一半的图块集。 (例如 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
正如您在屏幕截图中看到的那样,图块有些偏离地图的一侧。如果有人知道如何修复它或需要有关该信息的更多信息,请告诉我!
尝试代码:
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 得到 x
和 y
方块位置的公式。祝你好运:)