gif или анимация в гуи

dmitry.karle

Известный
Автор темы
407
108
Версия MoonLoader
Другое
какой есть вариант добавить эту анимацию в mimgui?
 

Andrinall

Известный
702
528
какой есть вариант добавить эту анимацию в mimgui?
Есть такая вот штука, можно поиграться с значениями и заменить AddCircleFilled на какой-нибудь AddImage или AddImageQuad(если надо сделать ещё и рандомный поворот картинки, например) и туда пихнуть картинку снежинок.


Lua:
function Snowflake:Render()
    --imgui.GetWindowDrawList():AddCircleFilled(imgui.ImVec2(self.pos.x, self.pos.y), self.radius, self.color)
    imgui.GetWindowDrawList():AddImage(
        your_image,
        self.pos - imgui.ImVec2(self.radius, self.radius),
        self.pos + imgui.ImVec2(self.radius, self.radius),
        imgui.ImVec2(0, 0), imgui.ImVec2(1, 1), 0xFFFFFFFF
    )
end
 
Последнее редактирование:

donaks.

Известный
104
72
Сам столкнулся с этим. Просто режь гифку на кадры - обычные картинки - и обновляй их каждый кадр.


Гифка в imgui:
local GIF_FRAME_DELAY_MS = 30

local animation = {} -- тут будет хранится массив файлов
local animationStartedAt = nil

function drawWindow()
    -- ...

    local frameIndex = animation and getFrameIndex(#animation.frames)
    local texture = frameIndex and animation[frameIndex]

    if texture then
        imgui.Image(texture, imgui.ImVec2(256, 170))
    end
   
    -- ...
end

function getFrameIndex(frameCount)
    if not frameCount or frameCount <= 0 then
        return nil
    end

    if not animationStartedAt then
        animationStartedAt = getTimeMs()
    end

    local elapsedMs = getTimeMs() - animationStartedAt
    local loopDurationMs = frameCount * GIF_FRAME_DELAY_MS

    return math.floor((elapsedMs % loopDurationMs) / GIF_FRAME_DELAY_MS) + 1
end

function getTimeMs()
    if type(getGameTimer) == 'function' then
        return getGameTimer()
    end

    if type(sampGetTickCount) == 'function' then
        return sampGetTickCount()
    end

    return os.clock() * 1000
end
 

kyrtion

Проверенный
1,467
594
Сам столкнулся с этим. Просто режь гифку на кадры - обычные картинки - и обновляй их каждый кадр.


Гифка в imgui:
local GIF_FRAME_DELAY_MS = 30

local animation = {} -- тут будет хранится массив файлов
local animationStartedAt = nil

function drawWindow()
    -- ...

    local frameIndex = animation and getFrameIndex(#animation.frames)
    local texture = frameIndex and animation[frameIndex]

    if texture then
        imgui.Image(texture, imgui.ImVec2(256, 170))
    end
  
    -- ...
end

function getFrameIndex(frameCount)
    if not frameCount or frameCount <= 0 then
        return nil
    end

    if not animationStartedAt then
        animationStartedAt = getTimeMs()
    end

    local elapsedMs = getTimeMs() - animationStartedAt
    local loopDurationMs = frameCount * GIF_FRAME_DELAY_MS

    return math.floor((elapsedMs % loopDurationMs) / GIF_FRAME_DELAY_MS) + 1
end

function getTimeMs()
    if type(getGameTimer) == 'function' then
        return getGameTimer()
    end

    if type(sampGetTickCount) == 'function' then
        return sampGetTickCount()
    end

    return os.clock() * 1000
end
протестируй, мб лучше станет