jay
jay

Reputation: 25

love2d: Image doesn`t get drawn

I am trying to draw my map(loadMap and drawMap) and a player(ghost.png), but only my Map gets drawn and i do not gat an error:

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, '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

I am using sublime text with the built in love2d building. If you need chez-peter.lua just ask and thankyou for helping. :)

Upvotes: 0

Views: 454

Answers (1)

tval
tval

Reputation: 582

Try switching the position of the drawPlayer/drawMap methods so that you first draw the map, then draw the player. It could be that they are both being drawn, but the map is being drawn over the player.

Upvotes: 2

Related Questions