Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

6. December 2017


GameMaker is a seminal game engine, with roots dating back to the late 1990s.  It is a cross platform 2D game engine with tools that run on Windows and Mac machines while capable of targeting both desktop operating systems as well as Ubuntu Linux, Android, iOS, UWP, HTML5, XBox One and PlayStation 4 consoles.  GameMaker is commercial software with a free trial available, we will discuss pricing shortly. 

The closer look series is a combination of overview, review and getting started tutorial aimed at helping you decide if a given engine is the right choice for you.  As always, there is an HD video version available here and embedded below.

Let’s jump right in with GameMaker Studio 2!


The Tools

GameMaker Studio is an all in one integrated environment for creating games.  It includes everything you need in a single application with a tabbed working environment and a unique virtual desktop style approach supporting multiple editing windows at once.  The all in one all tools at hand nature of GameMaker is probably one of it’s greatest selling points.


The Main Interface

image


Side and bottom panels can be collapsed down to give more room:

image


The primary work area is tabbed, supporting multiple open views at once:

image


As mentioned earlier, GMS has a workspace setup that enables you to work with and pan between multiple editors at once, like a giant virtual desktop.

GMSDesktop


The resource panel is commonly used across the various editors and contains the various assets that make up your game.  You can also drag and drop assets onto this window to import them for use in your game.  For example, dropping in an image file will create a new Sprite entity for you.

image


You can also create new entities via the dynamic right click menu.  For example, right clicking the Tile Sets area will bring up this menu:

image


The Room Editor

image

This is your traditional level editor, where you can create various layers of entities that compose your game level.  A top left you have the layers controls, enabling you to create/delete/hide the various layers that make up your game.  Layers can be composed of instances (objects), backgrounds, tile maps and paths.  The editors below the layer controls change dynamically based on what kind of layer is selected.


Selecting a tile layer brings up the tile map editing tools, including a palette of tiles you can paint with.

image

GMS even has support for auto tiling, if your tileset is compatible.


The Sprite Editor

image

This editor enables you to define how a sprite is imported, the various frames of animation if any as well as a preview of the sprite or animation.  Additionally, clicking Edit Image brings up a full blown image editor within GameMaker.

image

This is a full blown sprite editing package with a variety of brushes available, full layer support, the ability to paint across frames, several tools such as text tools, polygon tools, a magic wand selection tool, mirroring tools and more.  Pretty much all the functionality you would expect for creating or editing sprites is available directly in GMS.


Sound Editor

image

You also have control over sound effect details via the sound editor/mixer.  Supported audio files include wav, mp3, wma and ogg.


Tileset Editor

image


As mentioned earlier, the room editor has full support for tileset layers.  There is an editor for defining tilesets as well as defining auto tiling support.  There are also editors for defining tile animations and creating predefined tile brushes.


Path Editor

image

This editor is used to define paths, either straight line or curves.  Often used for AI paths, the generated paths can be used and editing directly in the room editor.


Script Editor

image


This is the built in editor for developing games using GameMaker Script.  It has syntax highlight, code suggestions and a selection of other features.

image

The code editor is also used for shaders.


Drag and Drop Editor

In addition to GMS scripting, GameMaker also provides a drag and drop programming option.

image

You can use drag and drop from the toolbox to script your programs behaviour.  We will cover both programming options in more detail shortly.


Font Editor

image


Enables you to import and preview fonts for use in your game.  Fonts can be in either true type or open font formats.


Object Editor

image

The Object Editor is where you will start to tie your various resources together.  For example, your main character will be an object that connects to a sprite, while handling various different events.  Objects are created in the Object Layers in the room editor and generally represent the entities that make up your world.  We will look at objects in a bit more detail later.


Programming In GameMaker

You may be wondering at this point how exactly you implement gameplay logic in your GameMaker game?  Essentially you attach logic to objects in the game world.  When you edit an object you will notice there is an Events option.

image


Click the Add Event button and you will see the various events you can respond to in your game:

image


These are called at various points by the game engine and are analogous to the game loop in other engines.  Step is called once per pass through the game loop and is most commonly where you will handle update logic.  There are also events for when the object is created, destroyed, etc… as well as various options for responding directly to events such as collisions, touches, etc.


