mieki256's diary



2017/11/05() [n年前の日記]

#2 [lua][love2d] love2dでタイルマップの表示

love2dでタイルマップBGを表示したいなと。

タイルマップは _Tiled Map Editor で作成するとして…。

ググってみたら、sti(Simple Tiled Implementation)を使うと楽になるらしい。

_karai17/Simple-Tiled-Implementation: Tiled library for LOVE
_Lua.Space | Using Tiled Maps in LOVE

試してみた。たしかに楽に表示できる。

tilemap_test01_ss.png

自作の画像やマップデータは以下。License : CC0 / Public Domain ってことで。

_tile01.png
_mecha_bg_map.tmx
_mecha_bg_map.lua

stiの使い方。 :

まず、Tiled から、.lua 形式でエクスポート。

sti を、 _karai17/Simple-Tiled-Implementation から、任意のフォルダ内で git でクローンするなり、zipでDL・解凍するなりして。
git clone https://github.com/karai17/Simple-Tiled-Implementation.git

main.lua があるフォルダに、stiフォルダを丸々コピー。例えば以下のようなファイル構成に。
.
|-- sti
|   |-- plugins
|   |   |-- box2d.lua
|   |   `-- bump.lua
|   |-- graphics.lua
|   |-- init.lua
|   `-- utils.lua
|
|-- conf.lua
|-- main.lua
|
|-- mecha_bg_map.lua : タイルマップデータ(.lua)
|-- mecha_bg_map.tmx : タイルマップデータ(.tmx)
`-- tile01.png : タイルマップで使う画像

表示するだけなら、以下で済む。
local sti = require "sti"

function love.load()
  map = sti("mecha_bg_map.lua")
end

function love.update(dt)
  map:update(dt)
end

function love.draw()
  map:draw()
end
簡単だ…。

ただ、スクロール等はどうすればいいのやら。調べてみないと。sti に同梱の main.lua が、カーソルキーやWASDキーでスクロールできているので、参考になりそうな予感。

以上です。

過去ログ表示

Prev - 2017/11 - Next
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30

カテゴリで表示

検索機能は Namazu for hns で提供されています。(詳細指定/ヘルプ


注意: 現在使用の日記自動生成システムは Version 2.19.6 です。
公開されている日記自動生成システムは Version 2.19.5 です。

Powered by hns-2.19.6, HyperNikkiSystem Project