-- Floating text: damage numbers and other pop-up text FloatingText = {} FloatingText.__index = FloatingText function FloatingText:new(x, y, text, config) self = setmetatable({}, FloatingText) self.x = x self.y = y self.text = text self.life = config and config.life or 1 self.maxLife = self.life self.maxY = config and config.maxY or -40 self.size = config and config.size or 14 self.color = config and config.color or { 1, 0.2, 0.2 } self.fadeIn = config and config.fadeIn or 0.1 self.alive = true return self end function FloatingText:update(dt) self.life = self.life - dt if self.life <= 0 then self.alive = false return end self.y = self.y + self.maxY * dt end function FloatingText:draw() if self.life <= 0 then return end local alpha = self.life / self.maxLife if alpha > 1 then alpha = 1 end local fadeInT = math.min(1, (self.maxLife - self.life) / self.fadeIn) alpha = alpha * fadeInT love.graphics.setColor(self.color[1], self.color[2], self.color[3], alpha) love.graphics.print(self.text, math.floor(self.x), math.floor(self.y)) love.graphics.setColor(1, 1, 1, 1) end