FlyingSpoon Posted November 21, 2017 Share Posted November 21, 2017 Haven't touched interpolate in a long while, just want to get up to date with it again. So I'm just experimenting and I'm trying to make it so that when I move into the DX Square, an overlay comes down, and when I leave the square it the overlay goes back up, into height = 0. showCursor(true); local start = getTickCount(); function dxDraw() local begin = ( ( getTickCount() - start ) / 500 ); dxDrawRectangle(567, 263, 229, 236, tocolor(0, 0, 0, 206), false); if isMouseInPosition(567, 263, 229, 236) then move = interpolateBetween(0, 0, 0, 236, 0, 0, begin, "Linear"); else move = interpolateBetween(0, 0, 236, 0, 0, 0, begin, "Linear"); end dxDrawRectangle(567, 263, 229, move, tocolor(189, 131, 131, 206), false); end addEventHandler("onClientRender", getRootElement(), dxDraw) function isMouseInPosition ( x, y, width, height ) if ( not isCursorShowing( ) ) then return false end local sx, sy = guiGetScreenSize ( ) local cx, cy = getCursorPosition ( ) local cx, cy = ( cx * sx ), ( cy * sy ) if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then return true else return false end end Right now, it only goes up as soon as the script starts, if I move into it later it just shows a random square appearing when I go inside the position, but doesn't animate. Link to comment
Moderators IIYAMA Posted November 21, 2017 Moderators Share Posted November 21, 2017 local begin = ( ( getTickCount() - start ) % 500 / 500 ); This will repeat the animation. It is not what you want.(so don't apply it in your end code) But it might tell you what you are doing wrong with the timing. What you need to do is using a boolean to set a status. This status indicates when you switch between hovering and not hovering. local hovering = false if not hovering then start = getTickCount() hovering = true end if hovering then start = getTickCount() hovering = false end The code will rest the timing, when you switch states. I leave the applying of the code to you. Link to comment
FlyingSpoon Posted November 21, 2017 Author Share Posted November 21, 2017 (edited) local hover = false; showCursor(true); function renderTicks() if not hover then start = getTickCount(); --outputDebugString("1: "..start) end if hover then start = getTickCount(); --outputDebugString("2: "..start) end end addEventHandler("onClientRender", root, renderTicks) function dxDraw() dxDrawRectangle(567, 263, 229, 236, tocolor(0, 0, 0, 206), false); if isMouseInPosition(567, 263, 229, 236) then hover = true; move = interpolateBetween(0, 0, 0, 236, 0, 0, ((getTickCount()-start)/500), "Linear"); else hover = false; move = interpolateBetween(0, 0, 236, 0, 0, 0, ((getTickCount()-start)/500), "Linear"); end dxDrawRectangle(567, 263, 229, move, tocolor(189, 131, 131, 206), false); end addEventHandler("onClientRender", getRootElement(), dxDraw) function isMouseInPosition ( x, y, width, height ) if ( not isCursorShowing( ) ) then return false end local sx, sy = guiGetScreenSize ( ) local cx, cy = getCursorPosition ( ) local cx, cy = ( cx * sx ), ( cy * sy ) if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then return true else return false end end Don't know what I've done, but it seems like it isn't working anymore xD. Edited November 21, 2017 by ℓιgнт Link to comment
Moderators IIYAMA Posted November 21, 2017 Moderators Share Posted November 21, 2017 (edited) local hover = false; showCursor(true); function dxDraw() dxDrawRectangle(567, 263, 229, 236, tocolor(0, 0, 0, 206), false); local move -- keep move local if isMouseInPosition(567, 263, 229, 236) then if not hover then start = getTickCount() iprint("state has been changed! (1)") hover = true end move = interpolateBetween(0, 0, 0, 236, 0, 0, ((getTickCount()-start)/500), "Linear"); else if hover then start = getTickCount() iprint("state has been changed! (2)") hover = false end move = interpolateBetween(0, 0, 236, 0, 0, 0, ((getTickCount()-start)/500), "Linear"); end dxDrawRectangle(567, 263, 229, move, tocolor(189, 131, 131, 206), false); end addEventHandler("onClientRender", getRootElement(), dxDraw) function isMouseInPosition ( x, y, width, height ) if ( not isCursorShowing( ) ) then return false end local sx, sy = guiGetScreenSize ( ) local cx, cy = getCursorPosition ( ) local cx, cy = ( cx * sx ), ( cy * sy ) if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then return true else return false end end That's because you only need to update the start tickCount when you change state. And not when you your state is true or false. Please check the debug console. Edited November 21, 2017 by IIYAMA Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now