Keine Ergebnisse gefunden
After using GMS1.4 extensively while developing INK and HackyZack, I learned to work around its quirks. Around three months passed between the release of GMS2 and the first time I could pick it up due to work, but I had heard fantastic things about the new version. These were not exaggerations, as GMS2 is a vast improvement over 1.4, adding tons of new features, streamlining most processes that used to be unintuitive, and improving the overall workflow for the engine.
Now it’s been about a year since the release and even though there are quite a few articles out there detailing the new features and some tips for more hidden functionality, I thought it would be a good idea to make a list of interesting tips and tricks to consider while using GMS2. I am really excited about most of the new features coming up in the next few months, listed in the road map, so I figured I’d talk about those too and the cool possibilities those features will unlock.
In this section, I will list a few features you should try at least once, since they can improve your workflow significantly. It may take a while to get into the habit of using these, but once you do, save a lot of time that would have been wasted navigating the interface with a mouse.
1. Navigate resources with Ctrl + T: Taking a hint from a famous Visual Studio plugin, GMS2 added the option to quickly search for any asset, be it a script, object, sprite, you name it, by simply using the Ctrl + T hotkey. This will display a window with a search bar that looks into every resource in your project, making it extremely fast to find what you are looking for and improve your overall workflow.
2. Workspaces: Gone are the days where you had tens of separate windows opened cluttering your screen. With the introduction of workspaces, you can now organize what you are working on by type of resource, or by a specific feature. Sure, you can work using only one workspace, but that is wasting the potential of this feature. Say you are implementing a feature that involves the player and a couple of enemies. You can have a workspace with all the resources you think are necessary in there to find them all easier. Thing is, you realize you need to work on something else now, but haven’t finished the other feature. No problem, just create a new workspace and open resources there. This will reduce the overall number of resources you have visible without requiring you to close everything else first, which allows you to go back to working on that previous feature whenever you want, as you already have the necessary objects and scripts opened there. You can even name each workspace by slowly double-clicking on the tab name or selecting the tab and pressing F2, further improving your organization. These workspaces will even reopen exactly as you left them if you close GameMaker and return to it later.
3. Switch workspaces with Ctrl + Tab: Now that you have your workspaces neatly set up, how about a nicer way to navigate through them? With Ctrl + Tab, you can quickly preview and switch between workspaces, and even access specific windows/tabs opened within those workspaces. Extremely useful to find what you need without relying on your mouse.
4. Resource views: As a project gets larger, the amount of resources and folders you need to keep track of can become hard to handle, especially when trying to find specific resources related to one another. You could use the Ctrl + T trick I mentioned above, but sometimes you can’t remember the specific name of the resource, or you want to keep all similar resources, or ones associated with a specific gameobject, together. This is where resource views come into play, letting you create a custom tree of resources in a separate view. To create a new view click on the “Views” button at the top of the resources tab and select “Add." This will create a new view you can rename to your liking. Next, right-click anywhere inside of this new empty section and add items by choosing “Add from Default View." This window works just like the default one, so you can add groups and sort resources in any way you see fit. In my example, I created a view called “Balls," where I created groups for each ball available in HackyZack. This way, I can keep the object, sprite, and sound effects all organized in individual folders, for quick access when I need to change one or all of them.
5. Bookmarks: This feature isn’t new to GMS2, but it’s one of the most under-used navigation features. To create a bookmark in code, all you need to do is highlight a line and press Ctrl + a number from 1 to 9 and zero (Ctrl + 3 for example). This will add a little flag on the line gutter with the number you selected. Next, if you want to return to this specific line, be anywhere else in code and press Ctrl + 3 and it will take you back to that same spot. You can only have 10 bookmarks set at a time, so delete them often if you plan on reusing them.
6. Shortcuts: There are plenty of other useful hotkeys within GMS2, so check them out! Here’s a full list of hotkeys from the GMS2 documentation: Hotkeys in GMS2.
7. Layouts: GameMaker is filled with windows docked as tabs all around the screen. You are able to drag these tabs and place them wherever to create your ideal workspace. One recommendation I have is to save your layout after you are done experimenting with it (in Layouts -> Save Layout), as GameMaker resets it back to default for new projects.
8. Custom skin: Even though the default look for GMS2 is nice, I still enjoy being able to customize it further. If you’ve seen my GIFs on this article, or previous ones, you may have noticed I have a skin that resembles Visual Studio. This is because I’m using a custom skin, which you can find HERE.
If you go through the README file provided by the skin, you’ll notice it works fine, but as soon as there is an update, your skin will be lost. This is due to the game uninstalling everything and installing it back again, which annoyed me the first few times it happened. There is a solution though! Go to the drive where GameMaker is installed for you, make sure you have hidden folders visible, and go to the ProgramData folder. There, navigate into the GameMaker Studio 2 folder and create a folder called “Skins” in there. Place your skin files inside and you are done! Your skin won’t be lost after every update anymore. To set it, open GMS2 and go to File > Preferences > General Settings > IDE Skin. I also changed the colors of my text editor and some other little changes (like colors for specific assets in the resources tab). I encourage you to take an hour or two of your time and experiment with every setting in this menu. There are tons of little checkboxes that can tailor the experience to your liking, so it’s worth it, especially if you are working on a game and will spend hundreds of hours looking at the same screen. This is what my final workspace looks like:
9. Custom background: Similar to the point above, you can also set a custom background to your workspaces. Simply go to File > Preferences > General Settings > Background and pick the image you like.
Then, select whether you want it to keep its original aspect ratio, stretch, best fit, whichever option works best with the image you selected, and apply it. You should end up with something like this:
The new GML is familiar to those of us coming from GMS1.4, but they still added a ton of new features which you should know. I will list the ones that stood out.
10. Inline macros: technically not a new feature since you could define macros before using a separate window, but in GMS2 we can define our macro constants in code by using #macro. These are not as robust as the ones seen in other languages such as C++, but still useful when defining values you want to be constant through the game. The values are also global, so they’ll be accessible to every object and script, regardless of where they were defined at. Good examples where I’ve used them on are for controller input, numeric limits and colors. Notice how for my colors, my constant is actually a script call, so know that is a possibility.
11. Ternary operator: another feature taken from other languages is the inclusion of the ternary operator. Some people suggest against using it since it’s not as easy to read as an if-statement, but I love them for simple calculations that can be represented in one line. If you’ve never seen it, then know it is a one-line statement that checks for a conditional and then returns one value or another, depending on the boolean result. The structure follows:
(Conditional statement ? value if true : value if false);
Two examples of where this can be useful are:
_canMove = (isOnGround && !isFrozen ? true : false);
_score += (timeInLevel < 20.0f ? 5 : 2);
In the first statement, we are checking if the player is on the ground and not frozen, then they can move, or else they can’t. Sure, you can do this with an if/else statement, but that would take about four lines of code, where this operator simplifies it.
In our second example, we are checking if the time the player took to complete the level was less than 20 seconds to calculate the score. If it was, then we add five to the score but if they didn’t, then we only add two. Just make sure to only use the ternary operator for simple calculations like this one as it can hurt readability when trying to make it work for more complex conditional situations where an if/else block is preferred.
12. Clean up event: In previous versions, if you were allocating any dynamic memory (surfaces, arrays, data structures) you had to duplicate your code in the destroy, room_end and game_end events. Now, you can place your dynamic resource cleaning code in the clean up event and it will trigger when any of those three happen, eliminating the need for duplicate code and errors that could come from it.
13. Better array initialization: In the past, we had to create a variable and then assign values to it to populate it as an array. We finally have the ability to declare and set initial values to an array in the same statement. It is done with this syntax:
var myArray = [1, 4, 6, 2];
var emptyArray = [];
So we can create an array of four elements with their initial values set and even create an empty array so we can add values to it later.
14. Variable and type introspection functions: Lastly in this section, I want to mention that these new functions are amazing! They let you check if a certain object has a variable, and even get and set the value, by passing the name as a string. There are a lot of great possibilities that these functions open, but there’s one in particular which I’m very passionate about, and for which I’m writing an article on, which is generic serialization. I won’t go too much into detail here since I am working on a very detailed article for it, but it should suffice to say it will allow you to serialize, deserialize, or even inspect any object with the same function call (and some magic behind the scenes). You can read more about the functions I’m referring to HERE and HERE.
15. Notes resources: If you look at the resources window, you may have noticed that a new section called “notes” is there. Yes, this may seem straightforward since it’s just a text editor to type notes in, but I feel like its potential is incredible when paired with source control (check my articles on Setting up Source Control if you want to learn more: Part 1 and Part 2). Imagine you have a checklist, or a bug report as one of your notes. With source control, people on your team can modify these files and they will be automatically updated for everyone else in the team, letting everyone know about the current status of a bug or feature.
If these features made you excited about all the new opportunities and cool mechanics that you can create taking advantage of them, then you should take a peek at the GameMaker road map. It’s filled with all additions they are planning on bringing in the next few months and I for one can’t wait to get my hands on some of them. For example, these I’m really excited about:
16. Game language support: I quite like GML, but I wouldn’t mind being able to code using other languages such as Python or LUA.
17. Personal asset library: I don’t remember how many times I’ve had to dig through my hard drive to find a script or code snippet I need. With this feature, you’ll be able to save those useful scripts you use all the time and access them from any project.
18. Save GIF: GIFs > Screenshots in my opinion, so having a built-in way to create them sounds great.
19. Tile collision: Having to make collision objects and place them on top of your tiles can be a chore sometimes, so having the options to make our tiles have collision boxes on them is a great addition.
20. Resize event: Having worked with surfaces extensively, I’m really happy about this event. Surfaces get destroyed when the window is resized, but you get no notification of this, so you have to constantly check if your surface still exists or not. This will fix that frame-by-frame query, hopefully reducing bugs and improving performance.
21. GML: method data type to allow calling scripts through variables: Yes! I can already see how we can make GML feel a bit more object oriented when using this functionality, but having the ability to assign a function to an object and then performing operations on that object like:
oPlayer.SetHealth(20);
Instead of the current way:
SetHealth(oPlayer, 20);
22. GML: data structures as a true datatype (not just an index): The reason I’m happy about this one is that it will greatly improve how we do variable introspection at runtime, having better information about each object and not just handles.
23. GML: Chained arrays and accessors - allow foo[a][b][c]: No more temp variables to access each level of a 2-3 dimensional array? Sign me up!
24. GML: Inline functions - allow var a = function( a, b ) { ….. }: This is areally cool new feature, especially when used as I described above with being able to call scripts from variables.
25. GML: lightweight objects: These are objects that hold data, so they don’t call their step and draw events, making them super fast and great ways to pass information around using objects that don’t update.
These lists were picked because I found them interesting, but it isn’t an extensive look at all that’s new with GMS2. I encourage you to keep exploring the IDE and find more on your own. Also, if you run into any bugs or have suggestions you’d like to see added, YoYo Games has a way of doing so by submitting your suggestion/bug report here: YoYo Bug Report. I’ve submitted two or three reports to them and they’ve all been fixed, so they definitely take it into account.
Feel free to contact me to talk about any features you’d like more clarification on, or discuss the possibilities of the features to come in the near future! My Twitter account is @AleHitti.
Alejandro Hitti is a videogame Programmer and Designer from Venezuela. Although his background is in C++ and working using custom-made game engines, his two commercial games, INK and HackyZack, were made using GameMaker Studio 1.4. With the release of GameMaker Studio 2, that became his engine of choice. The novelty of GMS2, paired with his knowledge of the previous version, ignited his interest to create tutorials that focus on this new engine.