博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
love2d教程1--最小的love2d程序
阅读量:6788 次
发布时间:2019-06-26

本文共 2823 字,大约阅读时间需要 9 分钟。

首先,新建一个文件夹,以及main.lua和conf.lua。

conf.lua

function love.conf(t)--设置标题和窗口大小t.title = "my first love" t.screen.width = 240t.screen.height = 320end

 

main.lua,这里暂时是几个空的常用回调函数

function love.load() --资源加载回调函数,仅初始化时调用一次endfunction love.draw() --绘图回调函数,每周期调用endfunction love.update(dt) --更新回调函数,每周期调用endfunction 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.

 

 

转载地址:http://zqigo.baihongyu.com/

你可能感兴趣的文章
bzoj1037生日聚会
查看>>
eclipse-->切换语言版本
查看>>
配置IIS服务器,APK文件下载
查看>>
2003应用池假死常见问题和解决方法
查看>>
使用javascript的日期函数
查看>>
c# : use xsd 校验 xml
查看>>
mybatis初接触
查看>>
没有测试的开发是多么的悲催哇
查看>>
awk的日志模块追加日期时间字段的方案
查看>>
[转]高级SQL注入:混淆和绕过
查看>>
System.IO.Path 文件名、路径、扩展名处理
查看>>
类的成员修饰符
查看>>
课堂训练
查看>>
HDU 5464:Clarke and problem
查看>>
Web服务器禁止range请求
查看>>
php编译GD库 JPEG Support
查看>>
【转】着色中的数学和物理原理
查看>>
overflow的使用
查看>>
Position Independent Code (PIC) in shared libraries on x64
查看>>
CNBLOG上几位.NET大牛的博客地址(转)
查看>>