Difference between revisions of "Config Files (简体中文)"

(Love 当前版本的配置文件)
m (love.conf)
Line 25: Line 25:
 
</source>
 
</source>
  
在发行游戏时,把不需要的模块设置为false是一件值得鼓励的事。这将减少启动时间(稍微的)和减少内存占用(稍微的)。
+
在发行游戏时,把不需要的模块设置为false是一件值得鼓励的事。这将稍微减少启动时间(特别是禁用 joystick 模块)和减少内存占用(稍微的)。
  
 
== Love 当前版本的配置文件 ==
 
== Love 当前版本的配置文件 ==

Revision as of 05:47, 16 October 2019

介绍

如果在游戏文件夹中(或在 .love 文件中)有一个名为 conf.lua 的文件, 它将在 LÖVE 模块加载 之前 运行。你能使用这个文件重写稍后将被 LÖVE '启动' 脚本调用的 love.conf 函数。利用 love.conf 函数, 可以设置一些配置选项和改变一些设置,诸如窗口默认尺寸,要加载哪些模块及其它的一些设置。

love.conf

love.conf 函数有一个参数:一个填满所有默认数值的表,并且你可以根据喜好更改这些参数。例如,想更改默认的屏幕尺寸:

function love.conf(t)
    t.window.width = 1024
    t.window.height = 768
    --[[ 0.8及之前版本为:
    t.screen.width = 1024
    t.screen.height = 768
    ]]
end

再举个栗子:如果不需要物理模块或手柄模块,就这么写

function love.conf(t)
    t.modules.joystick = false
    t.modules.physics = false
end

在发行游戏时,把不需要的模块设置为false是一件值得鼓励的事。这将稍微减少启动时间(特别是禁用 joystick 模块)和减少内存占用(稍微的)。

Love 当前版本的配置文件

下面是 LÖVE 11.0 版本的所有选项及它们的缺省值列表:

 
function love.conf(t)
    t.identity = nil                   -- 盘存文件夹的名称 (string)
    t.appendidentity = false            -- Search files in source directory before save directory (boolean)
    t.version = "11.0"                -- 此游戏对应的 LÖVE 版本(string)
    t.console = false                  -- 附带控制台 (boolean, Windows only)
    t.accelerometerjoystick = true      -- 通过将其暴露为操纵杆来启用 iOS and Android 上的加速度计 (boolean)
    t.externalstorage = false           -- 设为 True 会使程序在 Android 的外部存储中储存(和在同一目录读取)文件 (boolean) 
    t.gammacorrect = false              -- 当系统支持时,启用伽玛校正渲染 (boolean)

    t.audio.mixwithsystem = true        -- 在 LOVE 运行时启用后台播放 (boolean, iOS and Android only)

    t.window.title = "Untitled"        -- 程序窗口标题 (string)
    t.window.icon = nil                -- 使用一张游戏目录中的图片作为窗口图标 (string)
    t.window.width = 800               -- 程序窗口宽 (number)
    t.window.height = 600              -- 程序窗口高 (number)
    t.window.borderless = false        -- 移除所有程序边框的视觉效果 (boolean)
    t.window.resizable = false         -- 允许鼠标拖动调整窗口的宽度和高度 (boolean)
    t.window.minwidth = 1              -- 程序窗口的最小宽度,仅当t.window.resizable = true 时生效 (number)
    t.window.minheight = 1             -- 程序窗口的最小高度,仅当t.window.resizable = true 时生效 (number)
    t.window.fullscreen = false        -- 打开程序后全屏运行游戏 (boolean)
    t.window.fullscreentype = "desktop" -- 全屏的模式,有 "desktop" 桌面全屏 和 "exclusive" 全屏 两种选择 (string)
    t.window.vsync = 1              -- 垂直同步模式 (number)
    t.window.msaa = 0                  -- 多样本采样抗锯齿时的样本数 (number)
    t.window.depth = nil                -- The number of bits per sample in the depth buffer
    t.window.stencil = nil              -- The number of bits per sample in the stencil buffer
    t.window.display = 1               -- 显示器的指示显示窗口 (number)
    t.window.highdpi = false           -- 允许在视网膜显示器(Retina)下使用高DPI模式 (boolean)
    t.window.x = nil                    -- 指定显示中窗口位置的 x坐标 (number)
    t.window.y = nil                    -- 指定显示中窗口位置的 y坐标 (number)
 
    t.modules.audio = true             -- 加载 audio        模块 (boolean)
    t.modules.data = true               -- 加载 data        模块 (boolean)
    t.modules.event = true             -- 加载 event        模块 (boolean)
    t.modules.font = true               -- 加载 font        模块 (boolean)
    t.modules.graphics = true          -- 加载 graphics     模块 (boolean)
    t.modules.image = true             -- 加载 image        模块 (boolean)
    t.modules.joystick = true          -- 加载 the joystick 模块 (boolean)
    t.modules.keyboard = true          -- 加载 keyboard     模块 (boolean)
    t.modules.math = true              -- 加载 math         模块 (boolean)
    t.modules.mouse = true             -- 加载 mouse        模块 (boolean)
    t.modules.physics = true           -- 加载 physics      模块 (boolean)
    t.modules.sound = true             -- 加载 sound        模块 (boolean)
    t.modules.system = true            -- 加载 system       模块 (boolean)
    t.modules.thread = true             -- 加载 thread       模块 (boolean)
    t.modules.timer = true             -- 加载 timer        模块 (boolean),取消加载此模块会导致 love.update 中 delta time 为 0
    t.modules.touch = true              -- 加载 touch       模块 (boolean)
    t.modules.video = true              -- 加载 video       模块 (boolean)
    t.modules.window = true            -- 加载 window       模块 (boolean)
