Jump to content

help interpolateBetween


iiv03

Recommended Posts

how should I move position dxdraw rectangle if try to check progress time has end up ?


	borderY = interpolateBetween ( sy/1, 0, 0, sy/1.15, 0, 0, progress, "Linear")

	dxDrawRectangle ( 0, borderY, sx, 100, tocolor(0,0,0,255),false) -- panel


	if progress >= 1 then
  	-- i want move position Y goes down but how??
  	-- tired: borderY = borderY-50 It didn't work for me
  	end

 

Link to comment

Hello,

I wrote some stuff I think it might help you out.

local sx, sy = guiGetScreenSize()
local progress = 0;
local borderY = 0;
local animState = 0
local panelTick = getTickCount()

function animatePanel()
	local tick = getTickCount() - panelTick
	local progress = tick/1000

	if progress >= 1 then -- anim finished
		--togglePanel() -- uncomment if you want it to go back down once the animation finishes
	end

	if animState == 1 then
		borderY = interpolateBetween ( sy/1, 0, 0, sy/1.15, 0, 0, progress, "Linear")
	else
		borderY = interpolateBetween ( sy/1.15, 0, 0, sy/1, 0, 0, progress, "Linear")
	end

	dxDrawRectangle ( 0, borderY, sx, 100, tocolor(0,0,0,255),false) -- panel
end

function togglePanel()
	if animState == 0 then
		animState = 1 -- opening
	else
		animState = 0 -- closing
	end

	panelTick = getTickCount()
	removeEventHandler("onClientRender",getRootElement(),animatePanel)
	addEventHandler("onClientRender",getRootElement(),animatePanel)
end
addCommandHandler("tog", togglePanel)

 

Edited by SpecT
  • Thanks 1
Link to comment
1 hour ago, SpecT said:

Hello,

I wrote some stuff I think it might help you out.


local sx, sy = guiGetScreenSize()
local progress = 0;
local borderY = 0;
local animState = 0
local panelTick = getTickCount()

function animatePanel()
	local tick = getTickCount() - panelTick
	local progress = tick/1000

	if progress >= 1 then -- anim finished
		--togglePanel() -- uncomment if you want it to go back down once the animation finishes
	end

	if animState == 1 then
		borderY = interpolateBetween ( sy/1, 0, 0, sy/1.15, 0, 0, progress, "Linear")
	else
		borderY = interpolateBetween ( sy/1.15, 0, 0, sy/1, 0, 0, progress, "Linear")
	end

	dxDrawRectangle ( 0, borderY, sx, 100, tocolor(0,0,0,255),false) -- panel
end

function togglePanel()
	if animState == 0 then
		animState = 1 -- opening
	else
		animState = 0 -- closing
	end

	panelTick = getTickCount()
	removeEventHandler("onClientRender",getRootElement(),animatePanel)
	addEventHandler("onClientRender",getRootElement(),animatePanel)
end
addCommandHandler("tog", togglePanel)

 

I always recommend using default MTA variables like root instead of getRootElement() as it’s faster

  • Like 2
Link to comment
4 hours ago, SpecT said:

Hello,

I wrote some stuff I think it might help you out.


local sx, sy = guiGetScreenSize()
local progress = 0;
local borderY = 0;
local animState = 0
local panelTick = getTickCount()

function animatePanel()
	local tick = getTickCount() - panelTick
	local progress = tick/1000

	if progress >= 1 then -- anim finished
		--togglePanel() -- uncomment if you want it to go back down once the animation finishes
	end

	if animState == 1 then
		borderY = interpolateBetween ( sy/1, 0, 0, sy/1.15, 0, 0, progress, "Linear")
	else
		borderY = interpolateBetween ( sy/1.15, 0, 0, sy/1, 0, 0, progress, "Linear")
	end

	dxDrawRectangle ( 0, borderY, sx, 100, tocolor(0,0,0,255),false) -- panel
end

function togglePanel()
	if animState == 0 then
		animState = 1 -- opening
	else
		animState = 0 -- closing
	end

	panelTick = getTickCount()
	removeEventHandler("onClientRender",getRootElement(),animatePanel)
	addEventHandler("onClientRender",getRootElement(),animatePanel)
end
addCommandHandler("tog", togglePanel)

 

 

3 hours ago, Tekken said:

I always recommend using default MTA variables like root instead of getRootElement() as it’s faster

thank u guys v.much

Link to comment
17 hours ago, SpecT said:

Hello,

I wrote some stuff I think it might help you out.



local sx, sy = guiGetScreenSize()
local progress = 0;
local borderY = 0;
local animState = 0
local panelTick = getTickCount()

function animatePanel()
	local tick = getTickCount() - panelTick
	local progress = tick/1000

	if progress >= 1 then -- anim finished
		--togglePanel() -- uncomment if you want it to go back down once the animation finishes
	end

	if animState == 1 then
		borderY = interpolateBetween ( sy/1, 0, 0, sy/1.15, 0, 0, progress, "Linear")
	else
		borderY = interpolateBetween ( sy/1.15, 0, 0, sy/1, 0, 0, progress, "Linear")
	end

	dxDrawRectangle ( 0, borderY, sx, 100, tocolor(0,0,0,255),false) -- panel
end

function togglePanel()
	if animState == 0 then
		animState = 1 -- opening
	else
		animState = 0 -- closing
	end

	panelTick = getTickCount()
	removeEventHandler("onClientRender",getRootElement(),animatePanel)
	addEventHandler("onClientRender",getRootElement(),animatePanel)
end
addCommandHandler("tog", togglePanel)

 

hey mate I have tried this:

		if progress >= timeSpeedBorder then
			anim = 0
			borderTick = getTickCount()
			removeEventHandler("onClientRender", root,borderRender)
			addEventHandler("onClientRender", root,borderRender)
		end

but it keeps giving anim = 0 an end repeating how I should stop getTickCount without setting "setTimer" on removeEventHandler? because I think if i try remove line  addEventHandler animation will bug In the last move btw i gave addEventHandler out line function cuz after i will setting function with marker.

EDIT: well maybe i fixed. I gave the timing to removeEventHandler if the anime value 0

	if anim == 1 then
		borderY = interpolateBetween ( sy/1, 0, 0, sy/1.15, 0, 0, progress, "Linear")
	else
		borderY = interpolateBetween ( sy/1.15, 0, 0, sy/1, 0, 0, progress, "Linear")
		setTimer(function()
			removeEventHandler("onClientRender", root,borderRender)
		end,1000,1)
	end

If you have an idea or a second simple solution can u tell me

Edited by xFabel
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...