zocken212 Posted December 26, 2013 Share Posted December 26, 2013 Hey, I want to make an information window animated (fully dx) and so far it worked. But now the fail comes, when it should go smooth back out of the screen it just disappears in like lightspeed. Here is the code: local x,y = guiGetScreenSize() local startTick = getTickCount() local animState = "start" local length = 1500 local font = 1 local text = "" local handled = false function drawIt() if animState == "start" then local x1,y1,_ = interpolateBetween(512*x/1280,10-y/3,0,512*x/1280,10*y/960,0,progress(1000),"Linear") local x2,y2,_ = interpolateBetween(512*x/1280,10-y/3,0,512*x/1280,10*y/960,0,progress(1000),"Linear") local x3,y3,_ = interpolateBetween(767*x/1280,30-y/3,0,767*x/1280,30*y/960,0,progress(1000),"Linear") local x4,y4,_ = interpolateBetween(512*x/1280,30-y/3,0,512*x/1280,30*y/960,0,progress(1000),"Linear") local x5,y5,_ = interpolateBetween(512*x/1280,170-y/3,0,512*x/1280,170*y/960,0,progress(1000),"Linear") local x6,y6,_ = interpolateBetween(512*x/1280,30-y/3,0,512*x/1280,30*y/960,0,progress(1000),"Linear") local x7,y7,_ = interpolateBetween(763*x/1280,30-y/3,0,763*x/1280,30*y/960,0,progress(1000),"Linear") local x8,y8,_ = interpolateBetween(516*x/1280,30-y/3,0,516*x/1280,30*y/960,0,progress(1000),"Linear") local x8a,y8a,_ = interpolateBetween(763*x/1280,170-y/3,0,763*x/1280,170*y/960,0,progress(1000),"Linear") dxDrawRectangle(x1, y1, 255*x/1280, 20*y/960, tocolor(0, 120, 250, 255), true) dxDrawText("Information Window", x2, y2, x3, y3, tocolor(255, 255, 255, 255), 1.00*y/960, "default", "center", "center", false, false, true, false, false) dxDrawRectangle(x4, y4, 255*x/1280, 140*y/960, tocolor(0, 120, 250, 90), true) dxDrawRectangle(x5, y5, 255*x/1280, 4*y/960, tocolor(0, 120, 250, 255), true) dxDrawRectangle(x6, y6, 4*x/1280, 140*y/960, tocolor(0, 120, 250, 255), true) dxDrawRectangle(x7, y7, 4*x/1280, 140*y/960, tocolor(0, 120, 250, 255), true) dxDrawText("This is the window", x8,y8, x8a,y8a, tocolor(255, 255, 255, 255), 1.00*y/960, "default", "center", "center", false, true, true, false, false) if getTickCount() - startTick >= length then animState = "back" end elseif animState == "back" then local x1,y1,_ = interpolateBetween(512*x/1280,10*y/960,0,512,10-y/4,0,progress(1000),"Linear") local x2,y2,_ = interpolateBetween(512*x/1280,10*y/960,0,512,10-y/4,0,progress(1000),"Linear") local x3,y3,_ = interpolateBetween(767*x/1280,30*y/960,0,767,30-y/4,0,progress(1000),"Linear") local x4,y4,_ = interpolateBetween(512*x/1280,30*y/960,0,512,30-y/4,0,progress(1000),"Linear") local x5,y5,_ = interpolateBetween(512*x/1280,170*y/960,0,512,170-y/4,0,progress(1000),"Linear") local x6,y6,_ = interpolateBetween(512*x/1280,30*y/960,0,512,30-y/4,0,progress(1000),"Linear") local x7,y7,_ = interpolateBetween(763*x/1280,30*y/960,0,763,30-y/4,0,progress(1000),"Linear") local x8,y8,_ = interpolateBetween(516*x/1280,30*y/960,0,516,30-y/4,0,progress(1000),"Linear") local x8a,y8a,_ = interpolateBetween(763*x/1280,170*y/960,0,763,170-y/4,0,progress(1000),"Linear") dxDrawRectangle(x1, y1, 255*x/1280, 20, tocolor(0, 120, 250, 255), true) dxDrawText("Information Window", x2, y2, x3, y3, tocolor(255, 255, 255, 255), 1.00*y/960, "default", "center", "center", false, false, true, false, false) dxDrawRectangle(x4, y4, 255*x/1280, 140*y/960, tocolor(0, 120, 250, 90), true) dxDrawRectangle(x5, y5, 255*x/1280, 4*y/960, tocolor(0, 120, 250, 255), true) dxDrawRectangle(x6, y6, 4*x/1280, 140*y/960, tocolor(0, 120, 250, 255), true) dxDrawRectangle(x7, y7, 4*x/1280, 140*y/960, tocolor(0, 120, 250, 255), true) dxDrawText("This is the window", x8,y8, x8a,y8a, tocolor(255, 255, 255, 255), 1.00*y/960, "default", "center", "center", false, true, true, false, false) end end function progress(tick) local now = getTickCount() local elapsedTime = now-startTick local duration = startTick+tick-startTick local progress = elapsedTime/duration return progress end function draw(teXt,foNt) if not foNt then font = 1 end assert(teXt,"Error at @draw") foNt = font teXt = text --local lengthHere = string.len(text) --local length = 150*lengthHere/2 if handled ~= true then addEventHandler("onClientRender",getRootElement(),drawIt) handled = true end end draw("hello thereaaaaaaaaaa") Link to comment
Moderators IIYAMA Posted December 26, 2013 Moderators Share Posted December 26, 2013 maybe you should check your progress. This makes no sense. It is the exact same value tick. local duration = startTick+tick-startTick This will give you the future time, so you can compare it with the time now. local futureTime = startTick+tick For progress backwards: local progress = 1-(startTick/futureTime) Next to that, you have to reset the:(because you will be re-comparing the time now with the future time) startTick = getTickCount() Link to comment
zocken212 Posted December 26, 2013 Author Share Posted December 26, 2013 startTick = getTickCount() I did this where it changes to "back" and it worked fine as it should be. Thank you! Link to comment
Moderators IIYAMA Posted December 26, 2013 Moderators Share Posted December 26, 2013 np. 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