GameMaker: sprite_add_sprite in Studio / Studio 2

On this fine day[1], we're[2] proud to announce that we're bringing back everyone's[3] favourite GameMaker 8.x function!

That's right, we're bringing back sprite_add_sprite! 🎉

Now, you might be thinking either "this is not what I've expected" or "this is exactly what I expected [after reading the title] and I only have more questions now". You see, there's not always justification for things happening, sometimes they just do.

Should you actually need this function or if this introduction got you curious, take a seat and let me tell you a story (and some code),

Continue reading

Small Haxe questions & answers

Sometimes I have one or other semi-obscure Haxe question, find nothing via search, and think "I feel like I asked about this before somewhere". And sometimes it turns out that yes, I did, but it usually takes a while to find what project houses the solution code, or where did I ask it.

This post is a small dump of such questions, mostly eventually self-answered.

Continue reading

GameMaker: draw_sprite_ext_skew

(click to interact) (mouseover/click to play GIF) Drag sliders and click things (if JS is enabled)

This post is about a slightly fancier version of draw_sprite_ext - maybe you want to apply skewing/shearing to the sprite, or scale it after rotating it, or use a 2d matrix transformation.

The built-in function isn't made for that, but, with a little bit of math and draw_sprite_pos, you can have a script for this.

Continue reading

GameMaker: Formatted date output

(click to interact)

This is a small post about a replica of the strftime function seen in PHP, C standard library, and a handful of other APIs. Such a function takes a date-time and prints it according to the given format string.

The script supports the common formats and those that mapped reasonably to GML functions.

Continue reading

GameMaker: Microtester

Performance tester/comparator for GameMaker
And other reasons to avoid overusing reflection

On this fine day I have published the project that I use to compare relative performance of different approaches to algorithms. It aims to get a few things right with this:

  • Tested scripts are re-shuffled between runs to lower execution order/CPU cache bias.
  • Script call time can be excluded if you are comparing approaches rather than actual scripts.
  • Easy to use - you add scripts that you want tested to the project, specify how you want them to be called, and that's it.

The project can be found on GitHub.

GameMaker: Simplest possible instance methods

A tutorial about implementing instance methods in GameMaker.

After seeing series of increasingly strange uses of "user events" in GameMaker games for object-bound actions, it came to my attention that most people are only vaguely aware of other ways of doing things, so I decided to write a small blog post on the matter.

There are many uses for these - for example, you might want to have a "take X damage" method on your enemy objects so that it can be varied depending on requirements - some enemies might just take damage, some should retaliate on being hit, some might have a fancy damage reduction formula. Being able to comfortably define/redefine methods on per-object-type basis can help a lot.

Continue reading

Variable references in GameMaker

A tutorial about variable references in GameMaker.

Sometimes you might want to pass an instance variable by reference rather than by value - to have a script modify instance variable(s) passed to it without having to return them, or have an instance save a reference to variable(s) that it should change on other instance, or doing anything else that would usually imply using pointers.

But it might seem like GameMaker does not support such things... or does it? Well, we'll make it.

Continue reading

Simple intersection checking between rotated rectangles and circles/points

(click to interact)Intersection checking between rotated rectangle and point/circle
(mouseover/click to play GIF) (click and drag to adjust rectangle size/position/rotation; distance to a circle is shown)

Suppose you have a rotated rectangle and a basic shape that rotation doesn't matter for (such as a point, circle, or a line segment), and you want to check whether the two are intersecting - be that for collision handling, hit testing, or whatever else.

On a glance this might seem like a bother because things are rarely too simple with rotated rectangles, but in this case it isn't - because you can "unrotate" the rectangle.

This small post is about that.

Continue reading