Rose Posted April 29, 2017 Share Posted April 29, 2017 Quisiera saber cómo calcular para que un círculo (dxDrawCircle) se complete en ciertos segundos. El ejemplo de la wiki es este: local screenWidth, screenHeight = guiGetScreenSize( ) local stopAngle = 0 addEventHandler( "onClientRender", root, function( ) if ( stopAngle < 360 ) then stopAngle = stopAngle + 5 else stopAngle = 0 end dxDrawCircle( screenWidth / 2, screenHeight / 2, nil, nil, nil, nil, stopAngle ) end ) Link to comment
Plate Posted April 29, 2017 Share Posted April 29, 2017 No estoy muy seguro pero intenta asi: local screenWidth, screenHeight = guiGetScreenSize( ) local stopAngle = 0 setTimer(function() if ( stopAngle < 360 ) then stopAngle = stopAngle + 5 else stopAngle = 0 end end, 3600, 0) addEventHandler( "onClientRender", root, function( ) dxDrawCircle( screenWidth / 2, screenHeight / 2, nil, nil, nil, nil, stopAngle ) end ) Link to comment
Rose Posted April 29, 2017 Author Share Posted April 29, 2017 Just now, Plate said: No estoy muy seguro pero intenta asi: local screenWidth, screenHeight = guiGetScreenSize( ) local stopAngle = 0 setTimer(function() if ( stopAngle < 360 ) then stopAngle = stopAngle + 5 else stopAngle = 0 end end, 3600, 0) addEventHandler( "onClientRender", root, function( ) dxDrawCircle( screenWidth / 2, screenHeight / 2, nil, nil, nil, nil, stopAngle ) end ) Eso no va a funcionar, la idea es que el progreso(o animación) del círculo se vea "fluido" y no que le sume 5 cada 3.6 segundos. De todas formas, gracias. Link to comment
Arsilex Posted April 29, 2017 Share Posted April 29, 2017 (edited) Estoy haciendo pruebas parece que no se ajusta bien a los segundos. Ahora te envió el resultado. Edited April 29, 2017 by Arsilex Link to comment
Arsilex Posted April 29, 2017 Share Posted April 29, 2017 (edited) He estado probando de diferentes formas pero por ahora la mas simple que veo es usando interpolateBetween. local screenWidth, screenHeight = guiGetScreenSize( ) local stopAngle = 0 local time = 5000; local speed = ((getFPSLimit() / 60) * 100) / (time / 60); local tick = getTickCount(); addEventHandler( "onClientRender", root, function( ) local now = getTickCount() local endTime = tick + time local elapsedTime = now - tick local duration = endTime - tick local progress = elapsedTime / duration local angle = interpolateBetween ( 0, 0, 0, 360, 0, 0, progress, "Linear") dxDrawCircle( screenWidth / 2, screenHeight / 2, nil, nil, nil, nil, angle ) end ) Edited April 29, 2017 by Arsilex 3 Link to comment
aka Blue Posted April 29, 2017 Share Posted April 29, 2017 Para no crear otro tema. ¿Se podría hacer pero con el nivel de vida, etc? Me vendría bastante bien. Gracias! Link to comment
Simple0x47 Posted April 30, 2017 Share Posted April 30, 2017 (edited) Nivel de vida: addEventHandler( "onClientRender", root, function( ) local progress = getElementHealth( localPlayer ) / 100 local angle = interpolateBetween ( 0, 0, 0, 360, 0, 0, progress, "Linear") dxDrawCircle( screenWidth / 2, screenHeight / 2, nil, nil, nil, nil, angle ) end ) Edited April 30, 2017 by Simple01 2 Link to comment
Tomas Posted April 30, 2017 Share Posted April 30, 2017 21 hours ago, Simple01 said: Nivel de vida: addEventHandler( "onClientRender", root, function( ) local progress = getElementHealth( localPlayer ) / 100 local angle = interpolateBetween ( 0, 0, 0, 360, 0, 0, progress, "Linear") dxDrawCircle( screenWidth / 2, screenHeight / 2, nil, nil, nil, nil, angle ) end) Eso solo funcionará correctamente si su vida máxima es 100. addEventHandler( "onClientRender", root, function( ) local progress = getElementHealth( localPlayer ) / getPedMaxHealth(localPlayer) local angle = interpolateBetween ( 0, 0, 0, 360, 0, 0, progress, "Linear") dxDrawCircle( screenWidth / 2, screenHeight / 2, nil, nil, nil, nil, angle ) end ) function getPedMaxHealth(ped) assert(isElement(ped) and (getElementType(ped) == "ped" or getElementType(ped) == "player"), "Bad argument @ 'getPedMaxHealth' [Expected ped/player at argument 1, got " .. tostring(ped) .. "]") local stat = getPedStat(ped, 24) local maxhealth = 100 + (stat - 569) / 4.31 return math.max(1, maxhealth) end Link to comment
aka Blue Posted April 30, 2017 Share Posted April 30, 2017 @Tomas Podría venirme bien también, gracias Tomas! 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