首先,新建一個文件夾,以及main.lua和conf.lua。
conf.lua
function love.conf(t) --設置標題和窗口大小 t.title = "my first love" t.screen.width = 240 t.screen.height = 320 end
main.lua,這里暫時是幾個空的常用回調函數
function love.load() --資源加載回調函數,僅初始化時調用一次 end function love.draw() --繪圖回調函數,每周期調用 end function love.update(dt) --更新回調函數,每周期調用 end function love.keypressed(key) --鍵盤檢測回調函數,當鍵盤事件觸發是調用 end
在命令行里切換到main.lua所在目錄,或者用notepad++,運行菜單--open current dir cmd
輸入"love .",你會看的一個黑色的窗口。
說明
conf.lua會首先加載,你可以在conf.lua里加入你的配置或覆蓋love的默認配置
love的所有默認配置如下,禁止一些不用的模塊,可以輕微加快速度。
function love.conf(t) t.title = "Untitled" -- The title of the window the game is in (string) t.author = "Unnamed" -- The author of the game (string) t.url = nil -- The website of the game (string) t.identity = nil -- The name of the save directory (string) t.version = "0.8.0" -- The LÖVE version this game was made for (string) t.console = false -- Attach a console (boolean, Windows only) t.release = false -- Enable release mode (boolean) t.screen.width = 800 -- The window width (number) t.screen.height = 600 -- The window height (number) t.screen.fullscreen = false -- Enable fullscreen (boolean) t.screen.vsync = true -- Enable vertical sync (boolean) t.screen.fsaa = 0 -- The number of FSAA-buffers (number) t.modules.joystick = true -- Enable the joystick module (boolean) t.modules.audio = true -- Enable the audio module (boolean) t.modules.keyboard = true -- Enable the keyboard module (boolean) t.modules.event = true -- Enable the event module (boolean) t.modules.image = true -- Enable the image module (boolean) t.modules.graphics = true -- Enable the graphics module (boolean) t.modules.timer = true -- Enable the timer module (boolean) t.modules.mouse = true -- Enable the mouse module (boolean) t.modules.sound = true -- Enable the sound module (boolean) t.modules.physics = true -- Enable the physics module (boolean) end
注意不能禁止love.filesystem和love模塊
在main.lua里我們要處理游戲邏輯,主要依靠回調函數,它們會被love自動調用
所有的回調函數如下
love.draw Callback function used to draw on the screen every frame. love.focus Callback function triggered when window receives or loses focus. love.joystickpressed Called when a joystick button is pressed. love.joystickreleased Called when a joystick button is released. love.keypressed Callback function triggered when a key is pressed. love.keyreleased Callback function triggered when a key is released. love.load This function is called exactly once at the beginning of the game. love.mousepressed Callback function triggered when a mouse button is pressed. love.mousereleased Callback function triggered when a mouse button is released. love.quit Callback function triggered when the game is closed. love.run The main function, containing the main loop. A sensible default is used when left out. love.update Callback function used to update the state of the game every frame.