Animasyon Ekleme GUI

0 Üye ve 1 Ziyaretçi konuyu incelemekte.

Çevrimdışı Meta_Script

  • Yeni Üye
  • *
    • İleti: 51
  • Meta Script
: 23 Ocak 2023, 13:59:49
Merhaba, bugün sizlere GUI için yaptığım animasyon fonksiyonlarını paylaşacağım. Kodları inceleyip animasyon mantığını çözebilir ve panellerinizde kullanabilirsiniz


Kod
Kod
-------------------------------------------
--GUI Animations
-------------------------------------------
local animations = {}
local anim_timers = {}

--Gui moving animation
function guiMoveTo(elm,movex,movey,relative,easing,duration,waiting)
    local x,y = guiGetPosition(elm,relative)
    local tick  = getTickCount()
    table.insert(animations,{anim_type="moving",elm=elm,startx=x,starty=y,movex=movex,movey=movey,relative=relative,oldTick=tick,easing=easing,duration=duration})
    if waiting then
        table.insert(anim_timers,{
            elm = elm,
            timer = setTimer(function(elm,startx,starty,movex,movey,relative,easing,duration)
                table.insert(animations,{anim_type="moving",elm=elm,startx=x,starty=y,movex=movex,movey=movey,relative=relative,oldTick=tick,easing=easing,duration=duration})
            end,waiting,1,elm,startx,starty,movex,movey,relative,easing,duration)
        })
    end
end


--Gui sizing animation
function guiSizeTo(elm,sizew,sizeh,relative,easing,duration,waiting)
    local w,h = guiGetSize(elm,relative)
    local tick  = getTickCount()
    table.insert(animations,{anim_type="sizing",elm=elm,startw=w,starth=h,sizew=sizew,sizeh=sizeh,relative=relative,oldTick=tick,easing=easing,duration=duration})
    if waiting then
        table.insert(anim_timers,{
            elm = elm,
            timer = setTimer(function(elm,startx,starty,sizex,sizey,relative,easing,duration)
                table.insert(animations,{anim_type="sizing",elm=elm,startw=w,starth=h,sizew=sizew,sizeh=h,relative=relative,oldTick=tick,easing=easing,duration=duration})
            end,waiting,1,elm,w,hsizex,sizey,relative,easing,duration)
        })
    end
end

--Gui Alpha animation
function guiAlphaTo(elm,movealpha,easing,duration,waiting)
    local startalpha = guiGetAlpha(elm)
    local tick  = getTickCount()
    table.insert(animations,{anim_type="alpha",elm=elm,startalpha=startalpha,movealpha=movealpha,oldTick=tick,easing=easing,duration=duration})
    if waiting then
        table.insert(anim_timers,{
            elm = elm,
            timer = setTimer(function(elm,startalpha,movealpha,easing,duration)
                table.insert(animations,{anim_type="alpha",elm=elm,startalpha=startalpha,movealpha=movealpha,oldTick=tick,easing=easing,duration=duration})
            end,waiting,1,elm,startalpha,movealpha,easing,duration)
        })
    end
end


function guiStopAniming(elm)
    for k,v in ipairs(anim_timers) do
        if v.elm == elm then
            if isTimer(v.timer) then
                killTimer(v.timer)
            end
            table.remove(anim_timers,k)
        end
    end
    for index,animt in ipairs(animations) do
        if animt.elm == elm then
            table.remove(animations,index)
        end
    end
end


