Mya
11-12-2007, 08:58 PM
Hi guys,
I've recently added a function to my game, which checks to see if any element from array A is hitting any of the elements from array B - the function breaks down roughly to:
var arrayA:Array = new Array();
var arrayB:Array = new Array();
var indexA: Number;
var indexB: Number;
for (indexA = 0; indexA < arrayA.length; indexA++) {
for (indexB= 0; indexB < dots.length; arrayB++) {
if (arrayA[indexA].hitTest(arrayB[indexB])) {
trace("success!");
}
}
}
The code works fine, however, ever since putting in this code, my game has begun to slow down considerably after about a minute, even if the function is as simple as a trace...
- the only thing I can think of is that it's to do with the size of the arrays - they both get bigger as the game goes on (one at the rate of about 3 elements per second) plus there are another three arrays besides these two that are increasing similarly - so I guess first of all, does this sound like a likely explanation? If so, can anyone suggest any good methods of controlling the size of arrays?
I've recently added a function to my game, which checks to see if any element from array A is hitting any of the elements from array B - the function breaks down roughly to:
var arrayA:Array = new Array();
var arrayB:Array = new Array();
var indexA: Number;
var indexB: Number;
for (indexA = 0; indexA < arrayA.length; indexA++) {
for (indexB= 0; indexB < dots.length; arrayB++) {
if (arrayA[indexA].hitTest(arrayB[indexB])) {
trace("success!");
}
}
}
The code works fine, however, ever since putting in this code, my game has begun to slow down considerably after about a minute, even if the function is as simple as a trace...
- the only thing I can think of is that it's to do with the size of the arrays - they both get bigger as the game goes on (one at the rate of about 3 elements per second) plus there are another three arrays besides these two that are increasing similarly - so I guess first of all, does this sound like a likely explanation? If so, can anyone suggest any good methods of controlling the size of arrays?