Tag: Game Development

(PB) Loading Assets, the simple way.

Posted by on January 23, 2012


Assets are an essential part of most games, how you manage them determines whether you spend more time working on them than dealing with them.

For small to medium games, loading an entire directory and having it referenced to a Map is the ideal solution. It’s both flexible and simple.

The following code allows you to do just this:

Prototype.i LOAD_DIRECTORY_CALLBACK( Map Assets.i(), directory.s, extension.s, name.s, userDefined.i = #Null )

Procedure.i LoadDirectory( Map assets.i(), directory.s, extension.s, *callback.LOAD_DIRECTORY_CALLBACK, userDefined.i = #Null )

	Define.i dir = ExamineDirectory( #PB_Any, directory, "*" + extension )
	If IsDirectory( dir )

		Define.i count = 0
		Define.s name = ""

		While NextDirectoryEntry( dir )
			If DirectoryEntryType( dir ) = #PB_DirectoryEntry_File
				name = DirectoryEntryName( dir );
				assets( ReplaceString( name, extension, "" ) ) = *callback( assets(), directory, extension, name, userDefined );LoadSound( #PB_Any, directory + "\" + name )
				count + 1

		FinishDirectory( dir )
	ProcedureReturn count


To use this code you must define a procedure of your own, this procedure is going to be called on each file to be loaded; you’ll have to load and process the file in this function.

Example use:

Global NewMap sprite.i()
Procedure.i callback_loadsprites( Map Assets.i(), directory.s, extension.s, name.s, userDefined.i = #Null )
	ProcedureReturn LoadSprite( #PB_Any, directory + "\" + name, userDefined )

LoadDirectory( sprite(), "sprites", ".png", @callback_loadsprites() )

The example will attempt to scan through the directory “sprites”, it will execute your callback on each png file it finds inside the aforementioned directory, furthermore it’ll reference the filename (without extension) to the sprite() Map, so when you need a handle for the sprite called “fire.png” you’d just use sprite(“fire”) to obtain it.

Since the files are referenced to a Map by their actual name, you could easily implement a scripting system or any other dynamic management solution for your assets without much hassle.

An interesting part of the code is the return value, it’s actually the number of assets found (not the ones loaded, since your callback could choose not to load a certain file, for instance).

There are several limitations to this simple implementation, which is why I mentioned “small games” – There is no directory recursion, no advanced filtering options, no way to parallel the process on a separate thread and there’s no error handling at the moment.

However, it’s still very useful and I highly recommend you try it out, while it’s not a novel aproach, it’s always been the method I used to load my assets and it just works.

Have fun!

(FREE) Game sprites | Fire 1

Posted by on June 27, 2011


Light fire sprite sheet, ideal for filler or part of a composition. Complete with all frames.


  • 128×128
  • 38 frames
  • Alpha channel, PNG


The goodies:

Neat little fire


Take a look at the legal notesĀ here. Commercial use is prohibited.

More to come…

(FREE) Game sprites | Explosion 1

Posted by on June 16, 2011


The following is a volumetric explosion sprite sheet, one of many left over from past work. You may use them for private or freeware (open source only) projects. Commercial use is prohibited, please contact me regarding licensing or custom work.


There are 38 frames. Each frame is 128×128 and the complete sheet contains an alpha channel, the grid is centered but it hasn’t been packed; as you can see there’s a lot of wasted space. This is however a “sane” way of sharing the sprites, otherwise I would have to provide my own format specifications for the metadata, packer, etc.

This way you can split them and pack them however you want into whatever format you wish. These are however quite usable in their current form.

The goodies:

A simple volumetric explosion

Volumetric explosion sprite sheet

A simple volumetric explosion, corrected levels, saturation, etc.



The corrected version was not exactly proofed, there are a few artifacts due to the processing, however if you’re going to use any sort of scaling filter these shouldn’t be a problem.

As you probably noticed the particles were rendered using a black background, mostly because of the high amounts of smoke involved; white or neutral would’ve been problematic.


It’s no secret that these are leftovers, but they’re perfectly good sprites — they just didn’t make it due to time constraints.

I cannot discuss which title they were meant for though, but I can tell you there’s more of them.

The actual image data contains a disclaimer, it’s hidden by the alpha channel. I mention this because I take it seriously, you may not profit from my work unless “I” profit from your work (It’s only fair right?).

Other than that feel free to use them, even as place-holders. And of course, if you’d like to share some of your handy work, feel free to contact me.

I’ll probably post more freebies throughout the week.


Spaceship Generator!

Posted by on June 10, 2010

I’ve been working on implementing a content generator and mutator, this particular version was based on the Pixel Spaceships work. This was indeed my first goal.

One Iteration based on a base pattern gives us many ships to choose from.

The next logical step is to start separating the various parts of the code and begin to implement various means of generating content, adding noise based on a map/pattern as well as being able to mix different patterns to change the outcome. Another step in the process is to allow the use of arbitrarily sized patterns.

With just a few modifications to the base pattern we can generate all kinds of content, we then choose the one we like the most and select it’s pattern as the new base design for future mutations. The possibilities are endless!

Generating procedural content is nothing new, but it sure is exciting! — And it’s always a challenge to optimize and evolve this type of code.

Hopefully I’ll come up with something usable in the near future.

Animation lib

Posted by on August 6, 2009

Dependent on the time-lapse lib, the animation code provides you with several count methods to manipulate your animations in an easy and comprehensible way.

If you add a sprite atlas library (I’ll share later) you’ll be able to manipulate sprites with animation in quite a flexible way without too much hassle.

The idea is to encapsulate the animation functionality in such a way that it makes it easy to work with. You have the ability to start, stop, pause, change speed, etc. You can create animations that range from any frame to any frame and that can animate in many ways such as sequential (loop), play-once and ping-pong (back and forth, or rather the inverse). By making use of the time-lapse library we can easily create time-based animation.