Jump to content

Animation, intrepolateBetween..


DarkByte

Recommended Posts

Let the fProgress go from 1 to 0.

Like that:

local animcoming = true 
local progstart = 0 
  
local function drawThatAnim ( ) 
    local progress = 0 
    if animcoming then 
        progress = (getTickCount()-progstart)/5000  
        if progress >= 2 then  
            animcoming = false 
            progstart = getTickCount()+1050 
        end 
    else 
        progress = ( progstart - getTickCount() ) / 5000 
    end 
    local x, y = interpolateBetween ( 0, 0, 0, 1000, 1000, 0, progress, "Linear" ) 
    dxDrawRectangle ( x, y, 10, 10, tocolor ( 255, 0, 0 ), true ) 
end 
  
function stopAnimDraw ( ) 
    removeEventHandler ( "onClientRender", root, drawThatAnim ) 
end  
  
addCommandHandler ( "startanim", function ( ) 
    animcoming = true 
    progstart = getTickCount() 
    addEventHandler ( "onClientRender", root, drawThatAnim ) 
end ) 

Link to comment

Oh, I forgot to use stopAnimDraw:

local animcoming = true 
local progstart = 0 
  
local function drawThatAnim ( ) 
    local progress = 0 
    if animcoming then 
        progress = (getTickCount()-progstart)/5000 
        if progress >= 2 then 
            animcoming = false 
            progstart = getTickCount()+1050 
        end 
    else 
        progress = ( progstart - getTickCount() ) / 5000 
        if progress >= 1 then            -- NEW 
            stopAnimDraw()              -- NEW 
            return                            -- NEW 
        end                                  -- NEW 
    end 
    local x, y = interpolateBetween ( 0, 0, 0, 1000, 1000, 0, progress, "Linear" ) 
    dxDrawRectangle ( x, y, 10, 10, tocolor ( 255, 0, 0 ), true ) 
end 
  
function stopAnimDraw ( ) 
    removeEventHandler ( "onClientRender", root, drawThatAnim ) 
end 
  
addCommandHandler ( "startanim", function ( ) 
    animcoming = true 
    progstart = getTickCount() 
    addEventHandler ( "onClientRender", root, drawThatAnim ) 
end ) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...