function setAnimRender()
    local nowTick = getTickCount()
    for index,animt in ipairs(animations) do


        if animt.anim_type == "moving" then
            if animt.relative then
                local startx,starty = relativeto(animt.startx,animt.starty)
                local movex,movey =  relativeto(animt.movex,animt.movey)
                movex,movey = interpolateBetween(startx,starty,0,movex,movey,0,(nowTick-animt.oldTick)/animt.duration,animt.easing)
                movex,movey = torelative(movex,movey)
                guiSetPosition(animt.elm,movex,movey,animt.relative)
                if nowTick-animt.oldTick  > animt.duration then  table.remove(animations,index) end
            else
                local movex,movey = interpolateBetween(animt.startx,animt.starty,0,animt.movex,animt.movey,0,(nowTick-animt.oldTick)/animt.duration,animt.easing)
                guiSetPosition(animt.elm,movex,movey,animt.relative)
                if nowTick-animt.oldTick  > animt.duration then  table.remove(animations,index)  end
            end
        end


        if animt.anim_type == "alpha" then
            local movealpha= interpolateBetween(animt.startalpha,0,0,animt.movealpha,0,0,(nowTick-animt.oldTick)/animt.duration,animt.easing)
            guiSetAlpha(animt.elm,movealpha)
            if nowTick-animt.oldTick  > animt.duration then  table.remove(animations,index)  end
        end


        if animt.anim_type == "sizing" then
            if animt.relative then
                local startw,starth = relativeto(animt.startw,animt.starth)
                local sizew,sizeh =  relativeto(animt.sizew,animt.sizeh)
                sizew,sizeh = interpolateBetween(startw,starth,0,sizew,sizeh,0,(nowTick-animt.oldTick)/animt.duration,animt.easing)
                sizew,sizeh = torelative(sizew,sizeh)
                guiSetSize(animt.elm,sizew,sizeh,animt.relative)
                if nowTick-animt.oldTick  > animt.duration then  table.remove(animations,index) end
            else
                local movew,moveh = interpolateBetween(animt.startw,animt.starth,0,animt.sizew,animt.sizeh,0,(nowTick-animt.oldTick)/animt.duration,animt.easing)
                guiSetSize(animt.elm,sizew,sizeh,animt.relative)
                if nowTick-animt.oldTick  > animt.duration then  table.remove(animations,index)  end
            end
        end       
    end
end

addEventHandler("onClientRender",root,setAnimRender)


---Custom Anims
--------------------------------------------------
--gui Alert Animation ( - gui uyarı animasyonu - )
---------------------------------------------------
function guiAlertAnim(element,relative)
    if not element then return end
    local elm_x,elm_y = guiGetPosition(element,relative)
    local move_result = 0
    if relative then
        move_result =  0.01
    else
        move_result = 10
    end
    guiMoveTo(element,elm_x-move_result,elm_y,relative,"SineCurve",500)
    guiMoveTo(element,elm_x+move_result,elm_y,relative,"SineCurve",500,50)
    guiMoveTo(element,elm_x-move_result,elm_y,relative,"SineCurve",500,100)
    guiMoveTo(element,elm_x+move_result,elm_y,relative,"SineCurve",500,150)
    guiMoveTo(element,elm_x-move_result,elm_y,relative,"SineCurve",500,200)
    guiMoveTo(element,elm_x+move_result,elm_y,relative,"SineCurve",500,250)
    guiMoveTo(element,elm_x-move_result,elm_y,relative,"SineCurve",500,300)
    guiMoveTo(element,elm_x+move_result,elm_y,relative,"SineCurve",500,350)
    guiMoveTo(element,elm_x-move_result,elm_y,relative,"SineCurve",500,400)
    guiMoveTo(element,elm_x,elm_y,relative,"SineCurve",500,450)
    setTimer(function(element,elm_x,elm_y,relative)
        guiStopAniming(element)
        guiSetPosition(element,elm_x,elm_y,relative)
    end,650,1,element,elm_x,elm_y,relative)
end



Örnek
Kod
function click_fc()
    print("tıklama be")
    guiSetSize(panel,0.1,0.1,true)
    guiSizeTo(panel,0.5,0.5,true,"Linear",2000)
end

function click_fc2()
    print("tıklama be")
    guiAlertAnim(panel2,true)
    guiSetAlpha(panel2,0)
    guiAlphaTo(panel2,1.25,"Linear",1000)
end
« Son Düzenleme: 25 Temmuz 2023, 02:43:56 Gönderen: Narkoz »
META SCRİPT
Linki görebilmek için Kayıt olun yada Giriş yapın.
 


MTASATURK

Animasyon Ekleme GUI
« : 23 Ocak 2023, 13:59:49 »