I'm implementing a simple tile-based game which incorporates time based movement.
My code that is responsible for movement and collision detection is
private function onEnterFrame(event:Event):void
{
if (waiting && game.movingBreakers <= 0)
endLevel();
var interval:int = getTimer() - oldTime;
oldTime += interval;
var totalBreakers:uint = breakers.length;
if (totalBreakers)
{
for each (var breaker:Breaker in breakers)
{
if (!breaker.moving)
continue;
switch (breaker.direction)
{
case TOP:
breaker.y -= SPEED * interval;
break;
case BOTTOM:
breaker.y += SPEED * interval;
break;
case LEFT:
breaker.x -= SPEED * interval;
break;
case RIGHT:
breaker.x += SPEED * interval;
break;
}
checkCollisions(breaker);
}
}
}
The issue I faced recently is that for some irrelevant reason with the game, there was a heavy cpu load on my computer. As a result, the frames of the game were updated on a later time, but the sprites (breakers) were at the right position as their movement based on time. However, some collisions were failed due to the fact that the sprites moved at a further position because of the greater time difference between the last two frames. Hence, my question is how can someone solve this collision detection issue in time based movement?