I have this code within a for condition within a enterframe. So it is running really fast. The thing is to test I put a trace statement with in the first if statement and it traces (as I assume) as many times as there are frames per second. However if I put a trace statements in the if code with the first if it only traces once. This tells me that, that code only runs once. While the first if runs multiple times. Which doesn’t make sense. So my character runs into the wall output panel traces “this updates a lot” constantly while my character is in the wall. The output panel only traces “this updates only once” one time even if I’m in the wall still and the other trace is showing up.
for (var i:int = 0; i < fixedObjects.length; i++)
{
var wallRect:Rectangle = fixedObjects*.getRect(this);
if (wallRect.intersects(newCharRect))
{
wallHit = true;
//////////////////////////////
trace("this updates a lot");
//////////////////////////////
// ball hitting left or right side
if (Math.floor(oldCharRect.right) < Math.floor(wallRect.left))
{
trace("left");
//////////////////////
trace("this updates only once");
/////////////////////
whichSide = "left";
rightMove = false;
break;
}
else if (Math.floor(oldCharRect.left) > Math.floor(wallRect.right))
{
trace("right");
whichSide = "right";
leftMove = false;
break;
}
// ball hitting top or bottom
if (Math.floor(oldCharRect.top) > Math.floor(wallRect.bottom))
{
trace("bottom");
whichSide = "bottom";
upMove = false;
break;
}
else if (Math.floor(oldCharRect.bottom) < Math.floor(wallRect.top))
{
trace("top");
whichSide = "top";
downMove = false;
break;
}
}
}