528a0b0b1dc5695c4380e47e084163aa

Is there a simpler way to get xMark and yMark?

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
		public function sortDepth():void {

			var gridItem:GridItem;
			var start:int = 0,
				gridLimit:int = GridArray.girdSize - 1,
				xMark:int = 0, 
				yMark:int = 0,
				cartMin = 0,
				depth:int = 0,
				iterations:int = GridArray.gridSize * 2 - 1;
				for (var i:int = 0; i < iterations; i++) {					
					cartMin = (i > gridLimit) ? i - gridLimit: start;
					yMark = cartMin;
					xMark = (i > gridLimit) ? gridLimit: i;
					while (xMark >= cartMin) {
						gridItem = this.gridItems[yMark][xMark] as GridItem;
						if (gridItem) {
							this.setChildIndex(gridItem, depth);
							depth++;
						}
						xMark--;
						yMark++;
					}
				}
		}

Refactorings

No refactoring yet !

A623216a5d2384489e012478c555d167

Juha Hollanti

August 12, 2008, August 12, 2008 10:28, permalink

No rating. Login to rate!

Umm, i don't know what you're trying to do. Maybe you could explain your snippet of code a bit more? I kind of got the idea that you're trying to do some 3D stuff, right? Am i close or am i just completely off the map?

528a0b0b1dc5695c4380e47e084163aa

ryanmagnon.myopenid.com

August 26, 2008, August 26, 2008 20:35, permalink

No rating. Login to rate!

Yeah, 2D Isometrics, sort of like "Fake 3D".

So if GridArray.gridSize = 3, then this is what I need in the loops:

yM = 0, xM = 0, depth = 0
yM = 0, xM = 1, depth = 1 / yM = 1, xM = 0, depth = 2
yM = 0, xM = 2, depth = 3 / yM = 1, xM = 1, depth = 4 / yM = 2, xM = 0, depth = 5
yM = 1, xM = 2, depth = 6 / yM = 2, xM = 1, depth = 7
yM = 2, xM = 2, depth = 8

I need to get that same pattern no matter what gridSize is though.

528a0b0b1dc5695c4380e47e084163aa

ryanmagnon.myopenid.com

September 2, 2008, September 02, 2008 23:17, permalink

No rating. Login to rate!

K, I'll add another example...

if GridArray.gridSize = 4 then here's the results I need:

yM = 0, xM = 0, depth = 0
yM = 0, xM = 1, depth = 1 / yM = 1, xM = 0, depth = 2
yM = 0, xM = 2, depth = 3 / yM = 1, xM = 1, depth = 4 / yM = 2, xM = 0, depth = 5
yM = 0, xM = 3, depth = 6 / yM = 1, xM = 2, depth = 7 / yM = 2, xM = 1, depth = 8 / yM = 3, xM = 0, depth = 9
yM = 0, xM = 2, depth = 10 / yM = 1, xM = 1, depth = 11 / yM = 2, xM = 0, depth = 12
yM = 1, xM = 2, depth = 13 / yM = 2, xM = 1, depth = 14
yM = 2, xM = 2, depth = 15

I thought there might be a simpler way to get this pattern.

Avatar

Tom Sirgedas

September 23, 2008, September 23, 2008 19:23, permalink

No rating. Login to rate!

loop through x, y and get the depth at (x,y) using the function below

1
function depthAt( x:Number, y:Number, N:Number ):Number { return x+y < N ? (x+y)*(x+y+1)/2 + y : N*N-1-depthAt(N-1-x,N-1-y,N); }

Your refactoring





Format Copy from initial code

or Cancel