Question
How to loop through a range of an array (based on element value)
How to loop through a range of an array (based on element
value)
I'm looping through an array doing some collision detection:
for (var n:int = 0; n<myArray.length; n++){
//do collision detection
trace(myArray.name);
trace(myArray.x);
}
Now I want to do the same thing, but I only want to loop through a subset of the array (since I don't want to waste resources doing collision detection on offscreen objects.
So I want to loop through the section of the array where the attribute X falls into a certain value.
Could someone please help me do that?
My array is sorted by X.
I'm looping through an array doing some collision detection:
for (var n:int = 0; n<myArray.length; n++){
//do collision detection
trace(myArray
trace(myArray
}
Now I want to do the same thing, but I only want to loop through a subset of the array (since I don't want to waste resources doing collision detection on offscreen objects.
So I want to loop through the section of the array where the attribute X falls into a certain value.
Could someone please help me do that?
My array is sorted by X.
