Error map-functions.lua:42: bad argument #2 to 'draw' (Quad expected, got nil) , 有什么错误吗?

我对love和lua都很新,不知道为什么我总是收到这个消息,有什么想法?这是我的代码,请问你们知道我应该做什么。

在maps-functions.lua中

function loadMap(path)
  love.filesystem.load(path)()
end

function newMap(tileW, tileH, tilesetPath, tileString, quadInfo)

  TileW = tileW
  TileH = tileH
  Tileset = love.graphics.newImage(tilesetPath)

  local tilesetW, tilesetH = Tileset:getWidth(), Tileset:getHeight()

  Quads = {}

  for _,info in ipairs(quadInfo) do
    -- info[1] = 字符,info[2] = x,info[3] = y
    Quads[info[1]] = love.graphics.newQuad(info[2], info[3], TileW,  TileH, tilesetW, tilesetH)
  end

  TileTable = {}

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

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

  local x,y = 1,1
  for row in tileString:gmatch("[^\n]+") do
    assert(#row == width, 'Map is not aligned: width of row ' .. tostring(y) .. ' should be ' .. tostring(width) .. ', but it is ' .. tostring(#row))
    x = 1
    for tile in row:gmatch(".") do
      TileTable[x][y] = tile
      x = x + 1
    end
    y=y+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

也许这与我绘制的地图或图像有关?

原文链接 https://stackoverflow.com/questions/70749760

点赞