Use requestAnimFrame for mainloop.