Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by phil

Hi,

Animating an image using the accelerometer is much slower on Ejecta than on a standard UIWebView. Can anybody confirm this, or tell me what I'm doing wrong on this basic code https://gist.github.com/3809646 ?

Thanks,

Phil

1 decade ago by dominic

I get the full 60fps with lots of headroom on my iPhone4s.

In case it isn't clear: Ejecta caps the framerate at 60fps, because that's the iPhone's and iPad's display refresh rate. Generating more than 60 frames per second wouldn't make much sense because they would never get presented.

If you want to have framerate independent animations, measure the time that went by since the last frame was drawn and multiply your velocities with it.

var timeLast = Date.now();

var draw = function() {
	var timeCurrent = Date.now();

	// time since last frame in seconds
	var tick = (timeLast - timeCurrent)/1000; 
	var timeLast = timeCurrent;


	// Move ball with 100px per second, regardless of framerate
	ball.x += 100 * tick;
}
Page 1 of 1
« first « previous next › last »