var createDrawFunction = function() { var functioncalls = [], currenttime = new Date().getTime(); if(dying || temporary) { functioncalls.push(function(ctx) { ctx.save(); }); if(dying) functioncalls.push(function(ctx) { if(life < 0.04) die(); life -= 0.03; ctx.globalAlpha = life; }); if(temporary) functioncalls.push(function(ctx) { ctx.shadowOffsetX = 2;ctx.shadowOffsetY = 1;ctx.shadowBlur = 3;ctx.shadowColor = '#000'; }); } if(animate) functioncalls.push(function(ctx) { movePen();drawPart(ctx); }); else functioncalls.push(function(ctx) { drawWhole(ctx); }); if(dying || temporary) functioncalls.push(function(ctx) { ctx.restore(); }); if(currenttime - time_created < 5000) { functioncalls.push(function(ctx) { ctx.fillText(u_name, xpos+width, ypos+height); }); setTimeout(function() { that.draw = createDrawFunction(); }, 5000 + 10 - (currenttime - time_created));//createDrawFunction(); }, 1000); } return (function(ctx) { for(var i = 0, max = functioncalls.length; i < max; ++i) functioncalls[i](ctx); }); };