window.performance

One of the latest release of Chrome broke the code of my HTML5 porting of Space Invaders.
Suddenly, the game was lacking few animations (background starts, for instance, or aliens moving in the main game screen).

The problem was due to the implementation of the high resolution timer draft: a new sub-millisecond accurate timestamp (a number of milliseconds accurate to a thousandth of a millisecond, since the page was opened). And, of course, to the way I use the timestamp callback input parameter in “requestAnimationFrame”.

A small “polyfill” solved the problem:

Well, not completely, I suppose. The behavior of “window.performance” seems to be related to the OS the browser is running in.

By the way it is available in Chrome stable, Firefox 15+, and IE10.

I also updated the cross browser implementation of “requestAnimationFrame”, using the polyfill described by Paul Irish.

code

references

Leave a Reply

Your email address will not be published. Required fields are marked *