PDA

View Full Version : [AS3] Dynamic Timer based on FPS... ideas?


ICD2k3
09-17-2008, 04:51 PM
Hey guys, so basically I'm making a processor intensive webcam motion detection game. The motion detection is called using a timer at that runs every fraction of a second.

The problem: on slower computers the game slows way down... when I increase the interval wait time it fixes the issue (with slightly less responsive motion detection)... so it seems I need some way to create a dynamic timer that can change it's delay time based on a user's FPS... I already have a script that gets FPS (counter-productively it makes it even slower cause it uses an enterframe).

Any suggestions to this issue would be greatly greatly appreciated.

Bombdogs
09-17-2008, 06:14 PM
Stick the motion detection code in an onEnterFrame event instead. As the frame rate slows your motion detection code gets run fewer times & as it picks up, more times.

If you don't want to run it as many times as once per frame do this sort of thing...

frameCnt = 0;
this.addEventListener(Event.ENTER_FRAME, motionDetect);

function motionDetect(e:Event):void
{
if(frameCnt%4 == 0) {
// motion detect code
}
frameCnt ++;
}

which will run your code every 4 frames.

PMF

ICD2k3
09-17-2008, 07:11 PM
Oh man, can't believe I didn't think of that. works perfectly. Thanks!