dynamic sprite loading

This commit is contained in:
jill 2021-01-26 00:17:32 +03:00
parent c575497b3f
commit 738398fc2b
Signed by: oat
GPG key ID: DD83A9617A252385
2 changed files with 21 additions and 3 deletions

View file

@ -1,11 +1,13 @@
require 'lib.audio'
local assets = {}
local rawsprites = {}
function assets.clear()
print(" clearing assets")
sprites = {}
rawsprites = {}
sound_path = {}
music_path = {}
end
@ -13,8 +15,15 @@ end
function assets.load(base)
print(" loading " .. base)
assets.addSprites(base)
print("✓ added sprites")
setmetatable(sprites, {__index = function(tbl, i)
if rawsprites[i] then return rawsprites[i] end
local sprite = love.graphics.newImage('assets/sprites/' .. i .. '.png')
rawsprites[i] = sprite
return sprite
end})
--assets.addSprites(base)
--print("✓ added sprites")
assets.addAudio(base)
print("✓ added audio")