Jump to content

HUD Popdown/Popup buttons


Recommended Posts

i got asked about how to have HUD buttons pop down when they are pressed and pop back up when released to help with visual feedback

a way to do this is with touch_start and touch_end. (it also works on non-HUD objects) Example:
 

// script goes in the root prim which acts as a backboard for linked prim buttons
// as wrote the buttons are linked / surfaced on Face 4 of the root prim
// Face 4 being the default orientation of a (root) HUD prim

integer buttonLink;
vector buttonPos;

default
{
    touch_start(integer total_number)
    {
        // check that there is no button currently being actioned
        if (buttonLink == 0)
        {   // we are good
            integer link = llDetectedLinkNumber(0);
            string name = llGetLinkName(link);
            if (llGetSubString(name, 0, 5) == "button") // are we a button prim ?
            {   // button prim names begin with button. Like
                // button1, button2, button3, etc
                // buttonRed, buttonGreen, buttonBlue, etc
            
                // save link number and local pos
                buttonLink = link;
                buttonPos = llList2Vector(llGetLinkPrimitiveParams(link, [PRIM_POS_LOCAL]), 0);
            
                // popdown button by (m) margin
                float m = 0.005;           
                llSetLinkPrimitiveParamsFast(link,
                    [PRIM_POS_LOCAL, <buttonPos.x - m, buttonPos.y - m, buttonPos.z - m>]);
            }
        }
    }
    
    touch_end(integer total_number)
    {
        integer link = llDetectedLinkNumber(0);
        if (link == buttonLink)
        {   // we are good, this is the same button as in touch_start         

            // action the button
            // whichever way works for you
            string name = llGetLinkName(link);
            if (name == "button1")
            {
                // do button1
            }
            else if (name == "button2")
            {
                // do button2     
            }
            // else if other buttons


            // after we have completed the button action
            // popup button and null buttonLink
            llSetLinkPrimitiveParamsFast(buttonLink,
                [PRIM_POS_LOCAL, buttonPos]);
            buttonLink = 0;
        }
    }
}

 

 

 

Link to post
Share on other sites

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
×
×
  • Create New...