Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var rendering = false;
- var waiting_for_data = true;
- var data_update = false;
- socket.on('update', function(data){
- if(rendering)console.log("rendering");
- data_update = true;
- game_data = data;
- data_update = false;
- if(waiting_for_data){
- waiting_for_data = false;
- render();
- }
- });
- window.requestAnimFrame = (function(){
- return window.requestAnimationFrame ||
- window.webkitRequestAnimationFrame ||
- window.mozRequestAnimationFrame ||
- window.oRequestAnimationFrame ||
- window.msRequestAnimationFrame ||
- function(/* function */ callback, /* DOMElement */ element){
- window.setTimeout(callback, 1000 / 60);
- };
- })();
- function render(){
- while(data_update){
- console.log("waiting" + data_update);
- }
- if(game_data == null )console.log(game_data);
- rendering = true;
- //mapa.draw(context, game_data.player_position);
- renderer.draw(game_data);
- rendering = false;
- window.requestAnimFrame(render);
- }
- }
Add Comment
Please, Sign In to add comment