Here is how to make buttons with code. Basically they can look in anyway, but the classical way is a rectangle and thus we make a rectangle (using variables x,y,x2,y2):
draw_rectangle(x,y,x2,y2,false) ;
draw_text(x+3,y+sprite_height/2-string_height(“button”)/2,”button”);
This also draws the text upon the button. Now we need to determine whether the mouse is over the button or not and whether it is pressed or not. This is how we do that:
if (mouse_x>x) && (mouse_x<x2) {
if (mouse_y>y) && (mouse_y<y2) {
//Mouse is over
if (mouse_check_button(mb_left)) {
//Left mouse button is pressed (on the button)
}
}
}
Notice that you may also add effects to your script, such as mouse-over effect, mouse button pressed effect etc. suggestively this can be done by changing the background colour of the button.
.
Users logged in:
Comments
Loading comments...