Rose

Completar círculo en segundos

Recommended Posts

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
)

 

Share this post


Link to post

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
)

 

Share this post


Link to post
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.

Share this post


Link to post

Estoy haciendo pruebas parece que no se ajusta bien a los segundos. Ahora te envió el resultado.

Edited by Arsilex

Share this post


Link to post

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 by Arsilex
  • Like 3

Share this post


Link to post

Para no crear otro tema. ¿Se podría hacer pero con el nivel de vida, etc? Me vendría bastante bien. Gracias!

Share this post


Link to post

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 by Simple01
  • Like 2

Share this post


Link to post
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

 

Share this post


Link to post

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.