Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't Optimize this :( ! 2

Status
Not open for further replies.

Chris99

Technical User
Jan 11, 2001
18
CA
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(&quot;dot&quot;, &quot;dot&quot;+i,i);
_root[&quot;dot&quot;+i]._x = x*17.5+28;
_root[&quot;dot&quot;+i]._y = y*17.5+27.4;

x++;
if (x > 25) {
x = 0;
y++; }

var z = _root[&quot;dot&quot;+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 :D !!
 
So, if I'm understanding the problem, you need to check for 21 false hitTests? Maybe this appraoch will work as an alternative to the massive condition... You run the test 21 times and then check how many &quot;false&quot; results you get - if all were false you remove the clip.

runningTotal=0;
for(i=1;i<=21;i++){
targetClip=_root[&quot;_root.block&quot;+i];
if(!z.hitTest(targetClip){
runningTotal++;
}
}
if (runningTotal=21){
removeMovieClip(z);
}
 
Just in case... (typo!)

if (runningTotal == 21){
removeMovieClip(z);
}

Regards,
new.gif
 
Thanx a ton Wangbar & Oldnewbie :) much appreciated! Will definitely give this a try tonight and get back to you. :) I want to Learn :D !!
 
Tried it out, didn't quite work out at first, but pointed me in the right direction and the massive condition is now history ;). Thanx again for your help! I want to Learn :D !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top