How is the ENTER_FRAME event made?

The ENTER_FRAME event is basically what handles openfl’s game loop. It can be useful for updateable instances and I wanna know how it was made.

Its tied into the render loop for our sdl targets. Sdl implements it in that case.

Similarly, for html5 we use the browser api Window.requestAnimationFrame() Window: requestAnimationFrame() method - Web APIs | MDN

The event is created on each frame tick received from each backend implementation and flooded through the display list tree.

There are a few ways to simulate this in haxe like using a while true loop with system breaks. This is a blocking method, though you can leverage multiple threads. Alternatively Haxe provides EventLoop/MainLoop and Timer Apis that relevant here, although accuracy of timing intervals is not always reliable in my experience.

I’m actually making a class for the event loop called “Updatable”. Where do I start?

What are you actually trying to do?

Trying to remove the old event listener ENTER_FRAME and replacing it with a new one that has a fixed delta.
(And the updatable will have a function named start, that starts the game loop. (I’m targeting it with FlxGame btw)

@SomeGuyWhoLovesHaxe You might want to try using the Timer class: haxe.Timer - Haxe 4.3.3 API
It will let you run a function at any millisecond interval.

It’s worth mentioning that Lime overrides haxe.Timer with its own custom implementation. I’ve found that this can prevent haxe.Timer from running faster than the frame rate in an OpenFL app.

That’s what I’ve did

package fv;

class Updatable {
	public static function start():Void {
		haxe.Timer.delay(start, / @:privateAccess Main.framerate));

You can instantiate a movieclip like this and add or remove ENTER_FRAME event.

var mc:MovieClip  = new MovieClip();
mc.addEventListener(Event.ENTER_FRAME, ef ) ;

function ef( e:Event )
trace ( "This function will loop at the set FPS ") ;

To remove :

mc.removeEventListener(Event.ENTER_FRAME, ef ) ;


Ah yes, that’s another solution.