LoginSignup
0
0

More than 1 year has passed since last update.

Android で Lua 言語で LÖVE2d で ’Hello World!’するまで。

Last updated at Posted at 2021-09-25

LÖVE2d はゲームエンジンです。
https://love2d.org/

As you probably know by now, LÖVE is a framework for making 2D games in the Lua programming language. LÖVE is totally free, and can be used in anything from friendly open-source hobby projects, to evil, closed-source commercial ones.

Lua言語が使えます。他のいくつかの言語でも非公式ですが使えるようです。

Fennel

Fennel is a programming language that brings together the speed, simplicity, and reach of Lua with the flexibility of a lisp syntax and macro system.
https://fennel-lang.org/


Hello World! に至るまでは、ここに参考となるチュートリアルがあります。

learn2love


この記事の内容は Android OS の環境(つまりタブレット)で google play store からインストールするアプリの LÖVE2d を使って GUI 上でHello World!するまで、です。

Termux を使います。( Termux でなくてもアプリでテキストエディターがあれば可能です。)

Hellow World! のためのプログラムの配置は、このようになっています。

Screenshot_20210926-013415.png

LÖVE2d では、main.luaというファイルに love.から始まるカスタムメソッドにプロパティを渡すプログラムコードがかかれていることが必要とされます。
main.luaのなかに、これだけを書きました。

main.lua
function love.draw()
      love.graphics.print('Hello World!',400,300)
end

gametest というフォルダ(ディレクトリ)のなかにあります。

u0_a185@localhost ~/gametest> tree ./
./
└── main.lua

0 directories, 1 file

このmain.luaを LÖVE2d のアプリで開けばいいわけですが、.loveというファイルにして LÖVE2d で開くことで main.lua が読み込まれます。

.loveとは zip 圧縮されたフォルダなのですが、LÖVE2d で読み込むには、そのフォルダの一階層目(ゼロ階層というべきか)にmain.luaがなくてはいけないということになっています。

つまり、hello.loveというアーカイブファイルを展開したら、ぽろっと main.luaというファイルが出てくる構造になっていないといけないということです。
展開したときに hello というフォルダに main.lua が入っているという構造ではエラーになります。

ここで、..で一階層上がって、

u0_a185@localhost ~/zip -r gametest.zip gametest/
u0_a185@localhost ~/mv gametest.zip hello.love

とすると、この場合、hello.loveのディレクトリ直下はフォルダになってしまいます。

フォルダを含めないで zip する方法としては、

u0_a185@localhost ~/gametest> zip hello.love main.lua

とするか、または、

u0_a185@localhost ~/gametest> zip -r -D hello.love *

とすると、hello.loveの直下はmain.luaになり、必要の無いフォルダが含まれず LÖVE2d でhello.loveを開いてもエラーになりません。

つまり、シェルコマンドで zip アーカイブするときにフォルダのなかにファイルを詰めるのではない方法ということになります。
この場合は、main.lua などがフォルダのなかにはない状態を実現することを説明しました。
他の画像や音声等のゲーム素材に使うものはフォルダに入った状態でアーカイブされていてもよいです。

Rf. https://sheepolution.com/learn/book/12
You can also put your image in a subdirectory, but in that case make sure to include the whole path.

myImage = love.graphics.newImage("path/to/sheep.png")

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0