Sign in to follow this  
Hugos

help [interpolateBetween]

Recommended Posts

Hey. I need your help!
I have this rectangle:

addEventHandler("onClientRender", root, windows)
-------------------------------------------------
function windows()
	dxDrawRectangle(0, y-y/7.5, y/1.6, y/15, tocolor(0, 0, 0), true)
end

How do I animate it with "interpolateBetween" so that it "leaves" (strEasingType - "Line") from the left corner?
Tell me how to WRITE correctly "interpolateBetween"! PLEASE)

Share this post


Link to post
local iStartTick = 0 -- Needs to get set using getTickCount() when you want to start your animation
local iAnimDuration = 2000 -- The animation takes 2s to perform

local x1 = 100 -- Left START position of your rectangle
local y1 = 100 -- Top START position of your rectangle
local x2 = 500 -- Left END position
local y2 = 500 -- Top END position

function render()
    local iProgress = (getTickCount() - iStartTick) / iAnimDuration -- Get the difference between now and startTick and divide by wanted duration to get the progress of your animation
    local x, y = interpolateBetween(x1, y1, 0, x2, y2, 0, iProgress, "Linear")
  
    dxDrawRectangle(x, y, 100, 100, tocolor(255, 255, 255, 255))
  
    if (iProgress >= 1) then -- If the animation is done stop the animation + rendering
    	iStartTick = 0;
    	removeEventHandler("onClientRender", root, render)
    end
end

function startAnimation() -- Call this function when you want to start your animation
    iStartTick = getTickCount()
    
    addEventHandler("onClientRender", root, render)
end

This will start rendering and animation always when you call startAnimation()
Hope with this you can do everything you want.

Edited by Ceeser
  • Thanks 1

Share this post


Link to post
On 05/09/2019 at 17:39, Ceeser said:

local iStartTick = 0 -- Needs to get set using getTickCount() when you want to start your animation
local iAnimDuration = 2000 -- The animation takes 2s to perform

local x1 = 100 -- Left START position of your rectangle
local y1 = 100 -- Top START position of your rectangle
local x2 = 500 -- Left END position
local y2 = 500 -- Top END position

function render()
    local iProgress = (getTickCount() - iStartTick) / iAnimDuration -- Get the difference between now and startTick and divide by wanted duration to get the progress of your animation
    local x, y = interpolateBetween(x1, y1, 0, x2, y2, 0, iProgress, "Linear")
  
    dxDrawRectangle(x, y, 100, 100, tocolor(255, 255, 255, 255))
  
    if (iProgress >= 1) then -- If the animation is done stop the animation + rendering
    	iStartTick = 0;
    	removeEventHandler("onClientRender", root, render)
    end
end

function startAnimation() -- Call this function when you want to start your animation
    iStartTick = getTickCount()
    
    addEventHandler("onClientRender", root, render)
end

This will start rendering and animation always when you call startAnimation()
Hope with this you can do everything you want.

Thanks!

Share this post


Link to post
On 05/09/2019 at 09:04, Hugos said:

Hey. I need your help!
I have this rectangle:


addEventHandler("onClientRender", root, windows)
-------------------------------------------------
function windows()
	dxDrawRectangle(0, y-y/7.5, y/1.6, y/15, tocolor(0, 0, 0), true)
end

How do I animate it with "interpolateBetween" so that it "leaves" (strEasingType - "Line") from the left corner?
Tell me how to WRITE correctly "interpolateBetween"! PLEASE)

And how can you return the rectangle to the starting position (you need to make a reverse animation)?

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.