Dealman Posted January 6, 2014 Share Posted January 6, 2014 As I'm working on my new shooter, I decided to add a DX Progress Bar for the reloading, and use interpolateBetween to animate it. However I have encountered something rather odd. Either I've missed something blatantly obvious, or I've found a bug with interpolateBetween... Relevant Code; local screenX, screenY = guiGetScreenSize() local barWidth = screenX*(485/1360) local isAnimatingStage1 = false local isAnimatingStage2 = false function example() dxDrawRectangle(screenX*(438/1360), screenY*(714/768), barWidth, screenY*(44/768), tocolor(187, 0, 0, 255), true) end function handleAnimationStage1() if(isAnimatingStage1 == false) then isAnimatingStage1 = true coolBarStart = getTickCount() addEventHandler("onClientRender", getRootElement(), animateCooldownStage1) setTimer(function() isAnimatingStage1 = false removeEventHandler("onClientRender", getRootElement(), animateCooldownStage1) handleAnimationStage2() end, 3000, 1) end end function handleAnimationStage2() if(isAnimatingStage2 == false) then isAnimatingStage2 = true coolBarStart2 = getTickCount() addEventHandler("onClientRender", getRootElement(), animateCooldownStage2) setTimer(function() isAnimatingStage2 = false removeEventHandler("onClientRender", getRootElement(), animateCooldownStage2) end, 3000, 1) end end function animateCooldownStage1() if(isAnimatingStage1 == true) then local coolBarNow = getTickCount() local coolBarEndTime = coolBarNow + 3000 local coolBarElapsedTime = coolBarNow - coolBarStart local coolBarDuration = coolBarEndTime - coolBarStart local coolBarProgress = coolBarElapsedTime / coolBarDuration local coolBarX1, coolBarY1 = screenX*(485/1360), 0 local coolBarX2, coolBarY2 = 0, 0 local coolBarNewX, coolBarNewY = interpolateBetween(coolBarX1, coolBarY1, 0, coolBarX2, coolBarY2, 0, coolBarProgress, "Linear") barWidth, coolBarY1 = coolBarNewX, coolBarNewY end end function animateCooldownStage2() if(isAnimatingStage2 == true) then local coolBar2Now = getTickCount() local coolBar2EndTime = coolBar2Now + 3000 local coolBar2ElapsedTime = coolBar2Now - coolBarStart2 local coolBar2Duration = coolBar2EndTime - coolBarStart2 local coolBar2Progress = coolBar2ElapsedTime / coolBar2Duration local coolBar2X1, coolBar2Y1 = 0, 0 local coolBar2X2, coolBar2Y2 = screenX*(970/1360), 0 --970 local coolBar2NewX, coolBar2NewY = interpolateBetween(coolBar2X1, coolBar2Y1, 0, coolBar2X2, coolBar2Y2, 0, coolBar2Progress, "Linear") barWidth, coolBar2Y1 = coolBar2NewX, coolBar2NewY end end Problem; It's supposed to go from right, to left - and then when it reaches the far left(0) it should go back to the right again. However, the first stage is behaving very weirdly. If I use the variable, barWidth it goes from full to empty, way too fast. However, if I use the actual calculation(screenX*(485/1360)) - instead of the variable, it moves much slower - but only reaches 50% and then it starts the 2nd stage. What's weird is that barWidth should be the exact same as the actual calculation, as it's defined at the top of the script. And not changed anywhere else. I've tried various durations and things but I can't pin-point what's causing this. The 2nd stage seems to be working as intended. Can anyone spot what I have missed? Or is this some sort of bug with interpolateBetween...? Link to comment
.:HyPeX:. Posted January 6, 2014 Share Posted January 6, 2014 I'm just reading over, but, if you make a value to go up (0 -> 1) for interpolate, how ur expecting to do the way arround (1 -> 0) with the same code? Link to comment
Dealman Posted January 6, 2014 Author Share Posted January 6, 2014 Thank you, but a friend helped me spot what I did wrong. Had coolBarNow instead of coolBarStart. x) 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