love2d:图像不被绘制

时间:2017-12-28 16:59:26

标签: lua 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

地图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建筑的崇高文字。 如果你需要chez-peter.lua,请询问并谢谢你的帮助。 :)

1 个答案:

答案 0 :(得分:2)

尝试切换drawPlayer / drawMap方法的位置,以便首先绘制地图,然后绘制播放器。可能是他们都被绘制了,但是地图正在被玩家吸引。