Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Game programming

interpolate multiple components  [SOLVED]

All about the StoneScript

interpolate multiple components

Postby arhshine » 18 Apr 2012, 13:17

Let`s say i have many buttons in the main menu.I need to interpolate the size of every button on mouse enter and on mouse leave.How to avoid creating two actions for every single button ? Imagine 30 buttons to select the level would require 60 actions just to "jump" a little when hovering the mouse over them.Help ?
arhshine
Junior Boarder
Junior Boarder
 
Posts: 32

Re: interpolate multiple components

Postby broozar » 18 Apr 2012, 14:29

you can create 2 generic actions, one for mouseover (zoom in a little) and one for mouseout (revert to original size). you can then assign each button those 2 actions in the component's "event" tab in the HUD editor:

Image
User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3529
Location: Berlin - Germany

Re: interpolate multiple components

Postby arhshine » 18 Apr 2012, 15:02

Yes but for every action you have to assign a command - in this case "interpolateSize" in which i have to assign a component.In order for every button to have that same behavior it has to have it`s own action (because of the assigned component).Am i missing something ?
arhshine
Junior Boarder
Junior Boarder
 
Posts: 32

Re: interpolate multiple components

Postby broozar » 18 Apr 2012, 15:30

true, my bad. in that case, it would probably be easier if you coded your action by hand. if you gave your components generic names with a number at the end, you could write a simple for-loop that would assign the action to every component with the correct component name.
User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3529
Location: Berlin - Germany

Re: interpolate multiple components

Postby arhshine » 19 Apr 2012, 07:50

Could you please create a short generic example ? I`m just starting to learn LUA and i feel this is a bit over my head at this point.Thank you.
arhshine
Junior Boarder
Junior Boarder
 
Posts: 32

Re: interpolate multiple components  [SOLVED]

Postby broozar » 19 Apr 2012, 09:50

sure.

for this sample to work, i assume your main menu buttons are named MainMenuButton_0 to MainMenuButton_30

Code: Select all
    --initialze HUD
    hud.newTemplateInstance ( application.getCurrentUser ( ), "YourHudName", "MMenu" )
    local hUser = application.getCurrentUser ( )
   
    for i=0, 30, 1 do
        --create scaleup action
        local hActionScaleUp = hud.newAction ( hUser, "ScaleUpMMButton_"..i )
        hud.beginActionCommand ( hActionScaleUp, hud.kCommandTypeInterpolateSize )
        hud.pushActionCommandArgument ( hActionScaleUp, hud.getComponent ( hUser, "MMenu.MainMenuButton_"..i ) )
        --set your own scaling values here
        hud.pushActionCommandArgument ( hActionScaleUp, 10 )
        hud.pushActionCommandArgument ( hActionScaleUp, 10 )
        hud.pushActionCommandArgument ( hActionScaleUp, hud.kInterpolatorTypeLinear )
        hud.pushActionCommandArgument ( hActionScaleUp, 50 )
        hud.endActionCommand ( hActionScaleUp )

        --create scaledown action
        local hActionScaleDown = hud.newAction ( hUser, "ScaleDownMMButton_"..i )
        hud.beginActionCommand ( hActionScaleDown, hud.kCommandTypeInterpolateSize )
        hud.pushActionCommandArgument ( hActionScaleDown, hud.getComponent ( hUser, "MMenu.MainMenuButton_"..i ) )
        --set your own scaling values here
        hud.pushActionCommandArgument ( hActionScaleDown, 6 )
        hud.pushActionCommandArgument ( hActionScaleDown, 6 )
        hud.pushActionCommandArgument ( hActionScaleDown, hud.kInterpolatorTypeLinear )
        hud.pushActionCommandArgument ( hActionScaleDown, 50 )
        hud.endActionCommand ( hActionScaleDown )

       
        --get button
        local hComponent = hud.getComponent ( hUser, "MMenu.MainMenuButton_"..i )
        if hComponent then
            hud.addComponentEventHandler ( hComponent, hud.kEventTypeMouseEnter, hud.getAction ( hUser, "ScaleUpMMButton_"..i  ) )
            hud.addComponentEventHandler ( hComponent, hud.kEventTypeMouseLeave, hud.getAction ( hUser, "ScaleDownMMButton_"..i  ) )
            log.message ( "new mouse handlers for button "..i.." added!" )
        end
    end
User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3529
Location: Berlin - Germany

Re: interpolate multiple components

Postby arhshine » 19 Apr 2012, 21:26

It works !! Thanks man, you are awesome !
arhshine
Junior Boarder
Junior Boarder
 
Posts: 32


Return to Game programming

cron