Intel sponsors gamedev.net search:   
Tesseract's Game Development JournalBy Tesseract      

How I Work
Preferred Language
Actionscript 3
Development Environment
Notepad++ for coding
Flex 3 SDK for compiling
Graphics
The GIMP, among others

See my personal weblog

Completed (and published) Flash Game Projects:
Games
TriGavoid
Tutorials
Creating Textures with Perlin Noise
Simple Trigonometry and Curves Tutorial



Wednesday, September 19, 2007
As per my previous post, Here is the fire animation.

This experiment came from the need at work to create a looping fire animation for a project, which was extremely configurable and could eventually be turned into a series of bitmaps for use in a non-web installation.

Comments: 0 - Leave a Comment

Link



Tuesday, September 18, 2007
I don't know if I will ever use it for anything, but I figured out a way to do a looping fire animation in AS3 using the blur filter. Not as realistic as, well, as real fire, but very configurable, and a simple way to create relatively controllable animations. I will put up an example when I get home from work. In the meantime, here is the code:
/*	save this file as SpecialEffect.as	*/

package {
	import flash.display.Sprite;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	[SWF(backgroundColor="0xff0000",width="800",height="200",frameRate="16")]
	public class SpecialEffect extends Sprite {
		private var strobeLayer:Shape;
		private var strobes:Array;
		private var numDots:Number = 100;
		private var stepSizeX:Number;
		private var stepSizeY:Number;
		private var colors:Array;
		private var totalAnimationFrames:Number = 32;
		public function SpecialEffect() {
			strobes = [];
			colors = [0xff9900,0xff6600,0xcc0000];
		//	colors = [0x00ff00,0xffff00,0x0000ff];
		//	colors = [0xcccccc,0x999999,0x666666,0x333333];
			addEventListener(Event.ENTER_FRAME,init);
		}
		
		private function init(e:Event):void {
			if(!stage) return;
			removeEventListener(Event.ENTER_FRAME,init);
			stepSizeX = stage.stageWidth/totalAnimationFrames;
			stepSizeY = (stage.stageHeight+50)/totalAnimationFrames;
			for(var i:Number=0;i<numDots;i++) {
				var f:Number = (i%colors.length)
				strobes[i] = new Shape();
				strobes[i].graphics.beginFill(colors[f]);
				strobes[i].graphics.drawCircle(0,0,Math.round(Math.random()*50)+50);
				strobes[i].graphics.endFill();
				strobes[i].x = Math.round(Math.random()*stage.stageWidth);
				strobes[i].y = Math.round(Math.random()*stage.stageHeight)+50;
				strobes[i].scaleX = strobes[i].scaleY = strobes[i].y/stage.stageHeight;
				addChild(strobes[i]);
			}
			filters = [new BlurFilter(32,32,2)];
			addEventListener(Event.ENTER_FRAME,strobe);
		}
		
		private function strobe(e:Event):void {
			for(var i:Number = 0;i<strobes.length;i++) {
			/*
				if(i%2==0) {
					strobes[i].y -= stepSizeY;
					if(strobes[i].y < 0) strobes[i].y = stage.stageHeight;
				} else {
					strobes[i].x += stepSizeX;
					if(strobes[i].x > stage.stageWidth) strobes[i].x -= stage.stageWidth;
				}
			*/
				strobes[i].y -= stepSizeY;
				if(strobes[i].y < 0) strobes[i].y = stage.stageHeight+50;
				strobes[i].scaleX = strobes[i].scaleY = strobes[i].y/stage.stageHeight;
			}
		}
	}
}



Comments: 0 - Leave a Comment

Link



Tuesday, September 11, 2007
Well, summer is winding down and I am slowly moving my brain back inside, out of the sun and toward the computer.

I figured out a couple of things today at work, and the applied the results to the Parallax Sprite project: Now I have a scrolling background.

The code for it was, after all is said and done, pretty simple. Once I figured out how some of the Actionscript worked, everything else fell into place.

