2016-12-15 56 views
0

我正在为一些游戏制作一个模组,我正在使用一个基本的贴图地图,我想要将其扩展到更大的地图。但是,当我只使用“最近邻居”类型的缩放比例时,地图将具有硬方形边缘。我想阻止这一点。顺利地扩大瓷砖地图?

所以我有一个tilemap的,是这样的:

- - X - 
- X X X 
X X X X 
X X - - 

以我目前的比例,我得到这样的:

- - - - X X - - 
- - - - X X - - 
- - X X X X X X 
- - X X X X X X 
X X X X X X X X 
X X X X X X X X 
X X X X - - - - 
X X X X - - - - 

其中有一些硬的边缘,你可以看到。我希望他们更加流畅:

- - - - X X - - 
- - - X X X X - 
- - X X X X X X 
- X X X X X X X 
X X X X X X X X 
X X X X X X X X 
X X X X X X - - 
X X X X - - - - 

我不知道该怎么称呼这个,所以我的搜索没有多大变动。

我该怎么做这样的事情?

请注意,有几种不同类型的瓷砖,并且没有中间瓷砖类型。

回答

0

所以我玩了一下自己,发现了一些似乎工作得很好的东西。

这是我做的(LUA):

--First get the cells you're between (x and y are real numbers, not ints) 
local top = math.floor(y) 
local bottom = (top + 1) 
local left = math.floor(x) 
local right = (left + 1) 
--Then calculate weights. These are basically 1 - the distance. The distance is scaled to be between 0 and 1. 
local sqrt2 = math.sqrt(2) 
local w_top_left = 1 - math.sqrt((top - y)*(top - y) + (left - x)*(left - x))/sqrt2 
local w_top_right = 1 - math.sqrt((top - y)*(top - y) + (right - x)*(right - x))/sqrt2 
local w_bottom_left = 1 - math.sqrt((bottom - y)*(bottom - y) + (left - x)*(left - x))/sqrt2 
local w_bottom_right = 1 - math.sqrt((bottom - y)*(bottom - y) + (right - x)*(right - x))/sqrt2 
--Then square these weights, which makes it look better 
w_top_left = w_top_left * w_top_left 
w_top_right = w_top_right * w_top_right 
w_bottom_left = w_bottom_left * w_bottom_left 
w_bottom_right = w_bottom_right * w_bottom_right 
--Now get the codes (or types) of the surrounding tiles 
local c_top_left = decompressed_map_data[top % height][left % width] 
local c_top_right = decompressed_map_data[top % height][right % width] 
local c_bottom_left = decompressed_map_data[bottom % height][left % width] 
local c_bottom_right = decompressed_map_data[bottom % height][right % width] 
--Next calculate total weights for codes 
-- So add together the weights of surrounding tiles if they have the same type 
local totals = {} 
add_to_total(totals, w_top_left, c_top_left) --see below for this helper func 
add_to_total(totals, w_top_right, c_top_right) 
add_to_total(totals, w_bottom_left, c_bottom_left) 
add_to_total(totals, w_bottom_right, c_bottom_right) 
--Lastly choose final code, which is the tile-type with the highest weight 
local code = nil 
local weight = 0 
for _, total in pairs(totals) do 
    if total.weight > weight then 
     code = total.code 
     weight = total.weight 
    end 
end 
return terrain_codes[code] 

-- Helper function 
local function add_to_total(totals, weight, code) 
    if totals[code] == nil then 
     totals[code] = {code=code, weight=weight} 
    else 
     totals[code].weight = totals[code].weight + weight 
    end 
end 

瞧。这为任何x/y值选择了一个精确的tile-type,即使它们不是整数,这样就可以缩放网格。我不确定是否有更好的方法,但它有效,看起来不错。最后,我还在权重中添加了一些随机数,以使边缘稍微平直一些,这在缩放非常高的情况下在Factorio中看起来更好。

+1

良好的工作得到一些工作。我想你可能有兴趣[看看为像素艺术开发的一些缩放算法](https://en.wikipedia.org/wiki/Pixel_art_scaling_algorithms),因为应用程序看起来很相似。 – plast1k