Hi everyone !
Well, I spent several hours trying to optimize this - tried functions, arrays, just about anything I could think of or look up - but seems to be a dilemma here. For a game I'm working on, I create 29 rows (26 columns) of dots, for a total of 754. The characters will move by tracking horizontal and vertical lines, each line being a separate mc, named h1 to h21, v1 to v20 so I can use hitTest on them.
Thing is, I only wanted the dots to appear on the tracks, so I use hitTest - and so if a dot isn't "in contact" with a horizontal line, for example, then it is removed. And this coding works fine, I end up with dots appearing only on the tracks, all others are now gone via removeMovieClip .. but the problem is I am using a very long conditonal statement here that will eventually contain almost 40 &&'s lol once I add the vertical stuff. Of course I tried loops, nested loops, arrays, really creative functions lol, but nothing works. I almost can't believe it.
On the surface, the solution may look simple, but look very closely. If you use a nested loop, so that h1,h2, etc is now ["h"+j], then what happens is that all dots that don't meet the first logical NOT conditon are gone, which is about over 90% of them, and that's that, no more dots to work with and place on the other tracks. It seems to be all or nothing . Guess this is more of a puzzle than a problem. But it would sure be nice to optimize that big condtional statement. Thanks in advance to everyone.
x = 0;
y = 0;
for(i=1;i<755;i++) {
attachMovie("dot", "dot"+i,i);
_root["dot"+i]._x = x*17.5+28;
_root["dot"+i]._y = y*17.5+27.4;
x++;
if (x > 25) {
x = 0;
y++; }
var z = _root["dot"+i];
var m = _root.block;
if(!z.hitTest(m.h1) && !z.hitTest(m.h2) && !z.hitTest(m.h3) &&
!z.hitTest(m.h4) && !z.hitTest(m.h5) && !z.hitTest(m.h6) &&
!z.hitTest(m.h7) && !z.hitTest(m.h12) && !z.hitTest(m.h13) &&
!z.hitTest(m.h14) && !z.hitTest(m.h15) && !z.hitTest(m.h16) &&
!z.hitTest(m.h17) && !z.hitTest(m.h18) && !z.hitTest(m.h19) &&
!z.hitTest(m.h20) && !z.hitTest(m.h21)){removeMovieClip(z);};
} SEE WHAT I MEAN?? that's one whopper of a conditonal statement - and I did't include the vertical stuff yet - jeepers! There's just gotta be a way to do something about this. Hope some of you flash wizards out there can put me on the right track - much appreciated. I want to Learn !!
Well, I spent several hours trying to optimize this - tried functions, arrays, just about anything I could think of or look up - but seems to be a dilemma here. For a game I'm working on, I create 29 rows (26 columns) of dots, for a total of 754. The characters will move by tracking horizontal and vertical lines, each line being a separate mc, named h1 to h21, v1 to v20 so I can use hitTest on them.
Thing is, I only wanted the dots to appear on the tracks, so I use hitTest - and so if a dot isn't "in contact" with a horizontal line, for example, then it is removed. And this coding works fine, I end up with dots appearing only on the tracks, all others are now gone via removeMovieClip .. but the problem is I am using a very long conditonal statement here that will eventually contain almost 40 &&'s lol once I add the vertical stuff. Of course I tried loops, nested loops, arrays, really creative functions lol, but nothing works. I almost can't believe it.
On the surface, the solution may look simple, but look very closely. If you use a nested loop, so that h1,h2, etc is now ["h"+j], then what happens is that all dots that don't meet the first logical NOT conditon are gone, which is about over 90% of them, and that's that, no more dots to work with and place on the other tracks. It seems to be all or nothing . Guess this is more of a puzzle than a problem. But it would sure be nice to optimize that big condtional statement. Thanks in advance to everyone.
x = 0;
y = 0;
for(i=1;i<755;i++) {
attachMovie("dot", "dot"+i,i);
_root["dot"+i]._x = x*17.5+28;
_root["dot"+i]._y = y*17.5+27.4;
x++;
if (x > 25) {
x = 0;
y++; }
var z = _root["dot"+i];
var m = _root.block;
if(!z.hitTest(m.h1) && !z.hitTest(m.h2) && !z.hitTest(m.h3) &&
!z.hitTest(m.h4) && !z.hitTest(m.h5) && !z.hitTest(m.h6) &&
!z.hitTest(m.h7) && !z.hitTest(m.h12) && !z.hitTest(m.h13) &&
!z.hitTest(m.h14) && !z.hitTest(m.h15) && !z.hitTest(m.h16) &&
!z.hitTest(m.h17) && !z.hitTest(m.h18) && !z.hitTest(m.h19) &&
!z.hitTest(m.h20) && !z.hitTest(m.h21)){removeMovieClip(z);};
} SEE WHAT I MEAN?? that's one whopper of a conditonal statement - and I did't include the vertical stuff yet - jeepers! There's just gotta be a way to do something about this. Hope some of you flash wizards out there can put me on the right track - much appreciated. I want to Learn !!