Difference between revisions of "Z-order.as"

From Organic Design wiki
m
(legacy)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{legacy}}
 +
<as>
 +
// Z-order example
 
#include "ball.as"
 
#include "ball.as"
balls = 6;
+
balls = 5;
 
zbuff = [];
 
zbuff = [];
 
angle = 0;
 
angle = 0;
Line 32: Line 35:
  
 
}
 
}
 +
</as>
 +
[[Category:ActionScript]]

Latest revision as of 23:43, 24 September 2013

Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, now this page is for historic record only.

<as> // Z-order example

  1. include "ball.as"

balls = 5; 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++ ) { j = i + 1; colour = (j & 1) ? 0xff0000 : 0; colour |= (j & 2) ? 0x00ff00 : 0; colour |= (j & 4) ? 0x0000ff : 0; zbuff[i] = createSymbol( this, 'ball', 'ball' + i, i, colour ); }

// 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 = 50 + Math.cos(b) * 10; obj._x = width / 2 + Math.sin(b) * width / 3; obj._y = obj.z * 2; zbuff[i].swapDepths(i); }

} </as>