GameMaker: Window sliding effects

Window sliding example for GameMaker

This post is about creating window sliding effect such as seen in my old program called GMConveter. Program itself was a bit of joke actually, since at the moment of it's publication the only actual difference between GM80 and GM81 formats was a version byte in file header, which GMConverter would change, making files compatible again. Not too bad of functional part for something that was downloaded over 4 thousand times over course of two years, right?
Apart from inner simplicity, it also had nice visuals, including a nice window sliding effect used on start and end of program. And that's what this article is about.

Continue reading

GameMaker: Recursive folder copying

In some situations you may want to copy a folder from your GameMaker game. And it would seem trivial but not that easy. file_copy can only copy files, and folder functions only allow you to create, check, and search folders for files. However, given these standard functions, implementing a folder copying routine is fairly easy.
Idea used here is to find a list of files and folders via file_find_*, and then go through them, checking whether they are files or folders, copying or recursively calling recursively function script accordingly. Sure that poses a potential problem if you were to copy entire disc contents to other location, but you are probably not going to be doing that via GameMaker... right?

Attached example contains the function and brief demonstration of functionality (you have to input source/destination paths as text). Script source is located below download button.

Download GMK

Continue reading

GameMaker: Basic 3d bone animations

This example demonstrates how to create fairly basic bones for use in GameMaker 3d games fairly easily. Such can be used for character and environment animations, provided that they can be split in rotatable parts to some extent.


As you may know, GameMaker does not quite support vertex animations. That means that models have to be either composed on-fly (which is a slow method), or "baked" as a number per-frame models (which takes amounts of memory proportional to how smooth you want your animations look). Bone animations, on other hand, work fast (since only transformation calculations need to be done), and require small amounts of memory.


Idea of bone transformations is that you have so called bones, which can be attached to other bones, which makes them rotate together. That means, to find transformation matrix (position, rotation, and scale) of any given bone, you need to go through all of its "parent" bones, combining matrices. Normally this would be a slightly tricky task (especially if engine of choice does not have matrix operations built in), but, fortunately, GameMaker includes a set of functions to manipulate matrices (d3d_transform_).

Attached example includes a minimal system for linking bones together, drawing them, and a sort of procedural animation example.

Download GMK

GameMaker: Shadow casting in platformer games

This is a very old example of mine actually (creation timestamp says Sep 2010), which I've recently fixed & improved by request.
It demonstrates a simple algorithm to cast shadow from instance in platformer game. So when player jumps, shadow is displayed on ground below (realism!).
For the sake of simplicity and performance, shadows are checked against bounding boxes by default. Pixel-perfect checking is added as a separate condition, requiring affected objects to be children of obj_complex.
If you're interested in how this works behind-the-scenes, here's an illustration:

Outlined instances are ones used for finding top-most position below the player (which shadow will be cast onto). Red line is a number of point checks to indicate top-most point on objects with precise masks.
As another random visual tweak, there's a piece of code added to make shadow shrink as caster gets further from ground. A minimal touch, but these do stack.

Download GMK

GameMaker – Substitution “cipher”

This example provides a function to substitute all characters in a string, which present in first set of characters, by characters from second set. This can be used to substitute l/e/a/s/t/o characters in a string by 1/3/4/5/7/0 accordingly, turning your "Hello World" into "H3110 W0r1d" in single script call, or to replace/swap characters with completely irrelevant ones, providing simple "encryption" (e.g. Caesar cipher or various substitution methods) to challenge the player.

Functional part is presented by a single script, named string_subst(string, from, to), which returns string with all characters from set from replaced by according characters from set to. As long as both from and to are of equal length and do not contain repeating characters, output can be "decrypted" by passing parameters in swapped order, e.g.

var asrc, adst, source, encr, decr;
asrc = "0123456789"; // source "alphabet"
adst = "3456789012"; // destination "alphabet"
source = "51"; // source text
encr = string_subst(source, asrc, adst); // "encrypted" text
show_message(encr); // Displays "84;"
decr = string_subst(encr, adst, asrc); // "decrypted" text
show_message(decr); // Displays "51;"

Attached example demonstrates both "encryption" and "decryption", and has nice buttons.

Download GMK

GameMaker: Cycling random funky text

This example pictures something that I wanted to make for few days - awesome funky random text script.

The idea behind this effect is simple - for every string character that should be randomized, replace it with any other renderable character that has same width (so that output string would not shift in directions, and you could somewhat guess the words if you know letter widths well).

To keep lookup speeds optimal, system generates a hashtable (ds_map) for each font when it's first used with it. This allows high processing speeds even for GameMaker: Studio with it's 65K character limit per font.

Program interface consists of 3 functions, one of which is initialization (required to be called before you try to use system), one is font hashtable generation (just in case you want to push these manually at game start), and actual text_rand(string, font) function, which will return a string with randomized character for given font.

This sort of rendering may come particularly useful for different experimental games, along as an interesting way to censor text.

Download GMK Live demo

GameMaker: Input field (semi-advanced)

There are multiple cases where you may want to let user input text in a familiar way, keeping things intact with system settings and allowing minor tweaks like repositioning the text cursor. Such include consoles, chatboxes, input fields, and other. This example covers these needs with fairly short (less than 70 lines total) and fairly understandable code. It includes the following features:

  • Keeps track of input text on window focus loss. If you've tried to make an input box before, you may be similar with that unpleasant default behaviour of keyboard_string in GameMaker.
  • Allows to reposition cursor (left / right / home / end keys)
  • Allows to use Delete key to erase characters
  • Can be easily modified to support other keys and shortcuts

Example includes actual input field object, and sample list drawer, to which typed text is sent upon press of Enter.

Download GMK

GameMaker: Jetpack platformer

This is an older example of mine, featuring pixel-perfect movement and collision engine for jetpack platformer game. As extras, it includes particle spawning, and impact velocity calculations. Current version is updated to have a cleaner code style (no more bracket-less conditions and seriously doubtful operator combinations), as long as more comments (increasing comment coverage to a value close to 100%). Also there was a game being made around this concept once.

Download GMK