joseleeph

Untitled

Jan 28th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. --util.lua
  2. function generateQuads(atlas, tilewidth, tileheight) --[[ atlas is like a spritesheet. a path to the texture]]
  3. local sheetWidth = atlas:getWidth()/tilewidth
  4. local sheetHeight = atlas:getHeight()/tileheight -- we can't use local variables outside the file
  5.  
  6. local sheetCounter = 1
  7. local quads = {} -- a table that will store the quads... rectangles chunks of textures
  8.  
  9. for y = 0, sheetHeight - 1 do
  10. for x = 0, sheetWidth - 1 do
  11. quads[sheetCounter] = love.graphics.newQuad(x * tilewidth, y * tileheight, tilewidth, tileheight, atlas:getDimensions()) -- arrays are 1 indexed
  12. sheetCounter = sheetCounter + 1 -- he says the issue is to increment the sheet counter... i'm still getting the same error
  13. end
  14. end
  15.  
  16. return quads
  17. end
  18.  
  19.  
  20. --[[
  21. Error
  22.  
  23. Map.lua:69: bad argument #2 to 'draw' (Quad expected, got nil)
  24.  
  25.  
  26. Traceback
  27.  
  28. [C]: in function 'draw'
  29. Map.lua:69: in function 'render'
  30. main.lua:34: in function 'draw'
  31. [C]: in function 'xpcall'
  32.  
  33. ]]
Advertisement
Add Comment
Please, Sign In to add comment