You can also wire up code to be called when a Room is created, via the Creation Code button:

image


Next it’s a matter of deciding HOW you want to program in GameMaker, via Drag and Drop as well as directly using GameMaker scripting.


Scripting

Scripting is done using Game Maker Language, or GML, which is a C like scripting language.  The syntax is fairly simple and if you’ve had any prior C, Python, C++ or similar language experience, picking the language up should be fairly simple.  There are built in methods for most functions you would want to perform such as graphics drawing, audio code, networking, platform specific tasks like in app purchases etc.  There are also built in data types such as Stacks, Lists, Maps and Queues.  Actually teaching GML is beyond the scope of this document but you can access the language reference here.

If functionality is lacking it may be available on the GameMaker Market Place or you can add it yourself by creating a native extension.  You can add new functions to GML in this manner.


Drag And Drop

Programming via drag and drop in GameMaker is your other option and is a great choice for people that just want to jump in and figure things out on their own.  Don't worry too much about performance as the DnD code is ultimately generating GML script so performance should be roughly the same.  In fact, you can switch freely between the two programming methods at will within the same project or call GML directly in your DnD script.

Creating scripts in DnD is as simple as dragging in predefined functions to create a flow chart of sorts that occurs top down, like so:

GMLDnD

Once again, you can freely switch between the two methods.  Additionally, in any script your can right click and select Convert To Drag and Drop.  A reference of all the drag and drop tiles is available here.


The Price

GameMaker is commercial software, so that means there is a price tag attached.  There are multiple versions available for GameMaker as well as addition platforms coming with an additional price tag.  Pricing (as of today, 12/6/17) breaks down as follows:

image

image


In addition to these various different platforms, there is also now a new $39 per year ( most of the above non-console licenses are permanent buy once ) Creator Edition aimed at hobbyist developers.  It is fully featured but requires you to choose Windows or Mac and also requires your game display a splash screen.  There is also a heavily limited free trail available.  For more information on pricing or to download the trial visit here.


Community and Documentation

As you might expect for such a long lived game engine, there is also a very well established community.  The forums are available here.  With almost 20K registered users and 230K posts, the forums are quite active and contain a wealth of knowledge, although much of it is for earlier 1.x versions.  Questions seem to be answered fairly quickly.  In addition to the forums there is also the YoYoGames help desk containing several guides and how-tos.

There is also a fairly comprehensive GameMaker Studio manual available online which can be opened directly within Studio.

Additionally, there are several books available for GameMaker Studio such as:


In addition there are several tutorials and start kits available on the online marketplace, which we will talk about…


Online Marketplace

Quickly becoming the must have feature of modern game engines, GameMaker has an online store available, containing free and commercial assets including demos, scripts, sprites, shaders, extensions and more.

image

You do not need to have GameMaker Studio installed to access the marketplace, you can browse it in your browser here.


Conclusion


At the end of the day, GameMaker Studio faces a challenging new world as it is facing increasing competition from free and free to start game engines.  Is it worth it?  That is impossible for me to answer, as value is very subjective.  Game Maker is certainly a very complete 2D engine with a vibrant community and tons of resources.  Compared to the previous versions, the 2.x editor contains a great deal more polish and most every tool you would need is included out of the box.   Game Maker has certainly proven itself a production capable engine, having powered such titles as Hotline Miami, Undertale and Spelunky, all titles that have seen commercial success.

A proven catalog of game is always a strong selling point.

Personally, if you are working on a 2D title using Windows or Mac, Game Maker is certainly worth considering.  Do keep in mind however that as you add more platforms, you also add more cost.  In many cases though, this means you are ready to commercialize your title, so hopefully cost isn't as much of a concern.  I do think however they are making a mistake in charging for the Creator Edition.  Personally I would do away with the trial completely, make Creator free and charge people to deploy to additional platforms.  If this was the case it would be a great deal easier for me to recommend you check out GameMaker yourself.  Without a free option, its hard to recommend in the face of so many free/free to start options out there.  The engine is great, productive, proven and easy to learn… just saddled with a bit of a dinosaur business model.


