Jump to content

Smooth moving


Piorun

Recommended Posts

Hi guys,

Today i decided to write code who is moving softly gui elements, but on low FPS it moves slower than on high FPS. Im using standard incrementation:

local i = 0 
function exmpl() 
i = i + 0.001 
interpolateBeetwen(x,y,z,x1,y1,z1,i,"Linear") 
... 
end 
addEventHandler("onClientRender", root, exmpl) 

What should i use or/and what is wrong with my code?

Link to comment
  • Moderators

Then you better can use TIME instead of counting pixels.

https://wiki.multitheftauto.com/wiki/GetTickCount

local startTime = 0 
local endTime = 0 
  
  
  
function renderFunction () 
    local factor = startTime/endTime 
    if factor < 1 then 
        dxDrawText ( factor, 200, 2) 
    else 
        outputChatBox("We stop rendering the factor!") 
        removeEventHandler("onClientRender", root, renderFunction) 
    end 
end 
  
outputChatBox("We start rendering the factor over 5 seconds!!!") 
setTimer (function () 
    local timeNow = getTickCount () 
    startTime = timeNow 
    endTime = timeNow+10000 -- + 10 seconds 
    addEventHandler("onClientRender", root, renderFunction) 
end,5000,1) 

A factor can be used for increasing or de-increase other values.

0.8 = 80%

0.2 = 20%

local pixels = 0.2 * 100 
outputChatBox(pixels) -- 20 pixels.... 
  

Inverse the factor. So you can de-increase the value.

local 0.8 = 1 - 0.2 

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...