DonBGBase = {} DonBGBase.__index = DonBGBase function DonBGBase.new(index, player_num, path) local self = setmetatable({}, DonBGBase) self.name = string.format("%d_%d", index - 1, player_num) self.path = path tex.load_folder(path, string.format("donbg/%s", self.name)) self.bg_texture = tex.get_texture_info(self.name, "background") self.move = anim.move(3000, { total_distance = -self.bg_texture.width, loop = true }) self.move:start() self.is_clear = false self.clear_fade = tex.get_animation(1) self._id_bg = tex.get_id(self.name, "background") or 0 return self end function DonBGBase:set_clear(is_clear) if is_clear and not self.is_clear then self.is_clear = true self.clear_fade:start() end if not is_clear and self.is_clear then self.is_clear = false self.clear_fade:reset() end end function DonBGBase:update(current_time_ms) self.move:update(current_time_ms) self.clear_fade:update(current_time_ms) end function DonBGBase:draw_textures(fade, y, frame) for i = 0, 4 do tex.draw_texture(self._id_bg, { frame = frame, fade = fade, x = (i * self.bg_texture.width) + self.move.attribute, y = y }) end end function DonBGBase:draw(y) y = y or 0 self:draw_textures(1.0, y, 0) if self.is_clear then self:draw_textures(self.clear_fade.attribute, y, 1) end end function DonBGBase:destroy() tex.unload_folder(self.path, string.format("donbg/%s", self.name)) end return DonBGBase