Skip to content

Instantly share code, notes, and snippets.

@Ushiosan23
Created December 27, 2018 00:11
Show Gist options
  • Select an option

  • Save Ushiosan23/527cc22ea1993730e4f67af0c20eb0a3 to your computer and use it in GitHub Desktop.

Select an option

Save Ushiosan23/527cc22ea1993730e4f67af0c20eb0a3 to your computer and use it in GitHub Desktop.
Game maker studio 2 button creation
_x = argument0; // position x
_y = argument1; // position y
_fnt = argument2; // font
_txt = argument3; // text
_padd = argument4; // padding xy
_b_c = argument5; // background color
_b_h = argument6; // background hover
_f_c = argument7; // text color
_call = argument8; // return value if click over there
draw_set_font(_fnt);
var _txt_w = string_width(_txt);
var _txt_h = string_height(_txt);
var _current_c = _b_c;
#region Detect Mouse
if ( point_in_rectangle(mouse_x, mouse_y, _x, _y, (_x + _txt_w) + (_padd * 2), (_y + _txt_h) + (_padd * 2)) )
_current_c = _b_h;
else
_current_c = _b_c;
if ( mouse_check_button(mb_left) && point_in_rectangle(mouse_x, mouse_y, _x, _y, (_x + _txt_w) + (_padd * 2), (_y + _txt_h) + (_padd * 2)) ) {
return _call;
}
#endregion
#region Draw button
draw_set_color(_current_c);
draw_rectangle(_x, _y, (_x + _txt_w) + (_padd * 2), (_y + _txt_h) + (_padd * 2), false);
#endregion
#region Draw text
draw_set_color(_f_c);
draw_text((_x + _padd), (_y + _padd), _txt);
#endregion
return -1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment