Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit)

Thank you so much!

While it doesn't explicitly support gamepad, there are many ways you can do it:

--- CREATE EVENT ---

index = 0; // your current selected index 
c = auto_container_v(80, 8); // width/spacing 
radiogroup = auto_radiogroup();  
/// @desc Returns a struct of a new button element, index, and select function 
new_button = function(_text, _index, _select_func) {     
    // Create the button     
    var _btn = auto_button_checkable_center(80, 32, _text, FONTS.px_6x6, s_tt_btn_purple, _index == 0, radiogroup);
    // Set the hovering function, passing in this object and the index         
    _btn.set_hovering_func(function(_obj, _index) {             
    // Set this button to be "checked", and uncheck all other buttons in the radio group             
        set_checked(true, true);             
        _obj.index = _index; // set the obj's index correctly         
    }, [self, _index]);         
    // Assign the click function         
    _btn.set_click_func(function(_select_func) {             
        _select_func();         
    }, [_select_func]);     
    // Returning a struct of the button, index and select function     
    return {         
        button: _btn,         
        index: _index,         
        select: _select_func     
    } 
}  
// Here is our struct data where we create our buttons 
button_data = [     
    new_button("New Game", 0, function() { show_debug_message("START NEW GAME"); }),         
    new_button("Load Game", 1, function() { show_debug_message("LOAD GAME"); }),         
    new_button("Quit Game", 2, function() { game_end(); }) 
]  
// And don't forget to add the button to the main container 
for (var i = 0; i < array_length(button_data); i++) { c.add(button_data[i].button); }

--- STEP EVENT ---

c.step(5, 5);  
// EZ check if you press up or down (uses AutoInput; replace with gamepad_button_check etc.) 
var _ydir = control_is_pressed("menu_down", 0) - control_is_pressed("menu_up", 0);  
// If a button was pressed... 
if _ydir != 0 {     
    // Set the index     
    index = (index + array_length(button_data) + _ydir) mod array_length(button_data);     
    // And make sure to set checked to true     
    button_data[index].button.set_checked(true, true); 
}  
// If select, run function 
if control_is_pressed("menu_select", 0) { button_data[index].select(); }

And then run c.draw() in your draw event!  Now it handles BOTH mouse and gamepad.


Hopefully that helps - it's not quite as cut and dry, but because some people have their own input systems (eg. AutoTools' AutoInput!), I didn't want to put too much of that in AutoUi.

I'll probably add this to an example in the package, though - thanks for the suggestion!