【GameMaker】 program a button

Information about object: obj_dynamic_button
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

message="Hello";
bg_colour=c_white;

//code below is updated in step event, here to prevent error
width=string_width(message)+50;
height=string_height(message)+50;
xpos=x-(width/2);
xpos2=x+(width/2);
ypos=y-(height/2);
ypos2=y+(height/2);
Step Event:
execute code:

if point_in_rectangle(mouse_x,mouse_y,xpos,ypos,xpos2,ypos2) && mouse_check_button(mb_left)
{
bg_colour=c_red;
}
else if point_in_rectangle(mouse_x,mouse_y,xpos,ypos,xpos2,ypos2)
{
bg_colour=c_blue;
}
else bg_colour=c_white;

width=string_width(message)+50;
height=string_height(message)+50;
xpos=x-(width/2);
xpos2=x+(width/2);
ypos=y-(height/2);
ypos2=y+(height/2);
Draw Event:
execute code:

draw_set_colour(bg_colour);
draw_rectangle(xpos,ypos,xpos2,ypos2,false);
draw_set_font(font_text);
draw_set_halign(fa_center);
draw_set_valign(fa_middle);
draw_set_colour(c_black);
draw_text(x,y,message);

No comments:

Top 3 UX Design Articles of 2024 to Remember

Based on most subscriptions ͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­...

Contact Form

Name

Email *

Message *