• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Can't change shape sizes? Strange behaviour

Mr Giff

Member
So I have a problem that just started occurring when I was developing a button for a new UI system I'm working on.

The button is supposed to be 156px by 45px and have text in the middle describing the state; pretty simple. But instead it looks like this:
Screen Shot 2019-08-16 at 8.02.56 PM.png

Strange....

So here's my code stack:

Create Event:

Code:
// Visual Variables

c_normal = make_colour_rgb(140, 173, 250); //Light Blue
c_hover = make_colour_rgb(113, 231, 221); //Light Green
c_press = make_colour_rgb(100, 204, 195); //Dark Green
colour = c_normal;
alpha = 1;
c_text = c_white;

// Size

width = 156;
height = 45;

// State

state = 0;
left_click = false;

// Text String

text[0] = "Normal";
text[1] = "Hover";
text[2] = "Pressed";

// Initialize Surface
var dispwidth = display_get_width(), dispheight = display_get_height();
surf = surface_create(dispwidth,dispheight);
Step Event:

Code:
/
// Responsive

x = responsive(0,5.5);
y = responsive(1,5.5);


// Colour & State

if point_in_rectangle(mouse_x,mouse_y,x,y,width,height) {
   
       switch left_click {
   
       case false:
           colour = c_hover;
           state = 1;
           break;
       
       
       case true:
           colour = c_press;
           state = 2;
           break;
   
   }
} else {
   state = 0;
}
Draw GUI Event:

Code:
// Set the Surface Target

display_set_gui_maximize();
surface_set_target(surf);

//Draw the Button

draw_set_colour(colour);
draw_set_alpha(alpha);
draw_roundrect_ext(x, y, width, height, 11, 11, 0);

//Draw the Text

var htext = (width / 2), vtext = (height / 2);
draw_set_colour(c_text);
draw_set_halign(fa_center);
draw_text(htext, vtext, text[state]);

// Reset the surface and Draw

surface_reset_target();
draw_surface(surf, 0, 0);
And then the Global Left Press and Left Release events change the variable 'left_click' to True or False respectively.

I have one script:

Code:
/// @description  Returns desired position based on display width divisions
/// @param  Mode:width(0)-height(1)
/// @param  Point(1-12)

//Initialize variables
var mode = argument[0], point = argument[1];
var width = display_get_gui_width(), height = display_get_gui_height();
var pos;

switch mode {
   case 0: pos = (width / 12) * point; break; // Width
   case 1: pos = (height / 12) * point; break; // Height
}

return pos;
I was originally drawing the surface just to the size of the button but I wasn't seeing anything.

I figured it must've been my code somewhere so decided to troubleshoot with a basic object that draws a simple rectangle on the application surface in the Draw event using the following:

Code:
draw_set_colour(c_red);
draw_rectangle(x,y,156,45,0);
Same issue, the size and the position are WAY off. Surface or no surface. I also tried fiddling with the Mac OS Graphics and Scale settings but nothing sparked a change.

I tried creating a blank GM Project but the same problem occurred. I tried quitting GMS2 and opening it again but nope. Then I restarted my computer entirely and still nothing.

I'm at a loss as to why this might be happening as I've drawn rectangles thousands of times lol.

Any help would be greatly appreciated!
 
Last edited:

Mr Giff

Member
Just solved my own problem. It was my code..... But just so someone doesn't make the same (really very simple) mistake:

I was not drawing anything properly with my width and height variables not being drawn relative to the instance's X and Y points. Essentially adding x+width or y+width solved my problems. But because of the strange visual nature of this I overlooked SO much. Cheers for anyone who was about to help me. Although I will still gladly take feedback on the code above, perhaps a way of simplifying. Cheers!
 
Top