C
Cooltrain
Guest
Working on some GUI Buttons which I've built into 3 scripts, one for the create, one for the step, and one for the drawGUI, the buttons themselves work fine. Its just the problem of running them doesn't lend it self into creating multiple buttons. I'm thinking I need some kinda of buttonID/array to track which button is which but I'm not sure how to approach it. The aim is to be able to call these scripts from any object and create buttons easily.
scr_int_button
scr_step_button
scr_drawGUI_button
So if I were to list a bunch of new button script calls such as
Then it would create three working buttons. I might also need to list the scripts for the step and GUI the same number of times in the calling object ? I guess I need a way of indexing all the buttons that are created and running the code for each, or something ?
Any thoughts ?
scr_int_button
Code:
///scr_int_button(xGUI,yGUI,sprite)
button_pressed = false;
hover = false;
sprite_index=argument[2];
image_index=0;
image_speed=0;
button_x = argument[0];
button_y = argument[1];
button_width = sprite_get_width(argument[2])
button_height = sprite_get_height(argument[2])
//positions for mouse bounding box
button_left = button_x - button_width / 2;
button_right = button_left + button_width - 1;
button_top = button_y - button_height / 2;
button_bottom = button_top + button_height - 1;
Code:
///scr_step_button()
hover = point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), button_left, button_top, button_right, button_bottom);
if (!hover){
button_pressed = false;
}else
{
if (mouse_check_button_pressed(mb_left))
{
button_pressed = true;
}
else if (mouse_check_button_released(mb_left) && button_pressed)
{
// click action
scrToCall = asset_get_index(argument[0])
script_execute(scrToCall)
}
}
Code:
///scr_drawGUI_button()
if (button_pressed==true){
draw_sprite(sprite_index, 1, button_x, button_y);
}else if hover == true{
draw_sprite(sprite_index, 2, button_x, button_y);
}else{
draw_sprite(sprite_index, 1, button_x, button_y);
}
Code:
scr_int_button(200,140,spr_sprite)
scr_int_button(300,140,spr_sprite)
scr_int_button(400,140,spr_sprite)
scr_int_button(500,140,spr_sprite)
Any thoughts ?