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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...
If you found this post useful, please consider a small donation.
» Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.

5 Responses to “PixelBlitz AS3 game framework”

  1. Richard Davey on February 4th, 2010 1:45 am

    Thanks for the write-up of PixelBlitz, although neither Norm or I have updated it in nearly a year. I would strongly recommend that no-one use the zip download from Google Code, but instead get a fresh version from svn instead. You’ll find a lot more to play with in there. I personally am now using Flixel instead. But I am porting over a number of the features that PixelBlitz had that Flixel lacks. These will all be made available on my blog. Best of both worlds eventually?! :)

  2. jeanpier on February 4th, 2010 3:59 pm

    Nice. I heard of this engine before, but not tested. I’m using Flixel too now ;) I hope Richard port his Bitmap text class to Flixel :>

  3. Coban on February 5th, 2010 5:24 am

    I have been using PixelBlitz for 1 year now, personally I like it more than Flixel. I was wondering why richard stop updating PixelBlitz, now I konw the reason :)

  4. Colin Douch on February 7th, 2010 6:56 am

    Huh this could be very useful for bitmap based games old skool platformers, RPG’s etc

  5. abdu on February 23rd, 2010 2:53 am

    i think pixel engine are more fast than fixel and have variety of utils ,effect,twin,..and more.

Leave a Reply




flash games company