Jump to content

Completar círculo en segundos


Rose

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
)

 

Link to comment

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

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

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

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