package {
	import flash.display.*;
	import flash.events.*
	import flash.net.URLRequest;
	import flash.geom.*;
	[SWF(backgroundColor="0x000000",width="640",height="480",frameRate="50")]
	public class World extends Sprite {
		private var sprites:Array = [];
		private var totalSprites:Number = 5;
		private var maxHeight:Number = 0;
		public var centerX:Number;
		public var centerY:Number;
		
		private var dX:Number;
		private var dY:Number;
		private var dOff:Number;
		private var velocity:Number;
		private var theta:Number;
		private var mat:Matrix;
		private var bmp:BitmapData;
		private var _loader:Loader = new Loader();
		public var spriteBitmap:BitmapData;
		
		[Embed("ground.jpg")]
		private var Ground:Class;
		
		public function World() {
			addEventListener(Event.ENTER_FRAME,grabBitmap);
		}
		
		private function grabBitmap(e:Event):void {
			if(!stage) return;
			removeEventListener(Event.ENTER_FRAME,grabBitmap);
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,init);
			_loader.load(new URLRequest("brick_pattern_1.gif"));
			
		}
		
		private function init(e:Event):void {
			_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,init);
			var _i:Bitmap = Bitmap(_loader.content);
			spriteBitmap = _i.bitmapData;
			mat = new Matrix();
			centerX = stage.stageWidth/2;
			centerY = stage.stageHeight/2;
			
			var g:Bitmap = new Ground();
			bmp = new BitmapData(g.width,g.height);
			
			bmp.draw(g);
			graphics.beginBitmapFill(bmp,mat,true,false);
			graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
			graphics.endFill();
			
			graphics.beginFill(0xff0000,100);
			graphics.drawCircle(centerX,centerY,2.5);
			graphics.endFill();
			
			for(var i:Number = 0;i<totalSprites;i++) {
				sprites[i] = new ParallaxSprite(
					this,
					Math.round(Math.random()*stage.stageWidth*2/120)*120,
					Math.round(Math.random()*stage.stageHeight*2/120)*120
				);
				sprites[i].cacheAsBitmap = true;
				maxHeight = Math.max(sprites[i].layers,maxHeight);
			}
			
			for(i = 0;i<maxHeight;i++) {
				for(var j:Number = 0;j<totalSprites;j++) {
					if(sprites[j].spriteLayers[i]) {
						addChild(sprites[j].spriteLayers[i]);
						sprites[j].spriteLayers[i].cacheAsBitmap = true;
					}
				}
			}
			addEventListener(Event.ENTER_FRAME,moveSprites);
		}
		
		private function moveSprites(e:Event):void {
			dX = centerX - mouseX;
			dY = centerY - mouseY;
			theta = Math.atan2(dY,dX);
			dOff = Math.sqrt(dX*dX+dY*dY);
			velocity = dOff/50;
			/*	begin work on ground layer	*/
			mat.translate(Math.cos(theta)*velocity,Math.sin(theta)*velocity);
			graphics.clear();
			graphics.beginBitmapFill(bmp,mat,true,false);
			graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
			graphics.endFill();
			/*	end work on ground layer	*/
			for(var i:Number = 0;i<totalSprites;i++) {
				sprites[i].x += Math.cos(theta)*velocity;
				sprites[i].y += Math.sin(theta)*velocity;
				if(sprites[i].x < -360) sprites[i].x = stage.stageWidth + 360;
				else if(sprites[i].x > stage.stageWidth+360) sprites[i].x = -360;
				if(sprites[i].y < -360) sprites[i].y = stage.stageHeight + 360;
				else if(sprites[i].y > stage.stageHeight+360) sprites[i].y = -360;
				sprites[i].detectCenter();
			}
			
		}
	}
}


Everything I needed to know happens in the section inside of moveSprites() which is bracketed by comments.

I suppose the next project is to get an avatar of some kind in there walking around in the world. Then collision detection. Then varied terrain. Then monsters. Then combat. Then a story layer. Then...thenthenthen...

Argh.


Comments: 0 - Leave a Comment

Link


All times are ET (US)

 
S
M
T
W
T
F
S
1
2
3
4
5
6
7
8
9
10
12
13
14
15
16
17
20
21
22
23
24
25
26
27
28
29

OPTIONS
Track this Journal

 RSS 

ARCHIVES
November, 2009
March, 2009
January, 2009
November, 2008
October, 2008
September, 2008
August, 2008
July, 2008
February, 2008
December, 2007
November, 2007
October, 2007
September, 2007
July, 2007
June, 2007
March, 2007
February, 2007
January, 2007
December, 2006
August, 2006
July, 2006
June, 2006