Hello, Can anyone help me to make this code working?
My animation "stacks" or just works together. I want to make one animation that makes button larger when button is hovered and second animation that decreases button size after "unhovering" or just placing mouse outside button land.
local animacja = Derma_Anim( "EaseInQuad", ButtonKrysztalCzerwone, function( pnl, anim, delta, data )
pnl:SetPos( inQuad( delta, 720, -80 ), 0 )
pnl:SetSize( inQuad( delta, 30, 80 ), 20 )
-- Change the X coordinate from 200 to 200+600
end )
local animacja_zakonczenie = Derma_Anim( "EaseInQuad", ButtonKrysztalCzerwone, function( pnl, anim, delta, data )
pnl:SetPos( inQuad( delta, 720, 80 ), 0 )
pnl:SetSize( inQuad( delta, 30, -80 ), 20 )
-- Change the X coordinate from 200 to 200+600
end )
ButtonKrysztalCzerwone.Paint = function( s,w,h )
draw.RoundedBox(2,0,0,w,h,czerwony_zajebisty)
draw.DrawText( "X", "DonovanNormal", 15, -2 , Color(236, 240, 241), TEXT_ALIGN_CENTER )
if ButtonKrysztalCzerwone:IsHovered() then
animacja:Start( 3 )
animacja_zakonczenie:Stop()
elseif not (animacja_zakonczenie:Active()) and ButtonKrysztalCzerwone:IsHovered() then
animacja:Stop()
animacja_zakonczenie:Start(3)
end
end
ButtonKrysztalCzerwone.Think = function( self )
if animacja:Active() then
animacja:Run()
elseif animacja_zakonczenie:Active() then
animacja_zakonczenie:Run()
end
end
Or hastebin Thanks for any reply!
Panel/IsHovered
try example: DTextEntry/OnEnter
https://pastebin.com/5v53u6VY
This is a function I created for another project of mine to have a button that would “fill” up from the left, right, top, bottom, or center depending on what the user had a setting set to, whenever they hover over the button (and “empty” when you stop). I removed the unnecessary things for the sake of simplicity, so this only contains the code to fill from the center. This function is meant to be called inside a paint function of an element.
This more or less does what you want. Just remove the border, and mess around with the start and end values of the lerps. Personally I would recommend changing the size of a painted rectangle over setting the actual size of the button, but that’s just personal preference. (I suppose you could even set the size before and after the actual animation for the sake of being neat) If you still want to use your method, I believe the math involved is still more or less the same.
You simply need to move the rectangle’s coordinates proportionally to the amount it is decreasing/increasingly to keep it centered.
It sounds like Lechu already has the animations figured out for themselves. They're just having trouble doing their animation only when they hover over the button which is why I suggested IsHovered()
The issue is probably because you're starting the animation every frame in the Paint method. Add an active check to the animation there to make sure you aren't constantly just restarting it
Looks like you're trying to something I did today, typing this on my phone so I can't send you a live example, but from the top of my head you want to do this:
local Hovering = false
ButtonKryczytalCzerwone.OnCursorEntered = function()
Hovering = true
End
ButtonKrycztal.OnCursorExited = function()
Hovering = false
End
Then check with an if statement in your Paint or Update methods:
if( Hovering ) then
end
No idea how I have to do this. Tried :
local animacja = Derma_Anim( "EaseInQuad", ButtonKrysztalCzerwone, function( pnl, anim, delta, data )
if not animacja:Active() then
pnl:SetPos( inQuad( delta, 720, -80 ), 0 )
pnl:SetSize( inQuad( delta, 30, 80 ), 20 )
end
end )
And similar in second animation.
Notice I said in the Paint method. Specifically this snippet:
if ButtonKrysztalCzerwone:IsHovered() then
animacja:Start( 3 )
animacja_zakonczenie:Stop()
elseif not (animacja_zakonczenie:Active()) and ButtonKrysztalCzerwone:IsHovered() then
animacja:Stop()
animacja_zakonczenie:Start(3)
end
In the first portion, you'll be restarting `animacja` every single frame if the button is hovered. You need to make sure the animation isn't already running then.
The `else if` portion will never run as it is because it shares a condition with the original if-statement, in which case that code path is impossible to reach.
xD I was again making something harder when I had:
ButtonKrysztalCzerwone.OnCursorEntered = function ( )
surface.PlaySound("buttons/lightswitch2.wav")
ButtonKrysztalCzerwone:SizeTo(100, 20, 1, 0, -1)
ButtonKrysztalCzerwone:MoveTo(650,0,1,0,-1)
end
Nice, nice...
Thanks for every reply, have nice day.
Sorry, you need to Log In to post a reply to this thread.