love2d:无法绘制图片

我试图绘制我的地图(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

player-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

map-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, '地图未对齐:第' ..tostring(rowIndex) .. '行的宽度应该为' .. tostring(width) .. ',但实际宽度为' ..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,请告诉我,谢谢帮助。 :)

点赞
用户5792527
用户5792527

尝试交换 drawPlayer/drawMap 方法的位置,先绘制地图,然后绘制玩家。可能是两者都被绘制了,但是地图被绘制在了玩家上方。

2017-12-28 17:11:35