PixelBlitz AS3 game framework

PixelBlitz Engine is an old game framework for Actionscript3 created by Richard Davey from Photon Storm.

pixelblitz

As said, it’s not that new, there isn’t any documentation or tutorial or even a feature list.

So, you may wonder why should I write about it, considering it’s a bitmap-based framework just like Flixel, which has a better documentation.

Well, the main reason is the blog is mine :) … the second reason is PixelBlitz supports the Flash IDE, and this means you can use the library with Flash, while Flixel only supports Adobe Flex Builder or FlashDevelop.

In the downloadable package you can find at Google Code you can find some examples but they are incomplete… you will only find the .as files, without the .fla.

So I took the most promising example (in my opinion) and created a complete project, with the .fla file and all needed objects (well, just one object, but it’s everything you need to make it work).

This is the script, let the comments guide you through the entire process.

package {

	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.events.Event;
	import flash.events.MouseEvent;

	import com.normsoule.pixelblitz.core.Renderer2D;
	import com.normsoule.pixelblitz.effects.TrailsEffect;
	import com.normsoule.pixelblitz.elements.PixelSprite;
	import com.normsoule.pixelblitz.layers.RenderLayer;

	/**
	 * This example bounces 20 PixelSprites around the stage. Click on a PixelSprite and it will be removed.
	 *
	 * This demonstrates several of the basic ingredients in using the PixelBlitz engine: 
	 *
	 *create the main renderer, 
	 *create a renderLayer and add it to the renderer,
	 *create some PixelSprites and add them to the renderLayer,
	 *create and apply an effect to a layer,
	 *check mouse interaction using the getCollisionPoint method
	 *properly remove PixelSprites and make them available for garbage collection
	 * and lastly call the renderer.render() method to render the PixelClips to the screen
	 */ 
	 
	public class pixelblitz extends Sprite {
		private const stageWidth:int = stage.stageWidth;
		private const stageHeight:int = stage.stageHeight;
		// main renderer
		private var renderer:Renderer2D=new Renderer2D(stageWidth,stageHeight);
		// renderLayer to hold the PixelClips
		private var layer:RenderLayer = new RenderLayer();
		// array to hold a reference to all of the PixelClips
		private var holder:Array = [];
		public function pixelblitz() {
			for (var i:int = 0; i < 20; i++) {
				// create 20 pixelClips
				spawn();
			}
			// add the layer to the renderer
			renderer.addLayer( layer );
			layer.effect = new TrailsEffect();
			stage.addEventListener( Event.ENTER_FRAME, update );
			stage.addEventListener( MouseEvent.MOUSE_DOWN, mouseHandler );
			addChild( renderer );
		}
		private function spawn():void {
			// create a new PixelSprite with the library linked symbol BoxHead
			var ps:PixelSprite = new PixelSprite( new BoxHead() );
			// center on the x axis
			ps.x=stageWidth/2;
			// center on the y axis
			ps.y=stageHeight/2;
			// assign a random x velocity
			ps.vx=Math.random()*12-6;
			// assign a random y velocity
			ps.vy=Math.random()*12-6;
			// add the PixelSprite to the layer
			layer.addItem( ps );
			// store a reference to the PixelSprite in the holder array
			holder.push( ps );
		}
		private function mouseHandler( event:MouseEvent ):void {
			// loop backwards through the holder array to check the top-most clips first
			for (var i:int = holder.length - 1; i > -1; i--) {
				// reference to each PixelSprite
				var ps:PixelSprite=holder[i];
				// check if the current mouse position is within a PixelSprite
				if (ps.getCollisionPoint(new Point(stage.mouseX,stage.mouseY))) {
					// remove the pixelSprite and clear internal data
					ps.dispose();
					// destroy the reference to the PixelSprite to make it available for garbage collection
					holder.splice( i, 1 );
					// break out of the loop to avoid removing more than one per click
					break;
				}
			}
		}
		private function update( event:Event ):void {
			for (var i:int = 0; i < holder.length; i++) {
				// grab a reference to each PixelSprite
				var ps:PixelSprite=holder[i];
				// bounce off of the walls
				if (ps.x+ps.width>stageWidth) {
					ps.x=stageWidth-ps.width;
					ps.vx=- ps.vx;
				} else if ( ps.x < 0 ) {
					ps.x=0;
					ps.vx=- ps.vx;
				}
				if (ps.y+ps.height>stageHeight) {
					ps.y=stageHeight-ps.height;
					ps.vy=- ps.vy;
				} else if ( ps.y < 0 ) {
					ps.y=0;
					ps.vy=- ps.vy;
				}
				// move on the x axis
				ps.x+=ps.vx;
				// move on the y axis
				ps.y+=ps.vy;
			}
			// render everything
			renderer.render();
		}
	}
}

And this is the result:

click on the sprites to make them disappear

Download the source code, library included.

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

215 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stairs
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers