Javascript Game Loop and RequestAnimationFrameCallback

279 views
Skip to first unread message

Jake Frederick

unread,
Nov 15, 2013, 11:39:28 PM11/15/13
to haxe...@googlegroups.com
I'm trying to get a basic enter_frame style game loop going in Javascript. In non Haxe JS I've done this before using requestAnimationFrame and some browser checking (http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/). I noticed that Haxe has a RequestAnimationFrameCallback type, which the requestAnimationFrame function requires as an argument; how exactly is this supposed to work? How would I type the callback function as RequestAnimationFrameCallback?

Justin L Mills

unread,
Nov 16, 2013, 12:16:50 AM11/16/13
to haxe...@googlegroups.com
I made this awhile ago it seems to work as well as a Timer for running the render loop of my zebra animation. Although only checked in my generic css3 enterframe class not an actual example of it's use but should be obvious.

https://github.com/Justinfront/divtastic3/blob/master/src/core/CSSenterFrame.hx

No idea if this is good practice?

Best Justin


On 16/11/2013 04:39, Jake Frederick wrote:
I'm trying to get a basic enter_frame style game loop going in Javascript. In non Haxe JS I've done this before using requestAnimationFrame and some browser checking (http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/). I noticed that Haxe has a RequestAnimationFrameCallback type, which the requestAnimationFrame function requires as an argument; how exactly is this supposed to work? How would I type the callback function as RequestAnimationFrameCallback?
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.

Andy Li

unread,
Nov 16, 2013, 12:25:43 AM11/16/13
to haxe...@googlegroups.com
Read the source ;)
RequestAnimationFrameCallback is just a typedef of Float -> Bool, i.e. any function that accept Float and returns Bool.

The js.html.* packages in haxe contains the same HTML API of JS's (together with a few extra convenient methods). So you may use the same API as you would in JS.

Cheers,
Andy


On Sat, Nov 16, 2013 at 12:39 PM, Jake Frederick <jfreder...@gmail.com> wrote:
I'm trying to get a basic enter_frame style game loop going in Javascript. In non Haxe JS I've done this before using requestAnimationFrame and some browser checking (http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/). I noticed that Haxe has a RequestAnimationFrameCallback type, which the requestAnimationFrame function requires as an argument; how exactly is this supposed to work? How would I type the callback function as RequestAnimationFrameCallback?

--

Jake Frederick

unread,
Nov 20, 2013, 4:18:51 PM11/20/13
to haxe...@googlegroups.com
Thanks JLM, that's basically what I was going for I just didn't realize that the callback is technically supposed to return a boolean (vanilla javascript's looseness lets you get away with a lot, one reason I'm glad to be working with Haxe!)
Reply all
Reply to author
Forward
0 new messages