Difference between revisions of "Z-order.as"
m |
m |
||
| Line 1: | Line 1: | ||
| + | balls = 6; | ||
| + | zbuff = []; | ||
| + | angle = 0; | ||
| + | arc = 2 * Math.PI / balls; | ||
| + | |||
// Create some balls each of different colours and put in z-buffer | // Create some balls each of different colours and put in z-buffer | ||
| − | |||
| − | |||
for ( i = 0; i < balls; i++ ) { | for ( i = 0; i < balls; i++ ) { | ||
attachMovie( 'ball', 'ball'+i, i ); | attachMovie( 'ball', 'ball'+i, i ); | ||
| Line 20: | Line 23: | ||
// Set ball coordinates, scales and depths for this frame | // Set ball coordinates, scales and depths for this frame | ||
| − | + | angle += 0.05; | |
| − | |||
for ( i = 0; i < balls; i++ ) { | for ( i = 0; i < balls; i++ ) { | ||
obj = _root['ball'+i]; | obj = _root['ball'+i]; | ||
| − | b = | + | b = angle + arc * i; |
| − | obj.z = obj._xscale = obj._yscale = 20+Math.cos(b)*5; | + | obj.z = obj._xscale = obj._yscale = 20 + Math.cos(b) * 5; |
| − | obj._x = width/2 + Math.sin(b) * width/3; | + | obj._x = width / 2 + Math.sin(b) * width / 3; |
| − | obj._y = height/2 + obj.z * 2; | + | obj._y = height / 2 + obj.z * 2; |
zbuff[i].swapDepths(i); | zbuff[i].swapDepths(i); | ||
} | } | ||
} | } | ||
Revision as of 11:34, 20 March 2006
balls = 6; zbuff = []; angle = 0; arc = 2 * Math.PI / balls;
// Create some balls each of different colours and put in z-buffer for ( i = 0; i < balls; i++ ) { attachMovie( 'ball', 'ball'+i, i ); zbuff[i] = _root['ball'+i]; j = i + 1; r = (j & 1) ? 0xff : 0; g = (j & 2) ? 0xff : 0; b = (j & 4) ? 0xff : 0; c = new Color( zbuff[i] ); c.setTransform( { ra:r, ga:g, ba:b } ); }
// Per frame function reduce() {
// Sort the z-buffer by z zbuff.sort( function(a,b) { return a.z > b.z; } );
// Set ball coordinates, scales and depths for this frame angle += 0.05; for ( i = 0; i < balls; i++ ) { obj = _root['ball'+i]; b = angle + arc * i; obj.z = obj._xscale = obj._yscale = 20 + Math.cos(b) * 5; obj._x = width / 2 + Math.sin(b) * width / 3; obj._y = height / 2 + obj.z * 2; zbuff[i].swapDepths(i); }
}



