2016-12-15 4 views
0

私はいくつかのゲームのためのMODを作っています。私はより大きな地図に拡大縮小したいベースタイルマップを使用しています。しかし、私はちょうど "最近隣"の種類のスケーリングを使用すると、マップは硬い方形のエッジを持つことになります。私はこれを防止したい。あなたが見ることができるように、いくつかのハードエッジを持っていタイルマップのスムーズな拡大?

- - - - 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値の正確なタイルタイプを選択し、グリッドを拡大縮小することができます。より良い方法があるかどうかはわかりませんが、うまくいくように見えます。最後に、私はまた、非常に高いスケーリングのときFactorioでよく見える少し少ないストレートを作るために、ウェイトにいくつかの乱数を追加しました。

+1

効果的なものを得る良い仕事。アプリケーションが類似しているように、あなたは[ピクセルアートのために開発されたいくつかのスケーリングアルゴリズムを見る](https://en.wikipedia.org/wiki/Pixel_art_scaling_algorithms)に興味があると思った。 – plast1k

関連する問題