The Video

Programming, General, Design , , ,

28. November 2017


JetBrains released version 1.2 of the Kotlin programming language.  Kotlin is a statically typed JVM based language that also has the ability to be compiled to JavaScript.  The goal of Kotlin is to be a “better Java”, while remaining fully intraoperative with the Java language and ecosystem.  AsKotlin of Android Studio 3.0, Kotlin is a first class language in that IDE.

In regards to the Kotlin 1.2 release:

In Kotlin 1.1, we officially released the JavaScript target, allowing you to compile Kotlin code to JS and to run it in your browser. In Kotlin 1.2, we’re adding the possibility to reuse code between the JVM and JavaScript. Now you can write the business logic of your application once, and reuse it across all tiers of your application – the backend, the browser frontend and the Android mobile app. We’re also working on libraries to help you reuse more of the code, such as a cross-platform serialization library.

Kotlin 1.2 is already bundled in IntelliJ IDEA 2017.3, which is being released this week. If you’re using Android Studio or an older version of IntelliJ IDEA, you can install the new version from the Tools | Kotlin | Configure Kotlin Plugin Updates dialog.

This release includes a lot of work done by external contributors, and we’d like to thank everyone who sent us feedback, reported issues, and especially those who submitted pull requests.

Multiplatform Projects

A multiplatform project allows you to build multiple tiers of your application – backend, frontend and Android app – from the same codebase. Such a project contains both common modules, which contain platform-independent code, as well as platform-specific modules, which contain code for a specific platform (JVM or JS) and can use platform-specific libraries. To call platform-specific code from a common module, you can specify expected declarations – declarations for which all platform-specific modules need to provide actual implementations.


Multiplatform projects isn’t the only new feature of Kotlin 1.2, other new 1.2 features include:

  • A more concise syntax for passing multiple arguments to an annotation (array literals);
  • Support for the lateinit modifier on top-level properties and local variables, as well as checking whether a lateinit variable is initialized;
  • Smarter smart casts and improved type inference in certain cases;
  • Compatibility of the standard library with the split package restrictions introduced in Java 9;
  • New kotlin.math package in the standard library;
  • New standard library functions for working with sequences and collections, including a set of functions for breaking a collection or sequence into potentially overlapping groups of a fixed size.


You can learn more about the release on their blog as well as in the more detailed What’s New article.  I did a cheat sheet for programmers used to other languages to get up to speed with Kotlin.  This was written shortly after the language was released however, so may not be current in regards to modern Kotlin language features.

Programming

21. November 2017


Up till this point in our ongoing Allegro Tutorial Series we have covered creating a window, handling a game loop, drawing sprites, handling input and playing audio, pretty much every aspect of creating a basic game.  In this final tutorial we are going to look at some of the other graphics capabilities in Allegro, specifically graphics primitives.


If you’ve been following the tutorial series till this point, it should come has no surprise that primitives are implemented as an add-on as well.  In this case it’s using the Primitives add-on:

image


Without further ado, let’s jump straight into the code example:

#include "stdafx.h"
#include <allegro5\allegro.h>
#include <allegro5\allegro_primitives.h>

int main()
{
	ALLEGRO_DISPLAY * display;

	al_init();
	display = al_create_display(640, 480);
	al_init_primitives_addon();
	float points[8] = {0.0f, 0.0f, 100.00f, 100.00f, 200.00f, 100.00f, 640.00f, 150.00f};

	float polygon[8] = { 640.0f, 100.0f, 640.0f, 300.0f, 380.0f, 350.0f, 200.0f, 200.0f };

	bool running = true;
	while (running) {
		al_draw_line(0, 0, al_get_display_width(display), al_get_display_height(display), al_map_rgb(255, 0, 0),5.0);
		al_draw_rectangle(100, 100, 300, 300, al_map_rgb(0, 255, 0), 1);
		al_draw_ellipse(300, 300, 120, 50, al_map_rgb(0, 0, 255), 3);

		al_draw_spline(points, al_map_rgb(128, 128, 0), 8);

		//al_draw_polygon(polygon, 8, ALLEGRO_LINE_JOIN_BEVEL, al_map_rgb(255, 15, 15),3,1);
		al_draw_filled_polygon(polygon, 8, al_map_rgb(255, 0, 0));
		al_flip_display();
	}

	al_destroy_display(display);
	
	return 0;
}

