Nicholas C. Zakas![]()
Game programming using canvas, or even older DOM elements, is complex because it's difficult to precisely time when animations should occur. Firefox added an experimental API for better-performing animations, and WebKit soon copied it. The AnimLoop makes it easy to use the best-performing implementation of an animation loop so you can focus on creating games or other experiences that require frequent animation. In browsers that support the new APIs, the framerate is automatically throttled; for all others, it's fixed at a max of 60 fps.
The technique used in this module is based on this blog post:
http://nokarma.org/2010/02/02/javascript-game-development-the-game-loop/
<script src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script>YUI({
//Last Gallery Build of this module
gallery: 'gallery-2011.02.09-21-32'
}).use('gallery-animloop', function(Y) {
Y.AnimLoop.on("beforedraw", function(){
//do your animation processing here
});
//start the loop
Y.AnimLoop.start();
//stop the loop, you can always call start() again later
Y.AnimLoop.stop();
});| Subject | Author | Date |
|---|---|---|
| Useful code for this lib? | Andrew Wooldridge | 02/23/11 |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info