Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

12. June 2018


If you’ve recently been to the GameFromScratch tutorial series page recently you may have noticed the addition of a new Armory game engine tutorial series.  It’s not actually hosted on GameFromScratch, instead it’s on our newly launched sister site (watch out, the paints still wet!) DevGa.me.  Don’t worry though, nothings changed, it’s just a newer, cleaner, ArmoryDevGame900x600mobile friendly home for tutorial series, I’ll explain more about this later.  For now, just be aware there is a new text and video based tutorial series on the Armory game engine under development!


Armory (or Armory3D) is a newly free open source cross platform game engine that runs inside and tightly integrates with the Blender application.  If you are interested in learning more about Armory and why I’m so excited about it, be sure to check out Introduction to Armory video.  The series is still quite young but already there is a fair bit to get you started.  Right now the series consists of:

The entire series homepage is available here.

Additionally the video series has begun, lagging slightly behind the text series.  So far videos consist of:

There is a (very small for now…) playlist available here.


DevGa.me is not a blog format and does not have any news, it’s just home to tutorials.  I will however announce new tutorials here on GameFromScratch, so stay tuned!  If you want to discuss the new series, there is a conversation over on the Armory discussion forums or leave a comment below or on YouTube.

Programming, Art ,

11. June 2018


Just finished adding another tutorial to the ongoing Godot 3 tutorial series, Sound Fx and Music.  This tutorial covers a ton of topics around audio:

  • Playing audio using AudioStreamPlayer
  • Positional audio using AudioStreamPlayer2D
  • Importing and loading audio files, WAV and Ogg
  • Using the Audio Bus
  • Creating special effects such as panning, reverb and chorus
  • Managing volume
  • Using sound with Area2D


The series homepage is available here.

Programming ,

12. February 2018


Today Unity have released a very high quality and full featured 2D Game Kit, available here.  The kit is a combination of 2D platformer game with multiple levels, a loading screen etc.  It has been designed in such a way that much of the game content can be customized and configured without ever having to write a single line of code.  Additionally there is a step by step tutorial series as well as comprehensive reference material that show you how to create your own 2D game using the game kit.  The kit is available completely free and can be downloaded from the asset store.


If you are interested in seeing the Unity 2D game kit in action be sure to check out this quick video, which is also embedded below.


Programming, GameDev News , ,

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 , ,

Month List

Popular Comments