When you run this example you should see:

image


Granted, a pretty chaotic mess in the end, but illustrating a number of concepts in a single example.  First we start off by calling the appropriate init() method for the Primitives add-on.  When then draw a line in red ( R = 255, G = 0, B=0 ) from the top left to the bottom right corner of our display.  Next we illustrate drawing a rectangle, followed by an eclipse.  Finally we illustrate a slightly more advanced example of drawing a spline, then a polygon, by providing an array of points/vertices to draw.  As you can notice from the commented function, there are also functions specifically for drawing primitives fill with a solid colour.


We have only scratched the surface of the drawing functionality the Primitive add-on is capable of in this example, but the basic concept applies to all functions.


That concludes the tutorial series and should hopefully give you a good foundation on getting started with Allegro.  If you wish to jump into more depth with Allegro, be sure to check out the official manual available here.


Back To Table Of Contents

Programming , ,

13. November 2017


In the first tutorial we looked at creating our initial application, while in the second tutorial we looked at events and a cleaner game loop, in the third tutorial we looked at drawing bitmaps on screen.  We then moved on to handling the keyboard and mouse while in this tutorial we are going to cover handling audio in Allegro.


Once again, lets jump straight into the code example.

#include "stdafx.h"
#include <allegro5/allegro.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>

int main()
{
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_SAMPLE *sample = NULL;
	ALLEGRO_SAMPLE_INSTANCE *sampleInstance = NULL;

	al_init();
	al_install_audio();
	al_init_acodec_addon();
	
	al_reserve_samples(1);

	sample = al_load_sample("explode.wav");

	// The commented out version below is much easier
	//al_play_sample(sample, 1.0, 0, 1, ALLEGRO_PLAYMODE_LOOP,NULL);

	//However if you need access to additional control, such as currently playing position, you need
	//to attach it to a mixer, like the following example
	sampleInstance = al_create_sample_instance(sample);
	al_attach_sample_instance_to_mixer(sampleInstance, al_get_default_mixer());
	al_play_sample_instance(sampleInstance);

	// Loop until sound effect is done playing
	while (al_get_sample_instance_playing(sampleInstance)) {}

	al_destroy_sample_instance(sampleInstance);
	al_destroy_sample(sample);
	al_uninstall_audio();
}


At this point it should come as no surprise that audio support in Allegro is implemented as an add-on.  In fact it’s implemented as a pair of add-ons.

image


The audio add-on implements the audio playback functionality, while the Codec add-on is what supports loading the various different audio file formats.  Speak of file formats, Allegro supports the following file formats: .wav, .flac, .ogg, .opus, .it, .mod, .s3m, .xm and .voc.  Since they are implemented as add-ons, we once again need to call the corresponding init or install function before we can use audio functions.


Audio files are loading into memory as samples.  Before we go to far, we need to reserve resources for the samples we are going to use.  In this simple example we have only a single example, thus we call al_reserve_samples(1).  Now that our resources are allocated, we actually load the sample from disk with a call to al_load_sample(), in this case I am passing in a sample named “explode.wav”, which I have copied into my debug directory. 


Now that our sample is loaded into memory there are two ways to access it.  One is very simple, a fire and forget function you can see commented in the example above.

	al_play_sample(sample, 1.0, 0, 1, ALLEGRO_PLAYMODE_LOOP,NULL);

This is the easiest way by far to play audio in Allegro.  This example will play the sample “sample” at normal volume (gain), centered, at regular 1x speed, in a constant loop.


If you want a bit more control over the audio playback however, this function will no longer suffice.  So for example if you want to be able to determine when a sample is done playing, you instead need to create a SAMPLE_INSTANCE, which is done by passing our sample to al_create_sample_instance().  We also need a mixer to actually play the instance, which thankfully there is one already available for us, accessible using the function al_get_default_mixer(). 


