Game Maker Studio 2 Create Event Again
20 GameMaker tips, tricks, and GML code snippets to use in 2021
This article has been updated since its original posting on June 20, 2018.
Did you know you lot tin prompt a user to send a pre-written Tweet from YoYo Games' GameMaker in merely a single line of code? How about this: numbers are less-precise on the HTML5 target when compared to the Windows target. Or that the YoYo Compiler target evaluates expressions and functions backwards?! This article is brimming total of information almost those facts and more.
Welcome to a curated list of twenty "Quick Bits", GameMaker Studio ii tips, tricks, and code snippets that come from my Step Event Twitter account. Whether you're seasoned with the software or just getting started on your game making journeying, chances are yous'll learn something new.
Get the most out of your new GameMaker Studio ii license. Here are the top 20 GML tips and code snippets for game devs in 2021.
#1 - How to reference a specific instance in GameMaker
The instance-creating functions —instance_create_layer andinstance_create_depth — are amongst the showtime functions that many new GameMaker Studio 2 developers volition acquire how to use. The importance of adding copies of specified objects into the game world goes without stating. But, there's more than to these backbone functions than what novice game makers may realize.
Image Transcript
instance_create_layer and instance_create_depth functions return the id of the newly-created instance. You tin can store this value in a variable so the particular instance tin be addressed.
#ii - Macros and Enums in GameMaker
Image Transcript
Macros and Enums don't need to exist chosen to be initialized.
An uncalled script, which houses your Macros and Enums, is enough for them to exist loaded into your game.
This Quick Bit was submitted to The Step Event by https://twitter.com/designbycloud
#three - Middle-click fourth dimension saver in GameMaker
Image Transcript
Time saver: heart-click a resources reference or function in the Code Editor. GMS2 will open the respective resource or Aid Doc entry.
#four - Ternary Operators in GameMaker Studio ii
Image Transcript
GMS2 supports ternary operators, an elegant approach to provisional expressions.
<condition> ? <status is true> : <condition is fake>
# 5 - Hold the result of an expression in a variable
Image Transcript
Instead of using an if-argument, you tin can hold the result of an expression in a variable.
#half-dozen - Counter lag past using delta timing in GameMaker
Paradigm Transcript
Delta timing is the number of microseconds that have passed since the last frame. Necktie movement to delta_time for consistent move speeds across all devices, regardless of frame rate.
#vii - Rotate an object to face the mouse in GameMaker
Epitome Transcript
How to gradually rotate an object's direction (eastward.k. to face towards the mouse)
#8 - Use GameMaker'south clamp instead of if-statements to limit values
Paradigm Transcript
Instead of using if-statements to limit the value of a variable, you can use clench.
#9 - Make text and sprites blink in GameMaker
Image Transcript
Make stuff - similar text and sprites - wink every [rate] seconds using this glimmer script. Supply values for "on" and "off" states, and optionally define the rate, which will default to i second.
#10 - Customize your GameMaker documentation experiences
Prototype Transcript
Get in the addiction of writing make clean code by customizing your documentation feel!
In Preferences → Objects, yous can setup a template that all Scripts and Events volition default to.
This Quick Bit was submitted to The Step Result past https://twitter.com/designbycloud
#11 - Send Twitter tweets from your GameMaker Studio game
#12 - How to insert commas into numbers (thousands)
Prototype Transcript
How to insert commas into numbers, like a score (e.g. 1234567 → one,234,567):
#13 - Logical inverses brand for easy GameMaker toggles
Image Transcript
Logical inverses brand for piece of cake toggles.
In the example below, variable soundEnabled switches between true and simulated each time the Southward key is pressed.
#xiv - Keep your GameMaker Linguistic communication code corking and linted
Image Transcript
Lawmaking formatting getting messy? Copy-paste yoru GML into a lawmaking beautifier.
http://jsbeautifier.org works cracking for GML even though it's intended for JavaScript!
#15 - Nuclear Throne camera, centered between player and cursor
Image Transcript
Making a camera that resembles the one constitute in Vlambeer'due south Nuclear Throne.
This code snippet centers the photographic camera, cam, betwixt the role player object, obj_player, and the cursor.
#sixteen - Remap a number from one range to another in GameMaker (similar to Processing.js)
Image Transcript
Re-map a number, arg0, from ane range (arg1,ii) to another (arg3,4).
#17 - Incremental 45-degree rotation in GameMaker
Prototype Transcript
Rotate a sprite towards the mouse in increments of 45 degrees for easy 8-directional facing.
#18 - GameMaker Studio "piddling endian" hex colour format
#19 - GameMaker number precision can be unlike depending on targets
Epitome Transcript
Numbers are actually treated every bit floating point values when doing comparisons in GMS. You may become different results on different platforms when checking what apepars to be an integer.
HTML5 target has less precision than Windows target. 0.5 + 0.5 does non equal 1 with floating point maths, and it may be that 1 is really something similar 1.000000000001.
To go around this, you tin can apply the floor() or round() functions to generate a fixed integer value.
Quick Bit source, caption, and more than HTML5 differences: https://assistance.yoyogames.com/hc/en-us/manufactures/216754018-HTML5-Issues-And-Differences
#xx - GameMaker expressions and functions are evaluated differently using the YoYo Compiler
Image Transcript
When using the YoYo Compiler targets, all expressions and functions are evaluated from left to right. On all other target platforms, they are evaluated from right to left.
This, for example, will give different results depending on the platform:
Thanks for reading!
Hopefully y'all institute some of these GameMaker Studio 1.four and 2.x lawmaking snippets, tips, and general trivia useful! You should now be able to answer the following questions that often pose game makers:
-
How do I post a tweet to Twitter using GameMaker?
-
You lot can mail service a tweet using a simple url_open_ext function telephone call and Twitter'southward intent API. Refer back to #11 for the code snippet.
-
-
What are floating point numbers and why should I exist concerned with precision?
-
Why doesn't GameMaker use standard red, greenish, bluish hex values?
-
This is left-over from the programming language that GameMaker was originally written in, Delphi!
-
-
How practise I add commas to my numbers?
-
Formatting your numbers, like currency, is as easy every bit casting integers to a string and adding a comma character every tertiary space, starting from the end.
-
-
What tin I do to finish my game from lagging?
-
Every bit #half dozen demonstrated, you can use the delta timing functionality to assist combat lag in your game.
-
If you're feeling like sharing your newfound cognition, pass this mail along to a friend.
Follow The Step Event on Twitter for more than Quick Bits. Know something that would make a great Quick Flake? Allow me know and you lot'll be credited!
Source: https://www.zackbanack.com/blog/gamemaker-studio-2-tips-and-tricks
0 Response to "Game Maker Studio 2 Create Event Again"
Post a Comment