end

0.92 后未检验 注意,不能禁止love.filesystem; 他是被强制使用的。同样对 love 模块本身也是如此。

最新版本的love.conf函数的选项内容总是可能会发生变化的,请注意这一点,0.92及更早版本的love.conf配置列表请参看英文wiki

简单说明

identity

identity的值应该为存盘目录名,而非存盘的绝对或相对路径:

t.identity = "gabe_HL3" -- 正确
--[[
t.identity = "c:/Users/gabe/HL3"、"./save" 以及 " ~/config/gabe" 都是错误的 
]]

另外 love.filesystem.setIdentity 函数也可以用来设置love2d的存盘目录名。

version

Available since LÖVE 0.8.0
This flag is not supported in earlier versions.

t.version设置的意义在于告诉玩家作者在开发此款游戏时使用的love2d版本,t.version的值应当为一个字符串,即类似"0.9.2"这样的。顺便说一句love2d的版本号规则,love2d的版本号遵循X.Y.Z的设定,X代表主版本号,通常意味着有革命性的功能变化;Y代表次版本号,一般表示有局部的功能改进;Z是补丁版本号,通常意味着非常少或者没有功能改进,只是程序稳定性或BUG修复。

通常一款love2d开发的游戏,在主版本号和次版本号相同,补丁版本号不同的love2d下运行时,兼容性问题是非常小的;当你所运行的love2d引擎程序(请注意love2d引擎和love2d游戏包是两个不同物体)和作者开发所使用的主版本和次版本号不同时,不建议运行此游戏,你应当更换到和作者同版本的love2d引擎程序来运行游戏。

window

Available since LÖVE 0.9.0
This flag is not supported in earlier versions.

t.window系列设置项用以设置游戏窗口相关内容,例如窗口宽和高,是否能拖拽修改宽高,是否默认全屏等等。

需要说明,在0.8及之前版本设置窗口的变量叫做t.screen,如果你的程序想同时兼容新老love2d引擎,可以这样写

function love.conf(t)
    --在0.9版本下写法
    t.window = t.window or t.screen
    t.window.width = 1024
    t.window.height = 768
    --t.window的其他子项以此类推

    --在0.8及之前版本写法
    t.screen = t.screen or t.window
    t.screen.width = 1024
end

window.fullscreentype

Available since LÖVE 0.9.0
This flag is not supported in earlier versions.

window.fullscreentype用来设置游戏全屏的方式,可选值为normaldesktop。其中desktop指的是保留操作系统的任务栏(OSX的Dock及Linux下的Dock类程序亦保留)和程序的标题栏模式的全屏方式。

See Also


Other Languages