local G = love.graphics local msgs = {} local function add(str) table.insert(msgs, 1, {text=G.newText(G.getFont(),str),time=10}) end local margin_bottom = 70 local function draw() if #msgs == 0 then return end local W,H = G.getDimensions() local maxw = 0 local sumh = 0 for _,msg in ipairs(msgs) do local text = msg.text maxw = math.max(maxw,text:getWidth()) sumh = sumh + text:getHeight() end G.setColor(0,0,0,0.8) G.rectangle("fill",0,H-sumh-margin_bottom,maxw,sumh) G.setColor(1,1,1) local cury = H for _,msg in ipairs(msgs) do local text = msg.text local h = text:getHeight() G.draw(text,0,cury-h-margin_bottom) cury = cury - h end end local function update(dt) for ix = #msgs,1,-1 do local m = msgs[ix] m.time = m.time - dt if m.time <= 0 then msgs[ix] = nil end end end return { draw=draw, update=update, add=add, }