在科罗纳 SDK 中为图块集生成等距网格



我将平铺制作的等距地图导入了 Corona SDK,现在正在尝试叠加网格图层。我已经对等距网格进行了大量阅读,但似乎它们都引用了高度为宽度一半的图块集。(例如 128x64 像素)。我正在使用一个要求网格为 256x149 像素的图块集,我认为我必须编辑网格生成功能以适应更改。任何帮助将不胜感激!

问题的屏幕截图(使用原始矢量):

原始载体:https://image.ibb.co/emXpQR/Screen_Shot_2017_12_18_at_1_35_19_PM.png

编辑的向量(在代码中注释掉的向量):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

我从等距瓷砖数学中获得了xy瓷砖位置的公式。 祝你好运:)

相关内容

  • 没有找到相关文章

最新更新