Jump to content

problem with alpha


Recommended Posts

Hey dear guys, Im having a problem building a Lib, well, my idea is to create a rectangle which when the mouse is over it, the alpha increase only to it.

Well, its a system to create animate buttons

local sX,sY = guiGetScreenSize() 
  
function animB(posX,posY,sizeX,sizeY,r,g,b) 
    if isCursorHover(posX,posY,sizeX,sizeY) then 
        aFinal = math.min(aFinal + 20, 255) 
        dxDrawRectangle(posX,posY,sizeX,sizeY,tocolor(r,g,b,aFinal)) 
    else 
        aFinal = math.min(aFinal - 20, 0) 
        dxDrawRectangle(posX,posY,sizeX,sizeY,tocolor(r,g,b,aFinal)) 
    end 
end 
  
function isCursorHover(posX,posY,sizeX,sizeY) 
    local x,y = 0,0 
    if isCursorShowing() then x,y = getCursorPosition() x,y = sX*x,sY*y else return false end 
    if x>=posX and x<=posX+sizeX and y>=posY and y<=posY+sizeY then 
        return true 
    else 
        return false 
    end 
end 
-- ## LETS TEST IT 
function testingIt() 
    animB(500,500,270,40,255,255,255) 
end 
addEventHandler("onClientRender",getRootElement(),testingIt) 

Well, the error that I get on Debugscript 3 is:

attemt to perfom arithmetic on global 'aFinal' (a nil value)

I hope u can tell me how can I define it :)

Regards.

Link to comment

then you can declare the alpha as 0 the first time.

function animB(posX,posY,sizeX,sizeY,r,g,b) 
    if (aFinal == nil) then 
        aFinal = 0 
    end 
    if isCursorHover(posX,posY,sizeX,sizeY) then 
        aFinal = math.min(aFinal + 20, 255) 
        dxDrawRectangle(posX,posY,sizeX,sizeY,tocolor(r,g,b,aFinal)) 
    else 
        aFinal = math.min(aFinal - 20, 0) 
        dxDrawRectangle(posX,posY,sizeX,sizeY,tocolor(r,g,b,aFinal)) 
    end 
end 

Link to comment
  • Moderators

There is also math.max (another problem)

  
    else 
        aFinal = math.min(aFinal - 20, 0) 
        dxDrawRectangle(posX,posY,sizeX,sizeY,tocolor(r,g,b,aFinal)) 
    end 
    else 
        aFinal = math.max(aFinal - 20, 0) 
        dxDrawRectangle(posX,posY,sizeX,sizeY,tocolor(r,g,b,aFinal)) 
    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...