【发布时间】:2017-05-01 10:04:05
【问题描述】:
我正在使用 lua 制作一个项目,该项目会在 lua 中从您的桌面获取所有文件名的列表。但是,我不知道该怎么做,我也将使用love2d,因为它将成为一个游戏。你能告诉我怎么做吗?谢谢!
这里是代码
function love.load()
require "player"
-- Lets add Some Variables!
-- Some Directory Suff first for Variables...
DesktopDirectory = love.filesystem.getUserDirectory().."Desktop"
DesktopFiles = love.filesystem.getDirectoryItems(DesktopDirectory)
-- These are the Images!
images = {
background = love.graphics.newImage("gfx/desktop.png")
}
players = {Player.New(50, 300, 40, 40, "gfx/stickman.png", true)}
love.graphics.setBackgroundColor(100, 220, 255)
for k in pairs(DesktopFiles) do
print(DesktopFiles[k])
end
end
function love.keypressed(k)
if k == "j" then
players[1].jump()
end
end
function love.update(dt)
for i in pairs(players) do
players[i].update()
end
end
function love.draw()
love.graphics.draw(images.background)
for i in pairs(players) do
players[i].draw()
end
end
【问题讨论】:
-
“从桌面访问文件”是什么意思?您只需要这些文件的列表吗?
-
几乎是的...我的意思是说“从您的桌面获取所有文件名的列表”...让我在问题中重新表述一下!
-
网上有很多关于如何在lua中获取文件列表的信息。例如阅读:stackoverflow.com/questions/5303174/…