如果你看看关于love.load的文档,它会说
此功能在游戏开始时只调用一次.
而且没有别的.它还有一个参数,即命令行参数.
所以如果你不使用args,有什么区别:
x = 5
-- rest of code
Run Code Online (Sandbox Code Playgroud)
和
function love.load()
x = 5
end
-- rest of code
Run Code Online (Sandbox Code Playgroud)
避免的最大好处love.load是你可以制造x本地而不是全球.使用有什么好处love.load吗?
我正在使用 Lua 和 LOVE2D 创建许多游戏,但每当我实现一个新功能并想要测试它,或者只是想知道 Lua 中变量的值时,我要么将其显示在游戏屏幕上,要么只是希望它作品。
现在我的问题是......有没有办法在终端或其他地方显示一些信息,例如变量值或其他内容?就像console.log在 javascript 中一样,它在浏览器的 javascript 控制台中显示一些内容。那么,Lua 有没有办法做到这一点?使用LOVE2D?
我使用的是 Mac,因此有terminal命令提示符,但没有命令提示符。有没有办法在那里显示一些内容?其他地方也可以,我只需要看看这些值是否符合预期。
标题.它只允许保存到某个目录,但有没有办法使用它自己更新自己?我有代码来检查它是否过时(HttpGet),但不知道如何安装更新的更新.
主要原因是人们抱怨不得不反复重新下载我的RPG.用它们可以运行的C#自动更新程序打包它会更容易吗?
好的,所以我希望快速生成一个相当大的表。看起来像这样的东西:
table{
{1, 1, 1, 1},
{1, 1, 1, 1},
{1, 1, 1, 1},
}
Run Code Online (Sandbox Code Playgroud)
只有表会包含更多的行,并且这些行中包含更多的值。我知道使用 table.insert() 我可以轻松地将所需的行添加到单行中,但是我是否也可以添加全新的行而无需将其全部输入?
每当我用数组做这样的事情时,我都会遇到一个非常恼人的错误.我有代码在love.load()函数中设置数组:
function iceToolsInit()
objectArray = {} --for object handling
objectArrayLocation = 0
end
Run Code Online (Sandbox Code Playgroud)
然后是允许创建对象的代码.它基本上抓取了有关所述对象的所有信息并将其插入到数组中.
function createObject(x, y, renderimage) --used in the load function
--objectArray is set up in the init function
objectArrayLocation = objectArrayLocation + 1
objectArray[objectArrayLocation] = {}
objectArray[objectArrayLocation]["X"] = x
objectArray[objectArrayLocation]["Y"] = y
objectArray[objectArrayLocation]["renderimage"] =
love.graphics.newImage(renderimage)
end
Run Code Online (Sandbox Code Playgroud)
在此之后,更新函数读取objectArray并相应地呈现图像:
function refreshObjects() --made for the update function
arrayLength = #objectArray
arraySearch = 0
while arraySearch <= arrayLength do
arraySearch = arraySearch + 1
renderX = objectArray[arraySearch]["X"]
renderY = …Run Code Online (Sandbox Code Playgroud) 所以今天我了解到Vim在一个非常类似于目录浏览器的界面中打开zip文件进行查看和修改.
有没有办法相应地打开.love文件?我尝试设置文件类型:
vim red-pill.love -c "set filetype=zip"
......但没有运气.它以二进制文件形式打开.
我正在学习Löve2d/ Lua,并尝试使用Perlin Noise算法生成噪音.
我在这里改编了Ken Perlin的改进噪音代码:
代码根据道格的答案编辑修复
-- original code by Ken Perlin: http://mrl.nyu.edu/~perlin/noise/
perlin = {}
perlin.p = {}
perlin.permutation = { 151,160,137,91,90,15,
131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180
}
perlin.size = 256
perlin.gx = {}
perlin.gy = {}
perlin.randMax = 256
function perlin:load( )
for i=1,self.size do
self.p[i] = self.permutation[i]
self.p[256+i] = self.p[i]
end
end
function perlin:noise( x, …Run Code Online (Sandbox Code Playgroud) 我尝试用Love2D打开游戏,出现以下错误:
错误
boot.lua:577: 无法在路径“/home/panali/Desktop/Lua.love/main.lua”加载游戏。确保指定路径中存在文件夹。
追溯
[C]:在函数“错误”中
[C]:在函数“xpcall”中
[C]:在函数“xpcall”中
谁能帮助我并告诉我我做错了什么?
所以我已经断断续续地工作了一个星期,谷歌搜索等等,我还没有找到如何做到这一点。
我有一张“射线”表和一张“线”表,我希望这些线充当镜子并在光线碰到一条线时反射光线。想象一下激光从镜子上反弹,那种反射。我已经让相交检测工作了,但我不知道如何正确计算反射角并将光线延伸到那个方向。
代码:
--the table rays is a table of tables, and each table inside is formatted as such:
--rays[x] = {100,200,150,600,200,400}, where (100,200) are ordered pairs, etc.
--The table lines simply contains values for x1,y1,x2,y2
for i,ray in ipairs(rays) do
for j,line in ipairs(lines) do
if line.x2 ~= nil and #ray>3 then
print(line.x2..' '..line.y2)
iX, iY = intersect.test(ray[#ray-3],ray[#ray-2],
ray[#ray-1],ray[#ray],line.x1,line.y1,line.x2,line.y2)
--The above code takes each ray and
--sees if it intersects with a line, with the intersect.test function
--Then if …Run Code Online (Sandbox Code Playgroud) love2d ×10
lua ×10
arrays ×1
console.log ×1
debugging ×1
download ×1
game-engine ×1
indexing ×1
math ×1
path ×1
perlin-noise ×1
vim ×1
zip ×1