LOVE2D-03-完整的LOVE2D程序

本文介绍了LOVE2D游戏开发的基本结构,包括`main.lua`和`conf.lua`两个核心文件的作用。`conf.lua`用于设置游戏窗口属性和管理模块加载,而`main.lua`则是游戏的主要逻辑代码。同时强调了`love.filesystem`和`love`模块的重要性,不能在`conf.lua`中禁止它们。
部署运行你感兴趣的模型镜像

 

love2d中文API地址https://love2d-cn.github.io/love2d-api/

 

一个完整的love2d源码包含2个基本的lua文件

main.lua  和  conf.lua

-------------------------------------------------------------------------------------------------------------------------------------------

conf.lua主要是对游戏程序的不必要的一些其他管理,如窗口大小,窗口标题,是否全屏,鼠标样式等等

man.lua主要是整个游戏的灵魂文件,所有资源的加载定义都必须在这个文件中完成,当然,也可以调用外部lua文件,和其他的文件。

-------------------------------------------------------------------------------------------------------------------------------------------

conf.lua会被首先执行,

-------------------------------------------------------------------------------------------------------------------------------------------

conf.lua 常用配置

function love.conf(win)
 
--设置标题和窗口大小
win.title = "My Love APP"
win.screen.width = 800
win.screen.height = 600
 
end

 

 

 

conf.lua 默认配置项

  使用conf.lua主要是管理游戏加载时的一些加载资源的管理

其中最主要的时conf.lua用来管理模块的加载与禁用,以提升游戏的加载速度,如:

function love.conf(win)
win.title = "Untitled" -- The title of the window the game is in (string)
win.author = "Unnamed" -- The author of the game (string)
win.url = nil -- The website of the game (string)
win.identity = nil -- The name of the save directory (string)
win.version = "0.8.0" -- The LÖVE version this game was made for (string)
win.console = false -- Attach a console (boolean, Windows only)
win.release = false -- Enable release mode (boolean)
win.screen.width = 800 -- The window width (number)
win.screen.height = 600 -- The window height (number)
win.screen.fullscreen = false -- Enable fullscreen (boolean)
win.screen.vsync = true -- Enable vertical sync (boolean)
win.screen.fsaa = 0 -- The number of FSAA-buffers (number)
win.modules.joystick = true -- Enable the joystick module (boolean)
win.modules.audio = true -- Enable the audio module (boolean)
win.modules.keyboard = true -- Enable the keyboard module (boolean)
win.modules.event = true -- Enable the event module (boolean)
win.modules.image = true -- Enable the image module (boolean)
win.modules.graphics = true -- Enable the graphics module (boolean)
win.modules.timer = true -- Enable the timer module (boolean)
win.modules.mouse = true -- Enable the mouse module (boolean)
win.modules.sound = true -- Enable the sound module (boolean)
win.modules.physics = true -- Enable the physics module (boolean)
end

但是绝不能禁止love.filesystem模块和love模块,如果禁止,在main.lua中就无法用love进行函数回调或调用,love.filesystem则是提供一个接口给用户的文件系统。

 

main.lua常用函数

function love.load() --资源加载回调函数,仅初始化时调用一次

end

function love.draw() --绘图回调函数,每周期调用

end

function love.update(dt) --更新回调函数,每周期调用

end

function love.keypressed(key) --键盘检测回调函数,当键盘事件触发是调用


end


main.lua所有回调函数

love.draw   
love.focus   
love.joystickpressed   
love.joystickreleased   
love.keypressed   
love.keyreleased  
love.load   
love.mousepressed  
love.mousereleased   
love.quit  
love.run 
love.update 


在以后将专门开设一篇文章来专门进行解释love2D中的所有函数

您可能感兴趣的与本文相关的镜像

Dify

Dify

AI应用
Agent编排

Dify 是一款开源的大语言模型(LLM)应用开发平台,它结合了 后端即服务(Backend as a Service) 和LLMOps 的理念,让开发者能快速、高效地构建和部署生产级的生成式AI应用。 它提供了包含模型兼容支持、Prompt 编排界面、RAG 引擎、Agent 框架、工作流编排等核心技术栈,并且提供了易用的界面和API,让技术和非技术人员都能参与到AI应用的开发过程中

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值