
Second, it also means that your GUI layer can have a different resolution than your camera. First, when you draw something on the GUI layer, it will not move or rotate when your camera moves or rotates. On the GUI layer, the top left of your screen is always 0, 0 and the bottom right of your screen is always the width and height of your GUI layer, regardless of how your camera moves, zooms, or rotates. The GUI layer solves this problem by using a different coordinate system. If you zoom or rotate the camera, the problem gets even worse! This means that the button will not move with the camera. For example, the built-in draw event draws an instance of an object using its x and y values as room coordinates. Many things in GameMaker work based on their position in the room. If you already know this information, you can skip to Making the Button Interactable. The GUI layerīefore we place the button in our room, we need to talk about the GUI layer, how it's different from GameMaker's normal draw event, and why you would want to use it. Our button is now ready to be placed in our room. So, it's important that we draw our button first using draw_self() and then draw the text over it. Note: GameMaker draws your game to the screen a bit like a painter adding paint to a canvas - when something is drawn, it's drawn over what has already been drawn. In GML Code, that looks like this: hovering = false In the Create event, we need two variables: hovering and clicked. We want the sprite's origin point to be centered for this demo, but you can experiment with different origin points in your project. This is because we don't actually want our sprite to animate. Our sprite has three frames, but an animation speed of 0. Read more about Nine Slicing in the manual. You can test out how the sprite will scale in the Preview panel on the right. For this sprite, I've found 36 pixels on each side to work nicely, and I've set the center to stretch.


Position your guides to create “nine slices”. Go to the Nine Slice section, and check the “Activate Nine Slice” box. To set up your sprite, open its Sprite Editor. Using GameMaker's built-in Nice Slice feature is one easy way to scale sprites for things like buttons, menus, and text boxes. You can use any sprite you want, but I'll be using spr_button_nine_slice. If you run the sample project, you should see the camera panning along the room. In the sample project, I've set up a room, a camera which follows an object, and included all the assets (sprites, sound, and font) I'll be using.
Fminer button code#
If you'd like to follow along with this tutorial, you can download the sample GML Code project or the sample GML Visual project.
Fminer button how to#
In this tutorial, you'll learn how to make a button that's easy to customise, scale, and modify to fit your needs.

Your game needs a great UI to match its great gameplay, and one of the most important UI elements is a button, which you can easily make in GameMaker.
