love2d:图像没有被绘制

love2d: Image doesn`t get drawn

我正在尝试绘制我的地图(loadMap 和 drawMap)和播放器(ghost.png),但只有我的地图被绘制并且我没有遇到错误:

main.lua:

function love.load()
    getFiles()
    loadPlayer()
    loadMap("/maps/chez-peter.lua")
end
function love.draw()
    drawPlayer()
    drawMap()
end

function love.update(dt)
    getKeyboard(dt)
end

function getFiles()
    require("player-functions")
    require("map-functions")
end

玩家-functions.lua:

function getKeyboard(dt)
    if love.keyboard.isDown("up") then
        Player.y = Player.y - 20 * dt
    end
    if love.keyboard.isDown("down") then
        Player.y = Player.y + 20 * dt
    end
    if love.keyboard.isDown("right") then
        Player.x = Player.x + 20 * dt
    end
    if love.keyboard.isDown("left") then
        Player.x = Player.x - 20 * dt
    end
end


function loadPlayer()
    Player = {}
    Player.img = love.graphics.newImage("player/ghost.png")
    Player.x = 0
    Player.y = 0
end

function drawPlayer()
    love.graphics.draw(Player.img , Player.x, Player.y)
end

地图-functions.lua:

  TileTable = {}

  local width = #(tileString:match("[^\n]+"))

  for x = 1,width,1 do TileTable[x] = {} end

  local rowIndex,columnIndex = 1,1
  for row in tileString:gmatch("[^\n]+") do
    assert(#row == width, 'Map is not aligned: width of row ' ..tostring(rowIndex) .. ' should be ' .. tostring(width) .. ', but it is ' ..tostring(#row))
     columnIndex = 1
    for character in row:gmatch(".") do
      TileTable[columnIndex][rowIndex] = character
      columnIndex = columnIndex + 1
    end
    rowIndex=rowIndex+1
  end

end

function drawMap()
  for x,column in ipairs(TileTable) do
    for y,char in ipairs(column) do
      love.graphics.draw(Tileset, Quads[ char ] , (x-1)*TileW, (y-1)*TileH)
    end
  end
end

我正在使用带有内置 love2d 建筑的 sublime text。 如果您需要 chez-peter.lua,请询问并感谢您的帮助。 :)

尝试切换 drawPlayer/drawMap 方法的位置,以便先绘制地图,然后再绘制玩家。可能是它们都在绘制,但地图是在玩家上方绘制的。