love2d教程1--最小的love2d程序

首先,新建一个文件夹,以及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.

 

 

posted @ 2012-12-07 09:06  半山无极  阅读(7990)  评论(7编辑  收藏  举报