Notice that both the sample and instance need to be cleaned up after use or they will leak resources.  Not shown in this tutorial, there are also streaming functions for breaking larger audio files up into smaller chunks for streaming.  In this day of abundant RAM, these functions are less used, so I have not covered them here.


Back to Table Of Contents

Programming , ,

10. November 2017


In the first tutorial we looked at creating our initial application, while in the second tutorial we looked at events and a cleaner game loop then in the third tutorial we looked at drawing bitmaps on screen.  Today we are going to look at handling keyboard and mouse input.  We covered this slightly in earlier tutorials when we looked at event queues and enabled the application to exit when the user pressed a key.  This tutorial will go into a great deal more depth.  Without further ado, let’s jump into the code sample:

#include "stdafx.h"
#include <allegro5\allegro.h>
#include <allegro5\allegro_image.h>

int main()
{
	ALLEGRO_DISPLAY * display;
	ALLEGRO_EVENT_QUEUE *queue;
	ALLEGRO_BITMAP * bitmap = NULL;

	al_init();
	display = al_create_display(640, 480);
	queue = al_create_event_queue();

	al_install_keyboard();
	al_install_mouse();

	al_register_event_source(queue, al_get_keyboard_event_source());
	al_register_event_source(queue, al_get_display_event_source(display));
	al_register_event_source(queue, al_get_mouse_event_source());

	al_init_image_addon();
	
	bitmap = al_load_bitmap("image64x64.jpg");
	assert(bitmap != NULL);

	bool running = true;
	float x = 0, y = 0;

	int width = al_get_display_width(display);
	while (running) {
		al_clear_to_color(al_map_rgba_f(0, 0, 0, 1));
		al_draw_bitmap(bitmap, x, y, 0);
		al_flip_display();

		ALLEGRO_EVENT event;

		if (!al_is_event_queue_empty(queue)) {
			al_wait_for_event(queue, &event);
			if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
				running = false;


			if (event.type == ALLEGRO_EVENT_MOUSE_AXES) {
				x = event.mouse.x;
				y = event.mouse.y;
			}

			if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
				x = y = 0;
				al_set_mouse_xy(display, 0, 0);
			}
		}

		// Actively poll the keyboard
		ALLEGRO_KEYBOARD_STATE keyState;

		al_get_keyboard_state(&keyState);
		if (al_key_down(&keyState, ALLEGRO_KEY_RIGHT))
			if (al_key_down(&keyState, ALLEGRO_KEY_LCTRL))
				x += 0.1;
			else
				x += 0.01;
		if (al_key_down(&keyState, ALLEGRO_KEY_LEFT))
			if (al_key_down(&keyState, ALLEGRO_KEY_LCTRL))
				x -= 0.1;
			else
				x -= 0.01;
	}

	al_destroy_display(display);
	al_uninstall_keyboard();
	al_uninstall_mouse();
	al_destroy_bitmap(bitmap);

	return 0;
}


When you run this application, the sprite will be drawn in the position of the mouse cursor.  Clicking and mouse button will reset the sprite’s position back to (0,0).  You can also control the position of the sprite by using the left and right arrow keys.

GIF

As we can see mouse and keyboard functionality is optional, so we need to call the appropriate init() function for both devices, then later the appropriate uninstall() function to clean them up.  Just like earlier we create an event queue, and register additional event sources for both keyboard and mouse.  As you can see, multiple event types can exist in a single event queue.

Mouse handling is extremely straight forward, when the mouse is moved it will fire a ALLEGRO_MOUSE_AXES_EVENT with the mouse location stored in the events mouse.x and mouse.y properties.  You can also see that mouse button activity fire a ALLEGRO_MOUSE_BUTTON_UP_EVENT when a mouse button is released.  In this case we set the position of the mouse using al_set_mouse_xy().

We take a slightly different approach with keyboard handling.  We could use a similar approach, however it would only handle one key event at a time.  What we instead want to do is poll the current status of the keyboard every pass through our game loop.  We take this approach so we can detect multiple concurrent key presses.  This is done by populating a ALLEGRO_KEYBOARD_STATE structure with a call to al_get_keyboard_state().  We can then poll the status of individual keys by calling al_key_down().


Back to Table Of Contents

Programming , ,

Month List

Popular Comments