在Corona SDK中为tileset生成等距网格
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Corona SDK中为tileset生成等距网格相关的知识,希望对你有一定的参考价值。
我导入了一个瓷砖制作的等轴测图到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
正如您在屏幕截图中看到的那样,瓷砖在地图一侧转向。如果有人知道如何解决它或需要更多信息的信息让我知道!
答案
试试代码:
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
我从x
得到了y
and Isometric Tiles Math瓷砖位置的公式。祝好运:)
以上是关于在Corona SDK中为tileset生成等距网格的主要内容,如果未能解决你的问题,请参考以下文章