diff --git a/jaws-min.js b/jaws-min.js
index be7d92b..07bb0b2 100644
--- a/jaws-min.js
+++ b/jaws-min.js
@@ -1,86 +1,2 @@
-/* Built at 2013-09-28 21:53:59 +0200 */
-var jaws=function(b){function c(c){b.mouse_x=c.pageX||c.clientX;b.mouse_y=c.pageY||c.clientY;c=b.canvas?b.canvas:b.dom;b.mouse_x-=c.offsetLeft;b.mouse_y-=c.offsetTop}var d,e;b.Parallax=function(){b.log.error("To use jaws.Parallax() you need to include src/extras/parallax.js")};b.SpriteList=function(){b.log.error("To use SpriteList() you need to include src/extras/sprite_list.js")};b.TileMap=function(){b.log.error("To use TileMap() you need to include src/extras/tile_map.js")};b.PixelMap=function(){b.log.error("To use PixelMap() you need to include src/extras/pixel_map.js")};
-b.QuadTree=function(){b.log.error("To use QuadTree() you need to include src/extras/quadtree.js")};b.Audio=function(){b.log.error("To use jaws.Audio() you need to include src/extras/audio.js")};b.title=function(c){if(b.isString(c))return c?d.innerHTML=c:d.innerHTML;b.log.error("jaws.title: Passed in value is not a String.")};b.unpack=function(){"Sprite SpriteList Animation Viewport SpriteSheet Parallax TileMap pressed QuadTree".split(" ").forEach(function(c){window[c]?b.log.warn("jaws.unpack: "+c+
-" already exists in global namespace."):window[c]=b[c]})};b.log=function(c,f){b.isString(c)||(c=JSON.stringify(c));b.log.on&&(e&&b.log.use_log_element&&(e.innerHTML=f?e.innerHTML+(c+"
"):c),console.log&&b.log.use_console&&console.log("JawsJS: ",c))};b.log.on=!0;b.log.use_console=!1;b.log.use_log_element=!0;b.log.warn=function(c){console.warn&&b.log.use_console&&b.log.on?console.warn(c):b.log("[WARNING]: "+JSON.stringify(c),!0)};b.log.error=function(c){console.error&&b.log.use_console&&b.log.on?
-console.error(c):b.log("[ERROR]: "+JSON.stringify(c),!0)};b.log.info=function(c){console.info&&b.log.use_console&&b.log.on?console.info(c):b.log("[INFO]: "+JSON.stringify(c),!0)};b.log.debug=function(c){console.debug&&b.log.use_console&&b.log.on?console.debug(c):b.log("[DEBUG]: "+JSON.stringify(c),!0)};b.log.clear=function(){e&&(e.innerHTML="");console.clear&&console.clear()};b.init=function(k){d=document.getElementsByTagName("title")[0];b.url_parameters=b.getUrlParameters();b.canvas=document.getElementsByTagName("canvas")[0];
-b.canvas||(b.dom=document.getElementById("canvas"));b.canvas?b.context=b.canvas.getContext("2d"):b.dom?b.dom.style.position="relative":(b.canvas=document.createElement("canvas"),b.canvas.width=k.width,b.canvas.height=k.height,b.context=b.canvas.getContext("2d"),document.body.appendChild(b.canvas));e=document.getElementById("jaws-log");b.url_parameters.debug&&!e&&(e=document.createElement("div"),e.id="jaws-log",e.style.cssText="overflow: auto; color: #aaaaaa; width: 300px; height: 150px; margin: 40px auto 0px auto; padding: 5px; border: #444444 1px solid; clear: both; font: 10px verdana; text-align: left;",
-document.body.appendChild(e));b.url_parameters.bust_cache&&(b.log.info("Busting cache when loading assets"),b.assets.bust_cache=!0);b.context&&b.useCrispScaling();b.width=b.canvas?b.canvas.width:b.dom.offsetWidth;b.height=b.canvas?b.canvas.height:b.dom.offsetHeight;b.mouse_x=0;b.mouse_y=0;window.addEventListener("mousemove",c)};b.useCrispScaling=function(){b.context.imageSmoothingEnabled=!1;b.context.webkitImageSmoothingEnabled=!1;b.context.mozImageSmoothingEnabled=!1};b.useSmoothScaling=function(){b.context.imageSmoothingEnabled=
-!0;b.context.webkitImageSmoothingEnabled=!0;b.context.mozImageSmoothingEnabled=!0};b.start=function(c,f,d){function e(c,k){b.log.info(k+"%: "+c,!0);f.loading_screen&&b.assets.displayProgress(k)}function h(c,k){b.log.info(k+"%: Error loading asset "+c,!0)}function p(){b.log.info("all assets loaded",!0);b.switchGameState(c||window,{fps:v},d)}f||(f={});var v=f.fps||60;void 0===f.loading_screen&&(f.loading_screen=!0);f.width||(f.width=500);f.height||(f.height=300);b.init(f);b.isFunction(c)||b.isObject(c)?
-b.isObject(d)||void 0===d?(f.loading_screen&&b.assets.displayProgress(0),b.log.info("setupInput()",!0),b.setupInput(),b.log.info("assets.loadAll()",!0),0c.x||0>c.y||c.x>b.width||c.y>b.height};b.forceInsideCanvas=function(c){c.x&&c.y&&(0>c.x&&(c.x=0),c.x>b.width&&(c.x=b.width),0>c.y&&(c.y=0),c.y>b.height&&(c.y=b.height))};b.getUrlParameters=function(){for(var b=[],c,d=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),
-e=0;ethis.size){this.values.splice(0,1);for(var b=this.value=0;this.values[b];b++)this.value+=this.values[b];this.value/=this.size}this.values.push(c);return this};this.get=function(){return parseInt(this.value)}}window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||
-window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(c,b){window.setTimeout(c,16.666)}}();b.GameLoop=function(d,e,k){if(!(this instanceof arguments.callee))return new arguments.callee(d,e);this.ticks=this.fps=this.tick_duration=0;var f,l=!1,g=!1,h=this,p=new c(20);this.runtime=function(){return this.last_tick-this.first_tick};this.start=function(){b.log.info("Game loop start",!0);this.first_tick=(new Date).getTime();this.current_tick=(new Date).getTime();
-this.last_tick=(new Date).getTime();d.setup&&d.setup(k);step_delay=1E3/e.fps;60==e.fps?requestAnimFrame(this.loop):f=setInterval(this.loop,step_delay)};this.loop=function(){h.current_tick=(new Date).getTime();h.tick_duration=h.current_tick-h.last_tick;h.fps=p.add(1E3/h.tick_duration).get();g||l||(d.update&&d.update(),d.draw&&d.draw(),h.ticks++);60!=e.fps||g||requestAnimFrame(h.loop);h.last_tick=h.current_tick};this.pause=function(){l=!0};this.unpause=function(){l=!1};this.stop=function(){f&&clearInterval(f);
-g=!0}};return b}(jaws||{}),jaws=function(b){b.Rect=function(c,b,e,k){if(!(this instanceof arguments.callee))return new arguments.callee(c,b,e,k);this.x=c;this.y=b;this.width=e;this.height=k;this.right=c+e-0;this.bottom=b+k-0};b.Rect.prototype.getPosition=function(){return[this.x,this.y]};b.Rect.prototype.move=function(c,b){this.x+=c;this.y+=b;this.right+=c;this.bottom+=b;return this};b.Rect.prototype.moveTo=function(c,b){this.x=c;this.y=b;this.right=this.x+this.width-0;this.bottom=this.y+this.height-
-0;return this};b.Rect.prototype.resize=function(c,b){this.width+=c;this.height+=b;this.right=this.x+this.width-0;this.bottom=this.y+this.height-0;return this};b.Rect.prototype.clone=function(){return new b.Rect(this.x,this.y,this.width,this.height)};b.Rect.prototype.shrink=function(c,b){this.x+=c;this.y+=b;this.width-=c+c;this.height-=b+b;this.right=this.x+this.width-0;this.bottom=this.y+this.height-0;return this};b.Rect.prototype.resizeTo=function(b,d){this.width=b;this.height=d;this.right=this.x+
-this.width-0;this.bottom=this.y+this.height-0;return this};b.Rect.prototype.draw=function(){b.context.strokeStyle="red";b.context.strokeRect(this.x-0.5,this.y-0.5,this.width,this.height);return this};b.Rect.prototype.collidePoint=function(b,d){return b>=this.x&&b<=this.right&&d>=this.y&&d<=this.bottom};b.Rect.prototype.collideRect=function(b){return(this.x>=b.x&&this.x<=b.right||b.x>=this.x&&b.x<=this.right)&&(this.y>=b.y&&this.y<=b.bottom||b.y>=this.y&&b.y<=this.bottom)};b.Rect.prototype.toString=
-function(){return"[Rect "+this.x+", "+this.y+", "+this.width+", "+this.height+"]"};return b}(jaws||{});"undefined"!==typeof module&&"exports"in module&&(module.exports=jaws.Rect);
-jaws=function(b){b.Sprite=function(c){if(!(this instanceof arguments.callee))return new arguments.callee(c);this.set(c);this.context=c.context?c.context:b.context};b.Sprite.prototype.default_options={x:0,y:0,alpha:1,angle:0,flipped:!1,anchor_x:0,anchor_y:0,image:null,image_path:null,anchor:null,scale_image:null,damping:1,scale_x:1,scale_y:1,scale:1,color:"#ddd",width:16,height:16,_constructor:null,context:null};b.Sprite.prototype.set=function(c){b.isString(this.image)&&(this.image_path=this.image);
-b.parseOptions(this,c,this.default_options);this.scale&&(this.scale_x=this.scale_y=this.scale);this.image&&this.setImage(this.image);this.scale_image&&this.scaleImage(this.scale_image);this.anchor&&this.setAnchor(this.anchor);if(!this.image&&this.color&&this.width&&this.height){c=document.createElement("canvas");var d=c.getContext("2d");c.width=this.width;c.height=this.height;d.fillStyle=this.color;d.fillRect(0,0,this.width,this.height);this.image=c}this.cacheOffsets();return this};b.Sprite.prototype.clone=
-function(b){b=new (this._constructor?eval(this._constructor):this.constructor)(this.attributes());b._constructor=this._constructor||this.constructor.name;return b};b.Sprite.prototype.setImage=function(c){var d=this;if(b.isDrawable(c))return this.image=c,this.cacheOffsets();b.assets.isLoaded(c)?(this.image=b.assets.get(c),this.cacheOffsets()):(b.log.warn("Image '"+c+"' not preloaded with jaws.assets.add(). Image and a working sprite.rect() will be delayed."),b.assets.load(c,{onload:function(){d.image=
-b.assets.get(c);d.cacheOffsets()}}));return this};b.Sprite.prototype.stepToWhile=function(b,d,e){var k=bthis.frame_duration&&(this.index+=this.frame_direction,this.sum_tick=0);if(this.index>=this.frames.length||0>this.index)this.bounce?(this.frame_direction=-this.frame_direction,this.index+=2*this.frame_direction):this.loop?this.index=0>this.frame_direction?
-this.frames.length-1:0:(this.index-=this.frame_direction,this.on_end&&(this.on_end(),this.on_end=null));return this};b.Animation.prototype.slice=function(c,d){var e={};e.frame_duration=this.frame_duration;e.loop=this.loop;e.bounce=this.bounce;e.on_end=this.on_end;e.frame_direction=this.frame_direction;e.frames=this.frames.slice().slice(c,d);return new b.Animation(e)};b.Animation.prototype.next=function(){this.update();return this.frames[this.index]};b.Animation.prototype.atLastFrame=function(){return this.index==
-this.frames.length-1};b.Animation.prototype.atFirstFrame=function(){return 0==this.index};b.Animation.prototype.currentFrame=function(){return this.frames[this.index]};b.Animation.prototype.toString=function(){return"[Animation, "+this.frames.length+" frames]"};return b}(jaws||{});
-jaws=function(b){b.Viewport=function(c){if(!(this instanceof arguments.callee))return new arguments.callee(c);b.parseOptions(this,c,this.default_options);this.context||(this.context=b.context);this.width||(this.width=b.width);this.height||(this.height=b.height);this.max_x||(this.max_x=b.width);this.max_y||(this.max_y=b.height);var d=this;this.move=function(b,c){b&&(this.x+=b);c&&(this.y+=c);this.verifyPosition()};this.moveTo=function(b,c){void 0!=b&&(this.x=b);void 0!=c&&(this.y=c);this.verifyPosition()};
-this.isOutside=function(b){return!d.isInside(b)};this.isInside=function(b){return b.x>=d.x&&b.x<=d.x+d.width&&b.y>=d.y&&b.y<=d.y+d.height};this.isPartlyInside=function(b){var c=b.rect();return c.right>=d.x&&c.x<=d.x+d.width&&c.bottom>=d.y&&b.y<=d.y+d.height};this.isLeftOf=function(b){return b.xd.x+d.width};this.isAbove=function(b){return b.yd.y+d.height};this.centerAround=function(b){this.x=Math.floor(b.x-this.width/
-2);this.y=Math.floor(b.y-this.height/2);this.verifyPosition()};this.forceInsideVisibleArea=function(c,d){c.xthis.x+b.width-d&&(c.x=this.x+b.width-d);c.ythis.y+b.height-d&&(c.y=this.y+b.height-d)};this.forceInside=function(b,c){b.xthis.max_x-c&&(b.x=this.max_x-c);b.ythis.max_y-c&&(b.y=this.max_y-c)};this.apply=function(b){this.context.save();this.context.translate(-this.x,-this.y);b();this.context.restore()};
-this.draw=function(b){this.apply(function(){b.forEach?b.forEach(d.drawIfPartlyInside):b.draw&&d.drawIfPartlyInside(b)})};this.drawTileMap=function(b){var c=b.atRect({x:this.x,y:this.y,right:this.x+this.width,bottom:this.y+this.height});this.apply(function(){for(var b=0;bthis.x&&(this.x=0);this.x>b&&(this.x=b);b=this.max_y-this.height;0>this.y&&
-(this.y=0);this.y>b&&(this.y=b)};this.moveTo(c.x||0,c.y||0)};b.Viewport.prototype.default_options={context:null,width:null,height:null,max_x:null,max_y:null,x:0,y:0};b.Viewport.prototype.toString=function(){return"[Viewport "+this.x.toFixed(2)+", "+this.y.toFixed(2)+", "+this.width+", "+this.height+"]"};return b}(jaws||{});
-jaws=function(b){function c(b,c){for(var k=function(c){return void 0!==b.isSpriteList?b.at(c):b[c]},f=[],l=Array(c),g=0;g=c.x&&b.x<=c.right||c.x>=b.x&&c.x<=b.right)&&(b.y>=c.y&&b.y<=c.bottom||c.y>=b.y&&c.y<=b.bottom)};b.distanceBetween=function(b,c){return Math.sqrt(Math.pow(b.x-c.x,2)+Math.pow(b.y-c.y,2))};b.collide=function(c,e,k){if(c.rect&&e.forEach)return 0b)b=0;if(void 0===d||0>d)d=0;if(void 0===e||e>this.width)e=this.width;if(void 0===k||k>this.height)k=this.height;if(0==arguments.length)this.data=this.context.getImageData(b,d,e,k).data;else for(var f=this.context.getImageData(b,d,e,k).data,l=0,g=4*this.width,h=4*d*this.width+4*b,p=4*e,v=0;vb.x;e--)if(this.namedColorAt(e,k)==d||void 0===d)return this.namedColorAt(e,k);for(;k>b.y;k--)if(this.namedColorAt(e,k)==d||void 0===d)return this.namedColorAt(e,
-k);return!1};b.PixelMap.prototype.at=function(b,d){b=parseInt(b);d=parseInt(d);0>d&&(d=0);var e=4*d*this.width+4*b;return[this.data[e],this.data[e+1],this.data[e+2],this.data[e+3]]};b.PixelMap.prototype.namedColorAt=function(b,d){for(var e=this.at(b,d),k=0;kk;b.xe&&(f?d=0:k&&(d=3));return d};b.QuadTree.prototype.insert=function(b){if(b.hasOwnProperty("x")||
-b.hasOwnProperty("y")||b.hasOwnProperty("width")||b.hasOwnProperty("height")){if("undefined"!==typeof this.nodes[0]){var d=this.getIndex(b);if(-1!==d){this.nodes[d].insert(b);return}}this.objects.push(b);"undefined"===typeof this.nodes[0]&&this.split();for(b=0;b Place middle of the ship on x/y
+ * .. and a sidescroller would probably use setAnchor("center_bottom") --> Place "feet" at x/y
+ */
+ jaws.Text.prototype.setAnchor = function(value) {
+ var anchors = {
+ top_left: [0, 0],
+ left_top: [0, 0],
+ center_left: [0, 0.5],
+ left_center: [0, 0.5],
+ bottom_left: [0, 1],
+ left_bottom: [0, 1],
+ top_center: [0.5, 0],
+ center_top: [0.5, 0],
+ center_center: [0.5, 0.5],
+ center: [0.5, 0.5],
+ bottom_center: [0.5, 1],
+ center_bottom: [0.5, 1],
+ top_right: [1, 0],
+ right_top: [1, 0],
+ center_right: [1, 0.5],
+ right_center: [1, 0.5],
+ bottom_right: [1, 1],
+ right_bottom: [1, 1]
+ };
+
+ if (anchors.hasOwnProperty(value)) {
+ this.anchor_x = anchors[value][0];
+ this.anchor_y = anchors[value][1];
+ this.cacheOffsets();
+ }
+ return this;
+ };
+
+ /**
+ * Save the object's dimensions
+ * @private
+ * @returns {this} The current function instance
+ */
+ jaws.Text.prototype.cacheOffsets = function() {
+
+ this.left_offset = this.width * this.anchor_x;
+ this.top_offset = this.height * this.anchor_y;
+ this.right_offset = this.width * (1.0 - this.anchor_x);
+ this.bottom_offset = this.height * (1.0 - this.anchor_y);
+
+ if (this.cached_rect)
+ this.cached_rect.resizeTo(this.width, this.height);
+ return this;
+ };
+
+ /**
+ * Returns a jaws.Rect() perfectly surrouning text.
+ * @returns {jaws.Rect}
+ */
+ jaws.Text.prototype.rect = function() {
+ if (!this.cached_rect && this.width)
+ this.cached_rect = new jaws.Rect(this.x, this.y, this.width, this.height);
+ if (this.cached_rect)
+ this.cached_rect.moveTo(this.x - this.left_offset, this.y - this.top_offset);
+ return this.cached_rect;
+ };
+
+ /**
+ * Draw sprite on active canvas or update its DOM-properties
+ * @this {jaws.Text}
+ * @returns {this} The current function instance
+ */
+ jaws.Text.prototype.draw = function() {
+ this.context.save();
+ if (this.angle !== 0) {
+ this.context.rotate(this.angle * Math.PI / 180);
+ }
+ this.context.globalAlpha = this.alpha;
+ this.context.translate(-this.left_offset, -this.top_offset); // Needs to be separate from above translate call cause of flipped
+ this.context.fillStyle = this.color;
+ this.context.font = this.style + " " + this.fontSize + "px " + this.fontFace;
+ this.context.textBaseline = this.textBaseline;
+ this.context.textAlign = this.textAlign;
+ if (this.shadowColor)
+ this.context.shadowColor = this.shadowColor;
+ if (this.shadowBlur)
+ this.context.shadowBlur = this.shadowBlur;
+ if (this.shadowOffsetX)
+ this.context.shadowOffsetX = this.shadowOffsetX;
+ if (this.shadowOffsetY)
+ this.context.shadowOffsetY = this.shadowOffsetY;
+ var oldY = this.y;
+ var oldX = this.x;
+ if (this.wordWrap)
+ {
+ var words = this.text.split(' ');
+ var nextLine = '';
+
+ for (var n = 0; n < words.length; n++)
+ {
+ var testLine = nextLine + words[n] + ' ';
+ var measurement = this.context.measureText(testLine);
+ if (this.y < oldY + this.height)
+ {
+ if (measurement.width > this.width)
+ {
+ this.context.fillText(nextLine, this.x, this.y);
+ nextLine = words[n] + ' ';
+ this.y += this.fontSize;
+ }
+ else {
+ nextLine = testLine;
+ }
+ this.context.fillText(nextLine, this.x, this.y);
+ }
+ }
+ }
+ else
+ {
+ if (this.context.measureText(this.text).width < this.width)
+ {
+ this.context.fillText(this.text, this.x, this.y);
+ }
+ else
+ {
+ var words = this.text.split(' ');
+ var nextLine = ' ';
+ for (var n = 0; n < words.length; n++)
+ {
+ var testLine = nextLine + words[n] + ' ';
+ if (this.context.measureText(testLine).width < Math.abs(this.width - this.x))
+ {
+ this.context.fillText(testLine, this.x, this.y);
+ nextLine = words[n] + ' ';
+ nextLine = testLine;
+ }
+ }
+ }
+ }
+ this.y = oldY;
+ this.x = oldX;
+ this.context.restore();
+ return this;
+ };
+
+ /**
+ * Returns sprite as a canvas context.
+ * (For certain browsers, a canvas context is faster to work with then a pure image.)
+ * @public
+ * @this {jaws.Text}
+ */
+ jaws.Text.prototype.asCanvasContext = function() {
+ var canvas = document.createElement("canvas");
+ canvas.width = this.width;
+ canvas.height = this.height;
+
+ var context = canvas.getContext("2d");
+ context.mozImageSmoothingEnabled = jaws.context.mozImageSmoothingEnabled;
+
+ this.context.fillStyle = this.color;
+ this.context.font = this.style + this.fontSize + "px " + this.fontFace;
+ this.context.textBaseline = this.textBaseline;
+ this.context.textAlign = this.textAlign;
+ if (this.shadowColor)
+ this.context.shadowColor = this.shadowColor;
+ if (this.shadowBlur)
+ this.context.shadowBlur = this.shadowBlur;
+ if (this.shadowOffsetX)
+ this.context.shadowOffsetX = this.shadowOffsetX;
+ if (this.shadowOffsetY)
+ this.context.shadowOffsetY = this.shadowOffsetY;
+ var oldY = this.y;
+ var oldX = this.x;
+ if (this.wordWrap)
+ {
+ var words = this.text.split(' ');
+ var nextLine = '';
+
+ for (var n = 0; n < words.length; n++)
+ {
+ var testLine = nextLine + words[n] + ' ';
+ var measurement = this.context.measureText(testLine);
+ if (this.y < oldY + this.height)
+ {
+ if (measurement.width > this.width)
+ {
+ this.context.fillText(nextLine, this.x, this.y);
+ nextLine = words[n] + ' ';
+ this.y += this.fontSize;
+ }
+ else {
+ nextLine = testLine;
+ }
+ this.context.fillText(nextLine, this.x, this.y);
+ }
+ }
+ }
+ else
+ {
+ if (this.context.measureText(this.text).width < this.width)
+ {
+ this.context.fillText(this.text, this.x, this.y);
+ }
+ else
+ {
+ var words = this.text.split(' ');
+ var nextLine = ' ';
+ for (var n = 0; n < words.length; n++)
+ {
+ var testLine = nextLine + words[n] + ' ';
+ if (this.context.measureText(testLine).width < Math.abs(this.width - this.x))
+ {
+ this.context.fillText(testLine, this.x, this.y);
+ nextLine = words[n] + ' ';
+ nextLine = testLine;
+ }
+ }
+ }
+ }
+ this.y = oldY;
+ this.x = oldX;
+ return context;
+ };
+
+ /**
+ * Returns text as a canvas
+ * @this {jaws.Text}
+ */
+ jaws.Text.prototype.asCanvas = function() {
+ var canvas = document.createElement("canvas");
+ canvas.width = this.width;
+ canvas.height = this.height;
+
+ var context = canvas.getContext("2d");
+ context.mozImageSmoothingEnabled = jaws.context.mozImageSmoothingEnabled;
+
+ this.context.fillStyle = this.color;
+ this.context.font = this.style + this.fontSize + "px " + this.fontFace;
+ this.context.textBaseline = this.textBaseline;
+ this.context.textAlign = this.textAlign;
+ if (this.shadowColor)
+ this.context.shadowColor = this.shadowColor;
+ if (this.shadowBlur)
+ this.context.shadowBlur = this.shadowBlur;
+ if (this.shadowOffsetX)
+ this.context.shadowOffsetX = this.shadowOffsetX;
+ if (this.shadowOffsetY)
+ this.context.shadowOffsetY = this.shadowOffsetY;
+ var oldY = this.y;
+ var oldX = this.x;
+ if (this.wordWrap)
+ {
+ var words = this.text.split(' ');
+ var nextLine = '';
+
+ for (var n = 0; n < words.length; n++)
+ {
+ var testLine = nextLine + words[n] + ' ';
+ var measurement = context.measureText(testLine);
+ if (this.y < oldY + this.height)
+ {
+ if (measurement.width > this.width)
+ {
+ context.fillText(nextLine, this.x, this.y);
+ nextLine = words[n] + ' ';
+ this.y += this.fontSize;
+ }
+ else {
+ nextLine = testLine;
+ }
+ context.fillText(nextLine, this.x, this.y);
+ }
+ }
+ }
+ else
+ {
+ if (context.measureText(this.text).width < this.width)
+ {
+ this.context.fillText(this.text, this.x, this.y);
+ }
+ else
+ {
+ var words = this.text.split(' ');
+ var nextLine = ' ';
+ for (var n = 0; n < words.length; n++)
+ {
+ var testLine = nextLine + words[n] + ' ';
+ if (context.measureText(testLine).width < Math.abs(this.width - this.x))
+ {
+ context.fillText(testLine, this.x, this.y);
+ nextLine = words[n] + ' ';
+ nextLine = testLine;
+ }
+ }
+ }
+ }
+ this.y = oldY;
+ this.x = oldX;
+ return canvas;
+ };
+
+ /**
+ * Returns Text's properties as a String
+ * @returns {string}
+ */
+ jaws.Text.prototype.toString = function() {
+ return "[Text " + this.x.toFixed(2) + ", " + this.y.toFixed(2) + ", " + this.width + ", " + this.height + "]";
+ };
+
+ /**
+ * Returns Text's properties as a pure object
+ * @returns {object}
+ */
+ jaws.Text.prototype.attributes = function() {
+ var object = this.options; // Start with all creation time properties
+ object["_constructor"] = this._constructor || "jaws.Text";
+ object["x"] = parseFloat(this.x.toFixed(2));
+ object["y"] = parseFloat(this.y.toFixed(2));
+ object["text"] = this.text;
+ object["alpha"] = this.alpha;
+ object["angle"] = parseFloat(this.angle.toFixed(2));
+ object["anchor_x"] = this.anchor_x;
+ object["anchor_y"] = this.anchor_y;
+ object["style"] = this.style;
+ object["fontSize"] = this.fontSize;
+ object["fontFace"] = this.fontFace;
+ object["color"] = this.color;
+ object["textAlign"] = this.textAlign;
+ object["textBaseline"] = this.textBaseline;
+ object["wordWrap"] = this.wordWrap;
+ object["width"] = this.width;
+ object["height"] = this.height;
+ return object;
+ };
+
+ /**
+ * Returns a JSON-string representing the properties of the Text.
+ * @returns {string}
+ */
+ jaws.Text.prototype.toJSON = function() {
+ return JSON.stringify(this.attributes());
+ };
+
+ return jaws;
+})(jaws || {});
+
+// Support CommonJS require()
+if (typeof module !== "undefined" && ('exports' in module)) {
+ module.exports = jaws.Text;
+}
/*
* @class jaws.QuadTree
* @property {jaws.Rect} bounds Rect(x,y,width,height) defining bounds of tree