Posts Tagged ‘actionscript’

ActionScript Animation

Posted in Programming on June 10th, 2009 by Jamie – Be the first to comment

Kosal had a problem pausing between tweens. We went through several revisions.

First I suggesting defining the tween properties via array and using anonymous functions passed to the setTimeout function.

We found out anonymous functions were a no-go in his version of ActionScript. Then, I suggested using globals, which resulted in the following code:

// globals

var g_mc,
	g_a,
	g_b,
	g_c;

function animate () {
	var arr = [
			// mc, slideto vars, timeout
			[ car, 200, 100, 1, 10 ],
			[dog, 200, 100, 5, 5]
		];

	var timeout = 0;
	for ( var i = 0; i < arr.length; i ++ ) {
		var item = arr [ i ];
		g_mc = item [ 0 ];
		g_a = item[1];
		g_b = item[2];
		g_c = item[3];

		timeout += item[4]; // total seconds to timeout

		setTimeout ( doSlide, timeout );
	}
}

function doSlide () {
	g_mc.slideTo ( g_a, g_b, g_c );
}
</code>

That had a problem with it, as when I was visualizing the code, I forgot that the globals would always point to the last array. We finally wound up with the code below, which uses recursion instead.
<code lang="actionscript">
// globals

var g_index = 0,
 g_arr = [];

function animate () {
 g_index = 0;
        g_arr = [
 // mc, slideto vars, timeout
 [ car, 200, 100, 1, 10 ],
 [dog, 200, 100, 5, 5]
 ];
        doSlide ();
}

function doSlide () {
        if ( g_index < g_arr.length  ) {
 var item = g_arr [ g_index ];
 g_mc = item [ 0 ];
 g_a = item[1];
 g_b = item[2];
 g_c = item[3];

 g_mc.slideTo ( g_a, g_b, g_c );
        	g_index ++;
         setTimeout ( doSlide, item[4] );
 }
}

Snake

Posted in Programming, Software on July 22nd, 2006 by Jamie – Be the first to comment

Objective

Eat all the red-colored blocks while avoiding the brown-colored barriers.

Controls

[Space] to (re)start the game
[Arrow Key] to move
[Home] to toggle barriers on/off (requires restart of game)

Project page (Source and downloads)

Oiramrd

Posted in Programming, Software on May 22nd, 2005 by Jamie – Be the first to comment

This is a clone of a popular puzzle game.

Objective

Clear all the round pieces by using the falling blocks to match 4-in-a-row!

Controls

[Right Arrow Key] to move right
[Left Arrow Key] to move left
[Down Arrow Key] to descend faster
[Up Arrow Key] to spin piece

Project Page (Source and downloads available)

Video of play:

Tetris

Posted in Programming, Software on February 22nd, 2004 by Jamie – Be the first to comment

Intro

This game needs no introduction!

Instructions

- left, right, down to move
- space to drop
- ctrl, up to rotate
- p to pause
- home to restart

Requested features:

- Next block window

Project page (Source and other downloads available)

Youtube Clip of Gameplay:


Switch to our mobile site