forked from wise9/enchant.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enchant.min.js
2 lines (2 loc) · 64.7 KB
/
enchant.min.js
1
2
/* enchant.js v0.6.1 http://enchantjs.com Copyright (c) Ubiquitous Entertainment Inc. Released Under MIT license. */
(function(e,t){typeof Object.defineProperty!="function"&&(Object.defineProperty=function(e,t,n){return"value"in n&&(e[t]=n.value),"get"in n&&e.__defineGetter__(t,n.get),"set"in n&&e.__defineSetter__(t,n.set),e}),typeof Object.defineProperties!="function"&&(Object.defineProperties=function(e,t){for(var n in t)t.hasOwnProperty(n)&&Object.defineProperty(e,n,t[n]);return e}),typeof Object.create!="function"&&(Object.create=function(e,t){function n(){}n.prototype=e;var r=new n;return t!=null&&Object.defineProperties(r,t),r}),typeof Object.getPrototypeOf!="function"&&(Object.getPrototypeOf=function(e){return e.__proto__}),typeof Function.prototype.bind!="function"&&(Function.prototype.bind=function(t){var n=this,r=Array.prototype.slice.call(arguments,1),i=function(){},s=function(){var s=r.concat(Array.prototype.slice.call(arguments));return n.apply(this instanceof i?this:t||e,s)};return i.prototype=n.prototype,s.prototype=new i,s});var n=function(t){t!=null&&(t instanceof Array||(t=Array.prototype.slice.call(arguments)),t=t.filter(function(e){return[e].join()})),function r(n,i){var s=[],o,u;for(var a in n)n.hasOwnProperty(a)&&(typeof n[a]=="function"?e[a]=n[a]:typeof n[a]=="object"&&Object.getPrototypeOf(n[a])===Object.prototype&&(t==null?s.push(a):(o=t.indexOf(i+a),o!==-1&&(s.push(a),t.splice(o,1)))));for(o=0,u=s.length;o<u;o++)r(n[s[o]],i+s[o]+".")}(n,""),e.Game=e.Core;if(t!=null&&t.length)throw new Error("Cannot load module: "+t.join(", "))};e.enchant=n,e.addEventListener("message",function(e,t){try{var r=JSON.parse(e.data);if(r.type==="event")n.Core.instance.dispatchEvent(new n.Event(r.value));else if(r.type==="debug")switch(r.value){case"start":n.Core.instance.start();break;case"pause":n.Core.instance.pause();break;case"resume":n.Core.instance.resume();break;case"tick":n.Core.instance._tick();break;default:}}catch(i){}},!1),n.Class=function(e,t){return n.Class.create(e,t)},n.Class.create=function(e,t){if(e==null)throw new Error("superclass is undefined");if(arguments.length===0)return n.Class.create(Object,t);if(arguments.length===1&&typeof arguments[0]!="function")return n.Class.create(Object,arguments[0]);for(var r in t)t.hasOwnProperty(r)&&(typeof t[r]=="object"&&t[r]!==null&&Object.getPrototypeOf(t[r])===Object.prototype?"enumerable"in t[r]||(t[r].enumerable=!0):t[r]={value:t[r],enumerable:!0,writable:!0});var i=function(){if(!(this instanceof i))return new i;i.prototype.initialize.apply(this,arguments)};i.prototype=Object.create(e.prototype,t),i.prototype.constructor=i,i.prototype.initialize==null&&(i.prototype.initialize=function(){e.apply(this,arguments)});var s=this.getInheritanceTree(e);for(var o=s.length-1;o>=0;o--)if(typeof s[o]._inherited=="function"){s[o]._inherited(i);break}return i},n.Class.getInheritanceTree=function(e){var t=[],n=e,r=n.prototype;while(n!==Object)t.push(n),r=Object.getPrototypeOf(r),n=r.constructor;return t},n.ENV={VENDOR_PREFIX:function(){var e=navigator.userAgent;return e.indexOf("Opera")!==-1?"O":e.indexOf("MSIE")!==-1?"ms":e.indexOf("WebKit")!==-1?"webkit":navigator.product==="Gecko"?"Moz":""}(),TOUCH_ENABLED:function(){var e=document.createElement("div");return e.setAttribute("ontouchstart","return"),typeof e.ontouchstart=="function"}(),RETINA_DISPLAY:function(){if(navigator.userAgent.indexOf("iPhone")!==-1&&e.devicePixelRatio===2){var t=document.querySelector('meta[name="viewport"]');return t==null&&(t=document.createElement("meta"),document.head.appendChild(t)),t.setAttribute("content","width=640"),!0}return!1}(),USE_FLASH_SOUND:function(){var e=navigator.userAgent,t=navigator.vendor||"";return location.href.indexOf("http")===0&&e.indexOf("Mobile")===-1&&t.indexOf("Apple")!==-1}(),USE_DEFAULT_EVENT_TAGS:["input","textarea","select","area"],CANVAS_DRAWING_METHODS:["putImageData","drawImage","drawFocusRing","fill","stroke","clearRect","fillRect","strokeRect","fillText","strokeText"],KEY_BIND_TABLE:{37:"left",38:"up",39:"right",40:"down"},PREVENT_DEFAULT_KEY_CODES:[37,38,39,40,32],SOUND_ENABLED_ON_MOBILE_SAFARI:!1,USE_WEBAUDIO:function(){return location.protocol!=="file:"}(),USE_ANIMATION:!0},n.Event=n.Class.create({initialize:function(e){this.type=e,this.target=null,this.x=0,this.y=0,this.localX=0,this.localY=0},_initPosition:function(e,t){var r=n.Core.instance;this.x=this.localX=(e-r._pageX)/r.scale,this.y=this.localY=(t-r._pageY)/r.scale}}),n.Event.LOAD="load",n.Event.PROGRESS="progress",n.Event.ENTER_FRAME="enterframe",n.Event.EXIT_FRAME="exitframe",n.Event.ENTER="enter",n.Event.EXIT="exit",n.Event.CHILD_ADDED="childadded",n.Event.ADDED="added",n.Event.ADDED_TO_SCENE="addedtoscene",n.Event.CHILD_REMOVED="childremoved",n.Event.REMOVED="removed",n.Event.REMOVED_FROM_SCENE="removedfromscene",n.Event.TOUCH_START="touchstart",n.Event.TOUCH_MOVE="touchmove",n.Event.TOUCH_END="touchend",n.Event.RENDER="render",n.Event.INPUT_START="inputstart",n.Event.INPUT_CHANGE="inputchange",n.Event.INPUT_END="inputend",n.Event.LEFT_BUTTON_DOWN="leftbuttondown",n.Event.LEFT_BUTTON_UP="leftbuttonup",n.Event.RIGHT_BUTTON_DOWN="rightbuttondown",n.Event.RIGHT_BUTTON_UP="rightbuttonup",n.Event.UP_BUTTON_DOWN="upbuttondown",n.Event.UP_BUTTON_UP="upbuttonup",n.Event.DOWN_BUTTON_DOWN="downbuttondown",n.Event.DOWN_BUTTON_UP="downbuttonup",n.Event.A_BUTTON_DOWN="abuttondown",n.Event.A_BUTTON_UP="abuttonup",n.Event.B_BUTTON_DOWN="bbuttondown",n.Event.B_BUTTON_UP="bbuttonup",n.Event.ADDED_TO_TIMELINE="addedtotimeline",n.Event.REMOVED_FROM_TIMELINE="removedfromtimeline",n.Event.ACTION_START="actionstart",n.Event.ACTION_END="actionend",n.Event.ACTION_TICK="actiontick",n.Event.ACTION_ADDED="actionadded",n.Event.ACTION_REMOVED="actionremoved",n.EventTarget=n.Class.create({initialize:function(){this._listeners={}},addEventListener:function(e,t){var n=this._listeners[e];n==null?this._listeners[e]=[t]:n.indexOf(t)===-1&&n.unshift(t)},on:function(){this.addEventListener.apply(this,arguments)},removeEventListener:function(e,t){var n=this._listeners[e];if(n!=null){var r=n.indexOf(t);r!==-1&&n.splice(r,1)}},clearEventListener:function(e){e!=null?delete this._listeners[e]:this._listeners={}},dispatchEvent:function(e){e.target=this,e.localX=e.x-this._offsetX,e.localY=e.y-this._offsetY,this["on"+e.type]!=null&&this["on"+e.type](e);var t=this._listeners[e.type];if(t!=null){t=t.slice();for(var n=0,r=t.length;n<r;n++)t[n].call(this,e)}}}),function(){var t;n.Core=n.Class.create(n.EventTarget,{initialize:function(r,i){if(e.document.body===null)throw new Error("document.body is null. Please excute 'new Core()' in window.onload.");n.EventTarget.call(this);var s=!0;t&&(s=!1,t.stop()),t=n.Core.instance=this,this.width=r||320,this.height=i||320,this.scale=1;var o=document.getElementById("enchant-stage");if(!o)o=document.createElement("div"),o.id="enchant-stage",o.style.position="absolute",document.body.firstChild?document.body.insertBefore(o,document.body.firstChild):document.body.appendChild(o),this.scale=Math.min(e.innerWidth/this.width,e.innerHeight/this.height),this._pageX=0,this._pageY=0;else{var u=e.getComputedStyle(o);r=parseInt(u.width,10),i=parseInt(u.height,10),r&&i?this.scale=Math.min(r/this.width,i/this.height):(o.style.width=this.width+"px",o.style.height=this.height+"px");while(o.firstChild)o.removeChild(o.firstChild);o.style.position="relative";var a=o.getBoundingClientRect();this._pageX=Math.round(e.scrollX+a.left),this._pageY=Math.round(e.scrollY+a.top)}this.scale||(this.scale=1),o.style.fontSize="12px",o.style.webkitTextSizeAdjust="none",this._element=o,this.fps=30,this.frame=0,this.ready=null,this.running=!1,this.assets={};var f=this._assets=[];(function b(e){e.assets instanceof Array&&[].push.apply(f,e.assets);for(var t in e)e.hasOwnProperty(t)&&typeof e[t]=="object"&&Object.getPrototypeOf(e[t])===Object.prototype&&b(e[t])})(n),this._scenes=[],this.currentScene=null,this.rootScene=new n.Scene,this.pushScene(this.rootScene),this.loadingScene=new n.Scene,this.loadingScene.backgroundColor="#000";var l=this.width*.4|0,c=this.width*.05|0,h=l*.03|0,p=new n.Sprite(l,c);p.x=(this.width-l)/2,p.y=(this.height-c)/2;var d=new n.Surface(l,c);d.context.fillStyle="#fff",d.context.fillRect(0,0,l,c),d.context.fillStyle="#000",d.context.fillRect(h,h,l-h*2,c-h*2),p.image=d;var v=0,m=0;this.addEventListener("progress",function(e){v=e.loaded/e.total}),p.addEventListener("enterframe",function(){m*=.9,m+=v*.1,d.context.fillStyle="#fff",d.context.fillRect(h,0,(l-h*2)*m,c)}),this.loadingScene.addChild(p),this._mousedownID=0,this._surfaceID=0,this._soundID=0,this._intervalID=null,this._offsetX=0,this._offsetY=0,this.input={},this._keybind=n.ENV.KEY_BIND_TABLE||{};var g=0;["left","right","up","down","a","b"].forEach(function(e){this.addEventListener(e+"buttondown",function(t){var r;this.input[e]||(this.input[e]=!0,r=new n.Event(g++?"inputchange":"inputstart"),this.dispatchEvent(r)),this.currentScene.dispatchEvent(t),r&&this.currentScene.dispatchEvent(r)}),this.addEventListener(e+"buttonup",function(t){var r;this.input[e]&&(this.input[e]=!1,r=new n.Event(--g?"inputchange":"inputend"),this.dispatchEvent(r)),this.currentScene.dispatchEvent(t),r&&this.currentScene.dispatchEvent(r)})},this);if(s){o=n.Core.instance._element;var y;document.addEventListener("keydown",function(e){t.dispatchEvent(new n.Event("keydown")),n.ENV.PREVENT_DEFAULT_KEY_CODES.indexOf(e.keyCode)!==-1&&(e.preventDefault(),e.stopPropagation());if(!t.running)return;var r=t._keybind[e.keyCode];r&&(y=new n.Event(r+"buttondown"),t.dispatchEvent(y))},!0),document.addEventListener("keyup",function(e){if(!t.running)return;var r=t._keybind[e.keyCode];r&&(y=new n.Event(r+"buttonup"),t.dispatchEvent(y))},!0),n.ENV.TOUCH_ENABLED&&(o.addEventListener("touchstart",function(e){var r=e.target.tagName.toLowerCase();n.ENV.USE_DEFAULT_EVENT_TAGS.indexOf(r)===-1&&(e.preventDefault(),t.running||e.stopPropagation())},!0),o.addEventListener("touchmove",function(e){var r=e.target.tagName.toLowerCase();n.ENV.USE_DEFAULT_EVENT_TAGS.indexOf(r)===-1&&(e.preventDefault(),t.running||e.stopPropagation())},!0),o.addEventListener("touchend",function(e){var r=e.target.tagName.toLowerCase();n.ENV.USE_DEFAULT_EVENT_TAGS.indexOf(r)===-1&&(e.preventDefault(),t.running||e.stopPropagation())},!0)),o.addEventListener("mousedown",function(e){var r=e.target.tagName.toLowerCase();n.ENV.USE_DEFAULT_EVENT_TAGS.indexOf(r)===-1&&(e.preventDefault(),t._mousedownID++,t.running||e.stopPropagation())},!0),o.addEventListener("mousemove",function(e){var r=e.target.tagName.toLowerCase();n.ENV.USE_DEFAULT_EVENT_TAGS.indexOf(r)===-1&&(e.preventDefault(),t.running||e.stopPropagation())},!0),o.addEventListener("mouseup",function(e){var r=e.target.tagName.toLowerCase();n.ENV.USE_DEFAULT_EVENT_TAGS.indexOf(r)===-1&&(e.preventDefault(),t.running||e.stopPropagation())},!0),t._touchEventTarget={},n.ENV.TOUCH_ENABLED&&(o.addEventListener("touchstart",function(e){var t=n.Core.instance,r=new n.Event(n.Event.TOUCH_START),i=e.changedTouches,s,o;for(var u=0,a=i.length;u<a;u++)s=i[u],r._initPosition(s.pageX,s.pageY),o=t.currentScene._determineEventTarget(r),t._touchEventTarget[s.identifier]=o,o.dispatchEvent(r)},!1),o.addEventListener("touchmove",function(e){var t=n.Core.instance,r=new n.Event(n.Event.TOUCH_MOVE),i=e.changedTouches,s,o;for(var u=0,a=i.length;u<a;u++)s=i[u],o=t._touchEventTarget[s.identifier],o&&(r._initPosition(s.pageX,s.pageY),o.dispatchEvent(r))},!1),o.addEventListener("touchend",function(e){var t=n.Core.instance,r=new n.Event(n.Event.TOUCH_END),i=e.changedTouches,s,o;for(var u=0,a=i.length;u<a;u++)s=i[u],o=t._touchEventTarget[s.identifier],o&&(r._initPosition(s.pageX,s.pageY),o.dispatchEvent(r),delete t._touchEventTarget[s.identifier])},!1)),o.addEventListener("mousedown",function(e){var t=n.Core.instance,r=new n.Event(n.Event.TOUCH_START);r._initPosition(e.pageX,e.pageY);var i=t.currentScene._determineEventTarget(r);t._touchEventTarget[t._mousedownID]=i,i.dispatchEvent(r)},!1),o.addEventListener("mousemove",function(e){var t=n.Core.instance,r=new n.Event(n.Event.TOUCH_MOVE);r._initPosition(e.pageX,e.pageY);var i=t._touchEventTarget[t._mousedownID];i&&i.dispatchEvent(r)},!1),o.addEventListener("mouseup",function(e){var t=n.Core.instance,r=new n.Event(n.Event.TOUCH_END);r._initPosition(e.pageX,e.pageY),t._touchEventTarget[t._mousedownID].dispatchEvent(r),delete t._touchEventTarget[t._mousedownID]},!1)}},preload:function(e){e instanceof Array||(e=Array.prototype.slice.call(arguments)),[].push.apply(this._assets,e)},load:function(e,r){r==null&&(r=function(){});var i=n.Core.findExt(e);if(n.Core._loadFuncs[i])n.Core._loadFuncs[i].call(this,e,r,i);else{var s=new XMLHttpRequest;s.open("GET",e,!0),s.onreadystatechange=function(i){if(s.readyState===4){if(s.status!==200&&s.status!==0)throw new Error(s.status+": "+"Cannot load an asset: "+e);var o=s.getResponseHeader("Content-Type")||"";o.match(/^image/)?(t.assets[e]=n.Surface.load(e),t.assets[e].addEventListener("load",r)):o.match(/^audio/)?(t.assets[e]=n.Sound.load(e,o),t.assets[e].addEventListener("load",r)):(t.assets[e]=s.responseText,r())}},s.send(null)}},start:function(){var r=function(){this.currentTime=this.getTime(),this.removeEventListener("load",r),this._intervalID=e.setInterval(function(){t._tick()},1e3/this.fps),this.running=!0};this.addEventListener("load",r);if(this._intervalID)e.clearInterval(this._intervalID);else if(this._assets.length){if(n.Sound.enabledInMobileSafari&&!t._touched&&n.ENV.VENDOR_PREFIX==="webkit"&&n.ENV.TOUCH_ENABLED){var i=new n.Scene;i.backgroundColor="#000";var s=Math.round(t.width/10),o=new n.Sprite(t.width,s);o.y=(t.height-s)/2,o.image=new n.Surface(t.width,s),o.image.context.fillStyle="#fff",o.image.context.font=s-1+"px bold Helvetica,Arial,sans-serif";var u=o.image.context.measureText("Touch to Start").width;o.image.context.fillText("Touch to Start",(t.width-u)/2,s-1),i.addChild(o),document.addEventListener("touchstart",function(){t._touched=!0,t.removeScene(i),t.start()},!0),t.pushScene(i);return}var a={},f=this._assets.filter(function(e){return e in a?!1:a[e]=!0}),l=0,c=f.length,h=function(){var e=new n.Event("progress");e.loaded=++l,e.total=c,t.dispatchEvent(e),l===c&&(t.removeScene(t.loadingScene),t.dispatchEvent(new n.Event("load")))};for(var p=0;p<c;p++)this.load(f[p],h);this.pushScene(this.loadingScene)}else this.dispatchEvent(new n.Event("load"))},debug:function(){this._debug=!0,this.rootScene.addEventListener("enterframe",function(e){this._actualFps=1/e}),this.start()},actualFps:{get:function(){return this._actualFps||this.fps}},_tick:function(){var e=this.getTime(),t=new n.Event("enterframe");t.elapsed=e-this.currentTime,this.currentTime=e;var r=this.currentScene.childNodes.slice(),i=Array.prototype.push;while(r.length){var s=r.pop();s.age++,s.dispatchEvent(t),s.childNodes&&i.apply(r,s.childNodes)}this.currentScene.age++,this.currentScene.dispatchEvent(t),this.dispatchEvent(t),this.dispatchEvent(new n.Event("exitframe")),this.frame++},getTime:function(){return e.performance&&e.performance.now?e.performance.now():e.performance&&e.performance.webkitNow?e.performance.webkitNow():Date.now()},stop:function(){this._intervalID&&(e.clearInterval(this._intervalID),this._intervalID=null),this.running=!1},pause:function(){this._intervalID&&(e.clearInterval(this._intervalID),this._intervalID=null)},resume:function(){if(this._intervalID)return;this.currentTime=this.getTime(),this._intervalID=e.setInterval(function(){t._tick()},1e3/this.fps),this.running=!0},pushScene:function(e){return this._element.appendChild(e._element),this.currentScene&&this.currentScene.dispatchEvent(new n.Event("exit")),this.currentScene=e,this.currentScene.dispatchEvent(new n.Event("enter")),this._scenes.push(e)},popScene:function(){return this.currentScene===this.rootScene?this.currentScene:(this._element.removeChild(this.currentScene._element),this.currentScene.dispatchEvent(new n.Event("exit")),this.currentScene=this._scenes[this._scenes.length-2],this.currentScene.dispatchEvent(new n.Event("enter")),this._scenes.pop())},replaceScene:function(e){return this.popScene(),this.pushScene(e)},removeScene:function(e){if(this.currentScene===e)return this.popScene();var t=this._scenes.indexOf(e);return t!==-1?(this._scenes.splice(t,1),this._element.removeChild(e._element),e):null},keybind:function(e,t){this._keybind[e]=t},getElapsedTime:function(){return this.frame/this.fps}}),n.Core._loadFuncs={},n.Core._loadFuncs.jpg=n.Core._loadFuncs.jpeg=n.Core._loadFuncs.gif=n.Core._loadFuncs.png=n.Core._loadFuncs.bmp=function(e,t){this.assets[e]=n.Surface.load(e),this.assets[e].addEventListener("load",t)},n.Core._loadFuncs.mp3=n.Core._loadFuncs.aac=n.Core._loadFuncs.m4a=n.Core._loadFuncs.wav=n.Core._loadFuncs.ogg=function(e,t,r){this.assets[e]=n.Sound.load(e,"audio/"+r),this.assets[e].addEventListener("load",t)},n.Core.findExt=function(e){var t=e.match(/\.\w+$/);return t&&t.length>0?t[0].slice(1).toLowerCase():e.indexOf("data:")===0?e.split(/[\/;]/)[1].toLowerCase():null},n.Core.instance=null}(),n.Game=n.Core,n.Node=n.Class.create(n.EventTarget,{initialize:function(){n.EventTarget.call(this),this._dirty=!1,this._matrix=[1,0,0,1,0,0],this._x=0,this._y=0,this._offsetX=0,this._offsetY=0,this.age=0,this.parentNode=null,this.scene=null,this.addEventListener("touchstart",function(e){this.parentNode&&this.parentNode.dispatchEvent(e)}),this.addEventListener("touchmove",function(e){this.parentNode&&this.parentNode.dispatchEvent(e)}),this.addEventListener("touchend",function(e){this.parentNode&&this.parentNode.dispatchEvent(e)});if(n.ENV.USE_ANIMATION)var e=this.tl=new n.Timeline(this)},moveTo:function(e,t){this._x=e,this._y=t,this._dirty=!0},moveBy:function(e,t){this._x+=e,this._y+=t,this._dirty=!0},x:{get:function(){return this._x},set:function(e){this._x=e,this._dirty=!0}},y:{get:function(){return this._y},set:function(e){this._y=e,this._dirty=!0}},_updateCoordinate:function(){var e=this,t=[e],r=e.parentNode,i=this.scene;while(r&&e._dirty)t.unshift(r),e=e.parentNode,r=e.parentNode;var s=n.Matrix.instance,o=s.stack,u=[],a,f,l;o.push(t[0]._matrix);for(var c=1,h=t.length;c<h;c++){e=t[c],a=[],s.makeTransformMatrix(e,u),s.multiply(o[o.length-1],u,a),e._matrix=a,o.push(a),f=typeof e._originX=="number"?e._originX:e._width/2||0,l=typeof e._originY=="number"?e._originY:e._height/2||0;var p=[f,l];s.multiplyVec(a,p,p),e._offsetX=p[0]-f,e._offsetY=p[1]-l,e._dirty=!1}s.reset()},remove:function(){this._listener&&this.clearEventListener(),this.parentNode&&this.parentNode.removeChild(this)}});var r=function(e,t){var n=[],r;for(var i=0,s=e.collection.length;i<s;i++)r=e.collection[i],t._intersectone(r)&&n.push(r);return n},i=function(e,t){var n=[],r,i;for(var s=0,o=e.collection.length;s<o;s++){r=e.collection[s];for(var u=0,a=t.collection.length;u<a;u++)i=t.collection[u],r._intersectone(i)&&n.push([r,i])}return n},s=function(e){return e instanceof n.Entity?r(this,e):typeof e=="function"&&e.collection?i(this,e):!1};n.Entity=n.Class.create(n.Node,{initialize:function(){var e=n.Core.instance;n.Node.call(this),this._rotation=0,this._scaleX=1,this._scaleY=1,this._touchEnabled=!0,this._clipping=!1,this._originX=null,this._originY=null,this._width=0,this._height=0,this._backgroundColor=null,this._opacity=1,this._visible=!0,this._buttonMode=null,this._style={},this.__styleStatus={},this.compositeOperation=null,this.buttonMode=null,this.buttonPressed=!1,this.addEventListener("touchstart",function(){if(!this.buttonMode)return;this.buttonPressed=!0;var t=new n.Event(this.buttonMode+"buttondown");this.dispatchEvent(t),e.dispatchEvent(t)}),this.addEventListener("touchend",function(){if(!this.buttonMode)return;this.buttonPressed=!1;var t=new n.Event(this.buttonMode+"buttonup");this.dispatchEvent(t),e.dispatchEvent(t)}),this.enableCollection()},width:{get:function(){return this._width},set:function(e){this._width=e,this._dirty=!0}},height:{get:function(){return this._height},set:function(e){this._height=e,this._dirty=!0}},backgroundColor:{get:function(){return this._backgroundColor},set:function(e){this._backgroundColor=e}},opacity:{get:function(){return this._opacity},set:function(e){this._opacity=e}},visible:{get:function(){return this._visible},set:function(e){this._visible=e}},touchEnabled:{get:function(){return this._touchEnabled},set:function(e){this._touchEnabled=e,(this._touchEnabled=e)?this._style.pointerEvents="all":this._style.pointerEvents="none"}},intersect:function(e){return e instanceof n.Entity?this._intersectone(e):typeof e=="function"&&e.collection?r(e,this):!1},_intersectone:function(e){return this._dirty&&this._updateCoordinate(),e._dirty&&e._updateCoordinate(),this._offsetX<e._offsetX+e.width&&e._offsetX<this._offsetX+this.width&&this._offsetY<e._offsetY+e.height&&e._offsetY<this._offsetY+this.height},within:function(e,t){this._dirty&&this._updateCoordinate(),e._dirty&&e._updateCoordinate(),t==null&&(t=(this.width+this.height+e.width+e.height)/4);var n;return(n=this._offsetX-e._offsetX+(this.width-e.width)/2)*n+(n=this._offsetY-e._offsetY+(this.height-e.height)/2)*n<t*t},scale:function(e,t){this._scaleX*=e,this._scaleY*=t!=null?t:e,this._dirty=!0},rotate:function(e){this._rotation+=e,this._dirty=!0},scaleX:{get:function(){return this._scaleX},set:function(e){this._scaleX=e,this._dirty=!0}},scaleY:{get:function(){return this._scaleY},set:function(e){this._scaleY=e,this._dirty=!0}},rotation:{get:function(){return this._rotation},set:function(e){this._rotation=e,this._dirty=!0}},originX:{get:function(){return this._originX},set:function(e){this._originX=e,this._dirty=!0}},originY:{get:function(){return this._originY},set:function(e){this._originY=e,this._dirty=!0}},enableCollection:function(){this.addEventListener("addedtoscene",this._addSelfToCollection),this.addEventListener("removedfromscene",this._removeSelfFromCollection),this.scene&&this._addSelfToCollection()},disableCollection:function(){this.removeEventListener("addedtoscene",this._addSelfToCollection),this.removeEventListener("removedfromscene",this._removeSelfFromCollection),this.scene&&this._removeSelfFromCollection()},_addSelfToCollection:function(){var e=this.getConstructor();e._collectionTarget.forEach(function(e){e.collection.push(this)},this)},_removeSelfFromCollection:function(){var e=this.getConstructor();e._collectionTarget.forEach(function(e){var t=e.collection.indexOf(this);t!==-1&&e.collection.splice(t,1)},this)},getConstructor:function(){return Object.getPrototypeOf(this).constructor}});var o=function(e){if(e._collective)return;var t=n.Class.getInheritanceTree(e),r=t.indexOf(n.Entity);r!==-1?e._collectionTarget=t.splice(0,r+1):e._collectionTarget=[],e.intersect=s,e.collection=[],e._collective=!0};o(n.Entity),n.Entity._inherited=function(e){o(e)},n.Sprite=n.Class.create(n.Entity,{initialize:function(e,t){n.Entity.call(this),this.width=e,this.height=t,this._image=null,this._frameLeft=0,this._frameTop=0,this._frame=0,this._frameSequence=[],this.addEventListener("enterframe",function(){if(this._frameSequence.length!==0){var e=this._frameSequence.shift();e===null?this._frameSequence=[]:(this._setFrame(e),this._frameSequence.push(e))}})},image:{get:function(){return this._image},set:function(e){if(e===this._image)return;this._image=e,this._setFrame(this._frame)}},frame:{get:function(){return this._frame},set:function(e){if(this._frame===e)return;if(e instanceof Array){var t=e,n=t.shift();this._setFrame(n),t.push(n),this._frameSequence=t}else this._setFrame(e),this._frameSequence=[],this._frame=e}},_setFrame:function(e){var t=this._image,n,r;t!=null&&(this._frame=e,n=t.width/this._width|0,this._frameLeft=(e%n|0)*this._width,this._frameTop=(e/n|0)*this._height%t.height)},width:{get:function(){return this._width},set:function(e){this._width=e,this._setFrame(),this._dirty=!0}},height:{get:function(){return this._height},set:function(e){this._height=e,this._setFrame(),this._dirty=!0}},cvsRender:function(e){if(this._image==null||this._width===0||this._height===0)return;var t=this._image,n=t._element,r=this._frameLeft,i=this._frameTop,s=Math.min(this.width,t.width-r),o=Math.min(this.height,t.height-i),u=Math.min(t.width,this.width),a=Math.min(t.height,this.height),f,l,c,h;for(l=0;l<this.height;l+=a){h=this.height<l+a?this.height-l:a;for(f=0;f<this.width;f+=u)c=this.width<f+u?this.width-f:u,e.drawImage(n,r,i,s*c/u,o*h/a,f,l,c,h)}},domRender:function(e){this._image&&(this._image._css?(this._style["background-image"]=this._image._css,this._style["background-position"]=-this._frameLeft+"px "+ -this._frameTop+"px"):this._image._element)}}),n.Label=n.Class.create(n.Entity,{initialize:function(e){n.Entity.call(this),this.width=300,this.font="14px serif",this.text=e||"",this.textAlign="left"},text:{get:function(){return this._text},set:function(e){if(this._text===e)return;this._text=e,e=e.replace(/<(br|BR) ?\/?>/g,"<br/>"),this._splitText=e.split("<br/>");var t=this.getMetrics();this._boundWidth=t.width,this._boundHeight=t.height;for(var n=0,r=this._splitText.length;n<r;n++)e=this._splitText[n],t=this.getMetrics(e),this._splitText[n]={},this._splitText[n].text=e,this._splitText[n].height=t.height}},textAlign:{get:function(){return this._style["text-align"]},set:function(e){this._style["text-align"]=e}},font:{get:function(){return this._style.font},set:function(e){this._style.font=e}},color:{get:function(){return this._style.color},set:function(e){this._style.color=e}},cvsRender:function(e){var t=0,n,r,i;if(this._splitText){e.textBaseline="top",e.font=this.font,e.fillStyle=this.color||"#000000";for(var s=0,o=this._splitText.length;s<o;s++){n=this._splitText[s],r="";for(var u=0,a=n.text.length;u<a;u++)i=n.text[u],e.measureText(r).width>this.width&&(e.fillText(r,0,t),t+=n.height-1,r=""),r+=i;e.fillText(r,0,t),t+=n.height-1}}},domRender:function(e){e.innerHTML!==this._text&&(e.innerHTML=this._text)},detectRender:function(e){e.fillRect(0,0,this._boundWidth,this._boundHeight)}}),n.Label.prototype.getMetrics=function(e){var t={},n,r,i;if(document.body){n=document.createElement("div");for(var s in this._style)s!=="width"&&s!=="height"&&(n.style[s]=this._style[s]);n.innerHTML=e||this._text,document.body.appendChild(n),t.height=parseInt(getComputedStyle(n).height,10)+1,n.style.position="absolute",t.width=parseInt(getComputedStyle(n).width,10)+1,document.body.removeChild(n)}else t.width=this.width,t.height=this.height;return t},n.Map=n.Class.create(n.Entity,{initialize:function(e,t){var r=n.Core.instance;n.Entity.call(this);var i=new n.Surface(r.width,r.height);this._surface=i;var s=i._element;s.style.position="absolute",n.ENV.RETINA_DISPLAY&&r.scale===2?(s.width=r.width*2,s.height=r.height*2,this._style.webkitTransformOrigin="0 0",this._style.webkitTransform="scale(0.5)"):(s.width=r.width,s.height=r.height),this._context=s.getContext("2d"),this._tileWidth=e||0,this._tileHeight=t||0,this._image=null,this._data=[[[]]],this._dirty=!1,this._tight=!1,this.touchEnabled=!1,this.collisionData=null,this._listeners.render=null,this.addEventListener("render",function(){if(this._dirty||this._previousOffsetX==null)this.redraw(0,0,r.width,r.height);else if(this._offsetX!==this._previousOffsetX||this._offsetY!==this._previousOffsetY)if(this._tight){var e=-this._offsetX,t=-this._offsetY,n=-this._previousOffsetX,i=-this._previousOffsetY,s=e-n+r.width,o=n-e+r.width,u=t-i+r.height,a=i-t+r.height;if(s>this._tileWidth&&o>this._tileWidth&&u>this._tileHeight&&a>this._tileHeight){var f,l,c,h,p,d;s<o?(f=0,c=n-e,p=s):(f=e-n,c=0,p=o),u<a?(l=0,h=i-t,d=u):(l=t-i,h=0,d=a),r._buffer==null&&(r._buffer=document.createElement("canvas"),r._buffer.width=this._context.canvas.width,r._buffer.height=this._context.canvas.height);var v=r._buffer.getContext("2d");this._doubledImage?(v.clearRect(0,0,p*2,d*2),v.drawImage(this._context.canvas,f*2,l*2,p*2,d*2,0,0,p*2,d*2),v=this._context,v.clearRect(c*2,h*2,p*2,d*2),v.drawImage(r._buffer,0,0,p*2,d*2,c*2,h*2,p*2,d*2)):(v.clearRect(0,0,p,d),v.drawImage(this._context.canvas,f,l,p,d,0,0,p,d),v=this._context,v.clearRect(c,h,p,d),v.drawImage(r._buffer,0,0,p,d,c,h,p,d)),c===0?this.redraw(p,0,r.width-p,r.height):this.redraw(0,0,r.width-p,r.height),h===0?this.redraw(0,d,r.width,r.height-d):this.redraw(0,0,r.width,r.height-d)}else this.redraw(0,0,r.width,r.height)}else this.redraw(0,0,r.width,r.height);this._previousOffsetX=this._offsetX,this._previousOffsetY=this._offsetY})},loadData:function(e){this._data=Array.prototype.slice.apply(arguments),this._dirty=!0,this._tight=!1;for(var t=0,n=this._data.length;t<n;t++){var r=0;e=this._data[t];for(var i=0,s=e.length;i<s;i++)for(var o=0,u=e[i].length;o<u;o++)e[i][o]>=0&&r++;if(r/(e.length*e[0].length)>.2){this._tight=!0;break}}},checkTile:function(e,t){if(e<0||this.width<=e||t<0||this.height<=t)return!1;var n=this._image.width,r=this._image.height,i=this._tileWidth||n,s=this._tileHeight||r;e=e/i|0,t=t/s|0;var o=this._data[0];return o[t][e]},hitTest:function(e,t){if(e<0||this.width<=e||t<0||this.height<=t)return!1;var n=this._image.width,r=this._image.height,i=this._tileWidth||n,s=this._tileHeight||r;e=e/i|0,t=t/s|0;if(this.collisionData!=null)return this.collisionData[t]&&!!this.collisionData[t][e];for(var o=0,u=this._data.length;o<u;o++){var a=this._data[o],f;if(a[t]!=null&&(f=a[t][e])!=null&&0<=f&&f<(n/i|0)*(r/s|0))return!0}return!1},image:{get:function(){return this._image},set:function(e){var t=n.Core.instance;this._image=e;if(n.ENV.RETINA_DISPLAY&&t.scale===2){var r=new n.Surface(e.width*2,e.height*2),i=this._tileWidth||e.width,s=this._tileHeight||e.height,o=e.width/i|0,u=e.height/s|0;for(var a=0;a<u;a++)for(var f=0;f<o;f++)r.draw(e,f*i,a*s,i,s,f*i*2,a*s*2,i*2,s*2);this._doubledImage=r}this._dirty=!0}},tileWidth:{get:function(){return this._tileWidth},set:function(e){this._tileWidth=e,this._dirty=!0}},tileHeight:{get:function(){return this._tileHeight},set:function(e){this._tileHeight=e,this._dirty=!0}},width:{get:function(){return this._tileWidth*this._data[0][0].length}},height:{get:function(){return this._tileHeight*this._data[0].length}},redraw:function(e,t,n,r){if(this._image==null)return;var i,s,o,u,a;this._doubledImage?(i=this._doubledImage,s=this._tileWidth*2,o=this._tileHeight*2,u=-this._offsetX*2,a=-this._offsetY*2,e*=2,t*=2,n*=2,r*=2):(i=this._image,s=this._tileWidth,o=this._tileHeight,u=-this._offsetX,a=-this._offsetY);var f=i.width/s|0,l=i.height/o|0,c=Math.max((e+u)/s|0,0),h=Math.max((t+a)/o|0,0),p=Math.ceil((e+u+n)/s),d=Math.ceil((t+a+r)/o),v=i._element,m=this._context,g=m.canvas;m.clearRect(e,t,n,r);for(var y=0,b=this._data.length;y<b;y++){var w=this._data[y],E=Math.min(p,w[0].length),S=Math.min(d,w.length);for(t=h;t<S;t++)for(e=c;e<E;e++){var x=w[t][e];if(0<=x&&x<f*l){var T=x%f*s,N=(x/f|0)*o;m.drawImage(v,T,N,s,o,e*s-u,t*o-a,s,o)}}}},cvsRender:function(e){var t=n.Game.instance;if(this.width!==0&&this.height!==0){e.save(),e.setTransform(1,0,0,1,0,0);var r=this._context.canvas;e.drawImage(r,0,0,t.width,t.height),e.restore()}},domRender:function(e){this._image&&(this._style["background-image"]=this._surface._css,this._style[n.ENV.VENDOR_PREFIX+"Transform"]="matrix(1, 0, 0, 1, 0, 0)")}}),n.Group=n.Class.create(n.Node,{initialize:function(){this.childNodes=[],n.Node.call(this),this._rotation=0,this._scaleX=1,this._scaleY=1,this._originX=null,this._originY=null,this.__dirty=!1,[n.Event.ADDED_TO_SCENE,n.Event.REMOVED_FROM_SCENE].forEach(function(e){this.addEventListener(e,function(e){this.childNodes.forEach(function(t){t.scene=this.scene,t.dispatchEvent(e)},this)})},this)},addChild:function(e){this.childNodes.push(e),e.parentNode=this;var t=new n.Event("childadded");t.node=e,t.next=null,this.dispatchEvent(t),e.dispatchEvent(new n.Event("added"));if(this.scene){e.scene=this.scene;var r=new n.Event("addedtoscene");e.dispatchEvent(r)}},insertBefore:function(e,t){var r=this.childNodes.indexOf(t);if(r!==-1){this.childNodes.splice(r,0,e),e.parentNode=this;var i=new n.Event("childadded");i.node=e,i.next=t,this.dispatchEvent(i),e.dispatchEvent(new n.Event("added"));if(this.scene){e.scene=this.scene;var s=new n.Event("addedtoscene");e.dispatchEvent(s)}}else this.addChild(e)},removeChild:function(e){var t;if((t=this.childNodes.indexOf(e))!==-1){this.childNodes.splice(t,1),e.parentNode=null;var r=new n.Event("childremoved");r.node=e,this.dispatchEvent(r),e.dispatchEvent(new n.Event("removed"));if(this.scene){e.scene=null;var i=new n.Event("removedfromscene");e.dispatchEvent(i)}}},firstChild:{get:function(){return this.childNodes[0]}},lastChild:{get:function(){return this.childNodes[this.childNodes.length-1]}},rotation:{get:function(){return this._rotation},set:function(e){this._rotation=e,this._dirty=!0}},scaleX:{get:function(){return this._scaleX},set:function(e){this._scaleX=e,this._dirty=!0}},scaleY:{get:function(){return this._scaleY},set:function(e){this._scaleY=e,this._dirty=!0}},originX:{get:function(){return this._originX},set:function(e){this._originX=e,this._dirty=!0}},originY:{get:function(){return this._originY},set:function(e){this._originY=e,this._dirty=!0}},_dirty:{get:function(){return this.__dirty},set:function(e){e=!!e,this.__dirty=e;if(e)for(var t=0,n=this.childNodes.length;t<n;t++)this.childNodes[t]._dirty=!0}}}),n.Matrix=n.Class.create({initialize:function(){if(n.Matrix.instance)return n.Matrix.instance;this.reset()},reset:function(){this.stack=[],this.stack.push([1,0,0,1,0,0])},makeTransformMatrix:function(e,t){var n=e._x,r=e._y,i=e.width||0,s=e.height||0,o=e._rotation||0,u=typeof e._scaleX=="number"?e._scaleX:1,a=typeof e._scaleY=="number"?e._scaleY:1,f=o*Math.PI/180,l=Math.cos(f),c=Math.sin(f),h=typeof e._originX=="number"?e._originX:i/2,p=typeof e._originY=="number"?e._originY:s/2,d=u*l,v=u*c,m=a*c,g=a*l;t[0]=d,t[1]=v,t[2]=-m,t[3]=g,t[4]=-d*h+m*p+n+h,t[5]=-v*h-g*p+r+p},multiply:function(e,t,n){var r=e[0],i=e[2],s=e[4],o=e[1],u=e[3],a=e[5],f=t[0],l=t[2],c=t[4],h=t[1],p=t[3],d=t[5];n[0]=r*f+i*h,n[1]=o*f+u*h,n[2]=r*l+i*p,n[3]=o*l+u*p,n[4]=r*c+i*d+s,n[5]=o*c+u*d+a},multiplyVec:function(e,t,n){var r=t[0],i=t[1],s=e[0],o=e[2],u=e[4],a=e[1],f=e[3],l=e[5];n[0]=s*r+o*i+u,n[1]=a*r+f*i+l}}),n.Matrix.instance=new n.Matrix,n.DetectColorManager=n.Class.create({initialize:function(e,t){this.reference=[],this.colorResolution=e||16,this.max=t||1,this.capacity=Math.pow(this.colorResolution,3);for(var n=1,r=this.capacity;n<r;n++)this.reference[n]=null},attachDetectColor:function(e){var t=this.reference.indexOf(null);return t===-1&&(t=1),this.reference[t]=e,this._getColor(t)},detachDetectColor:function(e){var t=this.reference.indexOf(e);t!==-1&&(this.reference[t]=null)},_getColor:function(e){var t=this.colorResolution,n=t/this.max;return[parseInt(e/t/t%t,10)/n,parseInt(e/t%t,10)/n,parseInt(e%t,10)/n,1]},_decodeDetectColor:function(e){var t=this.colorResolution;return~~(e[0]*t*t*t/256)+~~(e[1]*t*t/256)+~~(e[2]*t/256)},getSpriteByColor:function(e){return this.reference[this._decodeDetectColor(e)]}}),n.DomManager=n.Class.create({initialize:function(e,t){var r=n.Game.instance;this.layer=null,this.targetNode=e,typeof t=="string"?this.element=document.createElement(t):t instanceof HTMLElement&&(this.element=t),this.style=this.element.style,this.style.position="absolute",this.style[n.ENV.VENDOR_PREFIX+"TransformOrigin"]="0px 0px",r._debug&&(this.style.border="1px solid blue",this.style.margin="-1px");var i=this;this._setDomTarget=function(){i.layer._touchEventTarget=i.targetNode},this._attachEvent()},getDomElement:function(){return this.element},getDomElementAsNext:function(){return this.element},getNextManager:function(e){var t=this.targetNode.parentNode.childNodes.indexOf(e.targetNode);return t!==this.targetNode.parentNode.childNodes.length-1?this.targetNode.parentNode.childNodes[t+1]._domManager:null},addManager:function(e,t){var n;t&&(n=t.getDomElementAsNext());var r=e.getDomElement();r instanceof Array?r.forEach(function(e){this.element.insertBefore(e,n)},this):this.element.insertBefore(r,n),this.setLayer(this.layer)},removeManager:function(e){e instanceof n.DomlessManager?e._domRef.forEach(function(e){this.element.removeChild(e)},this):this.element.removeChild(e.element),this.setLayer(this.layer)},setLayer:function(e){this.layer=e;var t=this.targetNode,n;if(t.childNodes)for(var r=0,i=t.childNodes.length;r<i;r++)n=t.childNodes[r]._domManager,n&&n.setLayer(e)},render:function(e){var t=this.targetNode,r=n.Matrix.instance,i=r.stack,s=[];r.makeTransformMatrix(t,s),r.multiply(i[i.length-1],s,s),r.multiply(e,s,e),t._matrix=e;var o=typeof t._originX=="number"?t._originX:t.width/2||0,u=typeof t._originY=="number"?t._originY:t.height/2||0,a=[o,u];r.multiplyVec(s,a,a),t._offsetX=a[0]-o,t._offsetY=a[1]-u,t.parentNode&&!(t.parentNode instanceof n.Group)&&(t._offsetX+=t.parentNode._offsetX,t._offsetY+=t.parentNode._offsetY),this.style[n.ENV.VENDOR_PREFIX+"Transform"]="matrix("+s[0].toFixed(10)+","+s[1].toFixed(10)+","+s[2].toFixed(10)+","+s[3].toFixed(10)+","+s[4].toFixed(10)+","+s[5].toFixed(10)+")",this.domRender()},domRender:function(){var e=this.targetNode;e._style||(e._style={}),e.__styleStatus||(e.__styleStatus={}),e._style.width=e.width+"px",e._style.height=e.height+"px",e._style.opacity=e._opacity,e._style["background-color"]=e._backgroundColor,typeof e._visible!="undefined"&&(e._style.display=e._visible?"block":"none"),typeof e.domRender=="function"&&e.domRender(this.element);for(var t in e._style)e.__styleStatus[t]!==e._style[t]&&(this.style.setProperty(t,e._style[t]),e.__styleStatus[t]=e._style[t])},_attachEvent:function(){n.ENV.TOUCH_ENABLED&&this.element.addEventListener("touchstart",this._setDomTarget,!0),this.element.addEventListener("mousedown",this._setDomTarget,!0)},_detachEvent:function(){n.ENV.TOUCH_ENABLED&&this.element.removeEventListener("touchstart",this._setDomTarget,!0),this.element.removeEventListener("mousedown",this._setDomTarget,!0)},remove:function(){this._detachEvent(),this.element=this.style=this.targetNode=null}}),n.DomlessManager=n.Class.create({initialize:function(e){this._domRef=[],this.targetNode=e},_register:function(e,t){var n=this._domRef.indexOf(t),r;e instanceof Array?n===-1?Array.prototype.push.apply(this._domRef,e):Array.prototype.splice.apply(this._domRef,[n,0].concat(e)):n===-1?this._domRef.push(e):this._domRef.splice(n,0,e)},getNextManager:function(e){var t=this.targetNode.parentNode.childNodes.indexOf(e.targetNode);return t!==this.targetNode.parentNode.childNodes.length-1?this.targetNode.parentNode.childNodes[t+1]._domManager:null},getDomElement:function(){var e=[];return this.targetNode.childNodes.forEach(function(t){e=e.concat(t._domManager.getDomElement())}),e},getDomElementAsNext:function(){if(this._domRef.length)return this._domRef[0];var e=this.getNextManager(this);return e?e.element:null},addManager:function(e,t){var r=this.targetNode.parentNode;r&&(t===null&&(t=this.getNextManager(this)),r instanceof n.Scene?r._layers.Dom._domManager.addManager(e,t):r._domManager.addManager(e,t));var i=t?t.getDomElementAsNext():null;this._register(e.getDomElement(),i),this.setLayer(this.layer)},removeManager:function(e){var t,n=this._domRef.indexOf(e.element);n!==-1&&(t=this._domRef[n],t.parentNode.removeChild(t),this._domRef.splice(n,1)),this.setLayer(this.layer)},setLayer:function(e){this.layer=e;var t=this.targetNode,n;if(t.childNodes)for(var r=0,i=t.childNodes.length;r<i;r++)n=t.childNodes[r]._domManager,n&&n.setLayer(e)},render:function(e){var t=n.Matrix.instance,r=t.stack,i=this.targetNode,s=[];t.makeTransformMatrix(i,s),t.multiply(r[r.length-1],s,s),t.multiply(e,s,e),i._matrix=e;var o=typeof i._originX=="number"?i._originX:i.width/2||0,u=typeof i._originY=="number"?i._originY:i.height/2||0,a=[o,u];t.multiplyVec(s,a,a),i._offsetX=a[0]-o,i._offsetY=a[1]-u,r.push(s)},remove:function(){this._domRef=[],this.targetNode=null}}),n.DomLayer=n.Class.create(n.Group,{initialize:function(){var e=n.Game.instance;n.Group.call(this),this.width=this._width=e.width,this.height=this._height=e.height,this._touchEventTarget=null,this._element=document.createElement("div"),this._element.style.width=this.width+"px",this._element.style.height=this.height+"px",this._element.style.position="absolute",this._domManager=new n.DomManager(this,this._element),this._domManager.layer=this;var t=[n.Event.TOUCH_START,n.Event.TOUCH_MOVE,n.Event.TOUCH_END];t.forEach(function(e){this.addEventListener(e,function(e){this._scene&&this._scene.dispatchEvent(e)})},this);var r=function(e){var t=e.node,s=e.next,o=e.target,u=s?s._domManager:null;n.DomLayer._attachDomManager(t,r,i),o._domManager.addManager(t._domManager,u);var a=new n.Event(n.Event.RENDER);o._domManager.layer._rendering(t,a)},i=function(e){var t=e.node,s=e.target;s._domManager.removeManager(t._domManager),n.DomLayer._detachDomManager(t,r,i)};this.addEventListener("childremoved",i),this.addEventListener("childadded",r)},_startRendering:function(){this.addEventListener("exitframe",this._onexitframe),this._onexitframe()},_stopRendering:function(){this.removeEventListener("exitframe",this._onexitframe),this._onexitframe()},_onexitframe:function(){this._rendering(this,new n.Event(n.Event.RENDER))},_rendering:function(e,t,r){var i;r||(r=[1,0,0,1,0,0]),e.dispatchEvent(t),e._domManager.render(r);if(e.childNodes)for(var s=0,o=e.childNodes.length;s<o;s++)i=e.childNodes[s],this._rendering(i,t,r.slice());e._domManager instanceof n.DomlessManager&&n.Matrix.instance.stack.pop(),e._dirty=!1},_determineEventTarget:function(){return this._touchEventTarget&&this._touchEventTarget!==this?this._touchEventTarget:null}}),n.DomLayer._attachDomManager=function(e,t,r){var i;e._domManager||(e.addEventListener("childadded",t),e.addEventListener("childremoved",r),e instanceof n.Group?e._domManager=new n.DomlessManager(e):e._element?e._domManager=new n.DomManager(e,e._element):e._domManager=new n.DomManager(e,"div"));if(e.childNodes)for(var s=0,o=e.childNodes.length;s<o;s++)i=e.childNodes[s],n.DomLayer._attachDomManager(i,t,r),e._domManager.addManager(i._domManager,null)},n.DomLayer._detachDomManager=function(e,t,r){var i;e.removeEventListener("childadded",t),e.removeEventListener("childremoved",r);if(e.childNodes)for(var s=0,o=e.childNodes.length;s<o;s++)i=e.childNodes[s],e._domManager.removeManager(i._domManager,null),n.DomLayer._detachDomManager(i,t,r);e._domManager.remove(),delete e._domManager},n.CanvasLayer=n.Class.create(n.Group,{initialize:function(){var e=n.Game.instance;n.Group.call(this),this._cvsCache={matrix:[1,0,0,1,0,0],detectColor:"#000000"},this._cvsCache.layer=this,this.width=e.width,this.height=e.height,this._element=document.createElement("canvas"),this._element.width=e.width,this._element.height=e.height,this._element.style.position="absolute",this._detect=document.createElement("canvas"),this._detect.width=e.width,this._detect.height=e.height,this._detect.style.position="absolute",this._lastDetected=0,this.context=this._element.getContext("2d"),this._dctx=this._detect.getContext("2d"),this._colorManager=new n.DetectColorManager(16,256);var t=[n.Event.TOUCH_START,n.Event.TOUCH_MOVE,n.Event.TOUCH_END];t.forEach(function(e){this.addEventListener(e,function(e){this._scene&&this._scene.dispatchEvent(e)})},this);var r=function(e){var t=e.node,s=e.target,o;s instanceof n.CanvasLayer?o=s._scene._layers.Canvas:o=s.scene._layers.Canvas,n.CanvasLayer._attachCache(t,o,r,i);var u=new n.Event(n.Event.RENDER);s._dirty&&s._updateCoordinate(),n.Matrix.instance.stack.push(s._matrix),o._rendering(t,u),n.Matrix.instance.stack.pop(s._matrix)},i=function(e){var t=e.node,s=e.target,o;s instanceof n.CanvasLayer?o=s._scene._layers.Canvas:o=s.scene._layers.Canvas,n.CanvasLayer._detachCache(t,o,r,i)};this.addEventListener("childremoved",i),this.addEventListener("childadded",r)},_startRendering:function(){this.addEventListener("exitframe",this._onexitframe),this._onexitframe(new n.Event(n.Event.RENDER))},_stopRendering:function(){this.removeEventListener("render",this._onexitframe),this._onexitframe(new n.Event(n.Event.RENDER))},_onexitframe:function(){var e=n.Game.instance,t=this.context;t.clearRect(0,0,e.width,e.height);var r=new n.Event(n.Event.RENDER);this._rendering(this,r)},_rendering:function(e,t){var r=n.Game.instance,i=n.Matrix.instance,s=i.stack,o=this.context,u;o.save(),e.dispatchEvent(t),e.compositeOperation?o.globalCompositeOperation=e.compositeOperation:o.globalCompositeOperation="source-over",o.globalAlpha=typeof e._opacity=="number"?e._opacity:1,this._transform(e,o);if(typeof e._visible=="undefined"||e._visible)e._backgroundColor&&(o.fillStyle=e._backgroundColor,o.fillRect(0,0,e._width,e._height)),e.cvsRender&&e.cvsRender(o),r._debug&&(e instanceof n.Label||e instanceof n.Sprite?o.strokeStyle="#ff0000":o.strokeStyle="#0000ff",o.strokeRect(0,0,e._width,e._height)),e._clipping&&o.clip();if(e.childNodes)for(var a=0,f=e.childNodes.length;a<f;a++)u=e.childNodes[a],this._rendering(u,t);o.restore(),n.Matrix.instance.stack.pop()},_detectrendering:function(e){var t=this._dctx,r;t.save(),this._transform(e,t),t.fillStyle=e._cvsCache.detectColor,e._touchEnabled&&(e.detectRender?e.detectRender(t):t.fillRect(0,0,e.width,e.height)),e._clipping&&t.clip();if(e.childNodes)for(var i=0,s=e.childNodes.length;i<s;i++)r=e.childNodes[i],this._detectrendering(r);t.restore(),n.Matrix.instance.stack.pop()},_transform:function(e,t){var r=n.Matrix.instance,i=r.stack,s;e._dirty?(r.makeTransformMatrix(e,e._cvsCache.matrix),s=[],r.multiply(i[i.length-1],e._cvsCache.matrix,s),e._matrix=s):s=e._matrix,i.push(s),t.setTransform.apply(t,s);var o=typeof e._originX=="number"?e._originX:e._width/2||0,u=typeof e._originY=="number"?e._originY:e._height/2||0,a=[o,u];r.multiplyVec(s,a,a),e._offsetX=a[0]-o,e._offsetY=a[1]-u,e._dirty=!1},_determineEventTarget:function(e){return this._getEntityByPosition(e.x,e.y)},_getEntityByPosition:function(e,t){var r=n.Game.instance,i=this._dctx;this._lastDetected<r.frame&&(i.clearRect(0,0,this.width,this.height),this._detectrendering(this),this._lastDetected=r.frame);var s=i.getImageData(e,t,1,1).data;return this._colorManager.getSpriteByColor(s)}}),n.CanvasLayer._attachCache=function(e,t,r,i){var s;e._cvsCache||(e._cvsCache={},e._cvsCache.matrix=[1,0,0,1,0,0],e._cvsCache.detectColor="rgba("+t._colorManager.attachDetectColor(e)+")",e.addEventListener("childadded",r),e.addEventListener("childremoved",i));if(e.childNodes)for(var o=0,u=e.childNodes.length;o<u;o++)s=e.childNodes[o],n.CanvasLayer._attachCache(s,t,r,i)},n.CanvasLayer._detachCache=function(e,t,r,i){var s;e._cvsCache&&(t._colorManager.detachDetectColor(e),e.removeEventListener("childadded",r),e.removeEventListener("childremoved",i),delete e._cvsCache);if(e.childNodes)for(var o=0,u=e.childNodes.length;o<u;o++)s=e.childNodes[o],n.CanvasLayer._detachCache(s,t,r,i)},n.Scene=n.Class.create(n.Group,{initialize:function(){var e=n.Game.instance;n.Group.call(this),this.width=e.width,this.height=e.height,this.scene=this,this._backgroundColor=null,this._element=document.createElement("div"),this._element.style.width=this.width+"px",this._element.style.height=this.height+"px",this._element.style.position="absolute",this._element.style.overflow="hidden",this._element.style[n.ENV.VENDOR_PREFIX+"TransformOrigin"]="0 0",this._element.style[n.ENV.VENDOR_PREFIX+"Transform"]="scale("+n.Game.instance.scale+")",this._layers={},this._layerPriority=[],this.addLayer("Canvas"),this.addLayer("Dom"),this.addEventListener(n.Event.CHILD_ADDED,this._onchildadded),this.addEventListener(n.Event.CHILD_REMOVED,this._onchildremoved),this.addEventListener(n.Event.ENTER,this._onenter),this.addEventListener(n.Event.EXIT,this._onexit);var t=this;this._dispatchExitframe=function(){var e;for(var r in t._layers)e=t._layers[r],e.dispatchEvent(new n.Event(n.Event.EXIT_FRAME))}},x:{get:function(){return this._x},set:function(e){this._x=e;for(var t in this._layers)this._layers[t].x=e}},y:{get:function(){return this._y},set:function(e){this._y=e;for(var t in this._layers)this._layers[t].y=e}},rotation:{get:function(){return this._rotation},set:function(e){this._rotation=e;for(var t in this._layers)this._layers[t].rotation=e}},scaleX:{get:function(){return this._scaleX},set:function(e){this._scaleX=e;for(var t in this._layers)this._layers[t].scaleX=e}},scaleY:{get:function(){return this._scaleY},set:function(e){this._scaleY=e;for(var t in this._layers)this._layers[t].scaleY=e}},backgroundColor:{get:function(){return this._backgroundColor},set:function(e){this._backgroundColor=this._element.style.backgroundColor=e}},addLayer:function(e,t){var r=n.Game.instance;if(this._layers[e])return;var i=new n[e+"Layer"];r.currentScene===this&&i._startRendering(),this._layers[e]=i;var s=i._element;if(typeof t=="number"){var o=this._element.childNodes.indexOf(t);this._element.insertBefore(s,o),this._layerPriority.splice(t,0,e)}else this._element.appendChild(s),this._layerPriority.push(e);i._scene=this},_determineEventTarget:function(e){var t,n;for(var r=this._layerPriority.length-1;r>=0;r--){t=this._layers[this._layerPriority[r]],n=t._determineEventTarget(e);if(n)break}return n||(n=this),n},_onchildadded:function(e){var t=e.node,n=e.next;t._element?(this._layers.Dom.insertBefore(t,n),t._layer=this._layers.Dom):(this._layers.Canvas.insertBefore(t,n),t._layer=this._layers.Canvas),t.parentNode=this},_onchildremoved:function(e){var t=e.node;t._layer.removeChild(t),t._layer=null},_onenter:function(){for(var e in this._layers)this._layers[e]._startRendering();n.Game.instance.addEventListener("exitframe",this._dispatchExitframe)},_onexit:function(){for(var e in this._layers)this._layers[e]._stopRendering();n.Game.instance.removeEventListener("exitframe",this._dispatchExitframe)}}),n.Surface=n.Class.create(n.EventTarget,{initialize:function(e,t){n.EventTarget.call(this);var r=n.Core.instance;this.width=e,this.height=t,this.context=null;var i="enchant-surface"+r._surfaceID++;if(document.getCSSCanvasContext){this.context=document.getCSSCanvasContext("2d",i,e,t),this._element=this.context.canvas,this._css="-webkit-canvas("+i+")";var s=this.context}else document.mozSetImageElement?(this._element=document.createElement("canvas"),this._element.width=e,this._element.height=t,this._css="-moz-element(#"+i+")",this.context=this._element.getContext("2d"),document.mozSetImageElement(i,this._element)):(this._element=document.createElement("canvas"),this._element.width=e,this._element.height=t,this._element.style.position="absolute",this.context=this._element.getContext("2d"),n.ENV.CANVAS_DRAWING_METHODS.forEach(function(e){var t=this.context[e];this.context[e]=function(){t.apply(this,arguments),this._dirty=!0}},this))},getPixel:function(e,t){return this.context.getImageData(e,t,1,1).data},setPixel:function(e,t,n,r,i,s){var o=this.context.createImageData(1,1);o.data[0]=n,o.data[1]=r,o.data[2]=i,o.data[3]=s,this.context.putImageData(o,e,t)},clear:function(){this.context.clearRect(0,0,this.width,this.height)},draw:function(e){e=e._element;if(arguments.length===1)this.context.drawImage(e,0,0);else{var t=arguments;t[0]=e,this.context.drawImage.apply(this.context,t)}},clone:function(){var e=new n.Surface(this.width,this.height);return e.draw(this),e},toDataURL:function(){var e=this._element.src;return e?e.slice(0,5)==="data:"?e:this.clone().toDataURL():this._element.toDataURL()}}),n.Surface.load=function(e,t){var r=new Image,i=Object.create(n.Surface.prototype,{context:{value:null},_css:{value:"url("+e+")"},_element:{value:r}});return n.EventTarget.call(i),r.src=e,r.onerror=function(){throw new Error("Cannot load an asset: "+r.src)},r.onload=function(){i.width=r.width,i.height=r.height,i.dispatchEvent(new n.Event("load"))},i},e.webkitAudioContext&&n.ENV.USE_WEBAUDIO?(n.Game._loadFuncs.mp3=n.Game._loadFuncs.aac=n.Game._loadFuncs.m4a=n.Game._loadFuncs.wav=n.Game._loadFuncs.ogg=function(e,t,r){this.assets[e]=n.Sound.load(e,"audio/"+r,t)},n.Sound=n.Class.create(n.EventTarget,{initialize:function(){var e=n.Sound.audioContext;n.EventTarget.call(this),this.src=e.createBufferSource(),this.buffer=null,this._volume=1,this._currentTime=0,this._state=0,this.connectTarget=n.Sound.destination},play:function(e){var t=n.Sound.audioContext;this._state===2?this.src.connect(this.connectTarget):(this._state===1&&!e&&this.src.disconnect(this.connectTarget),this.src=t.createBufferSource(),this.src.buffer=this.buffer,this.src.gain.value=this._volume,this.src.connect(this.connectTarget),this.src.noteOn(0)),this._state=1},pause:function(){var e=n.Sound.audioContext;this.src.disconnect(this.connectTarget),this._state=2},stop:function(){this.src.noteOff(0),this._state=0},clone:function(){var e=new n.Sound;return e.buffer=this.buffer,e},dulation:{get:function(){return this.buffer?this.buffer.dulation:0}},volume:{get:function(){return this._volume},set:function(e){e=Math.max(0,Math.min(1,e)),this._volume=e,this.src&&(this.src.gain.value=e)}},currentTime:{get:function(){return e.console.log("currentTime is not allowed"),this._currentTime},set:function(t){e.console.log("currentTime is not allowed"),this._currentTime=t}}}),n.Sound.load=function(t,r,i){var s=n.Sound.audioContext,o=new XMLHttpRequest,u=new n.Sound,a="audio/"+n.Game.findExt(t);return o.responseType="arraybuffer",o.open("GET",t,!0),o.onload=function(){s.decodeAudioData(o.response,function(e){u.buffer=e,i()},function(t){e.console.log(t)})},o.send(null),u},n.Sound.audioContext=new webkitAudioContext,n.Sound.destination=n.Sound.audioContext.destination):(n.Sound=n.Class.create(n.EventTarget,{initialize:function(){throw n.EventTarget.call(this),this.duration=0,new Error("Illegal Constructor")},play:function(){this._element&&this._element.play()},pause:function(){this._element&&this._element.pause()},stop:function(){this.pause(),this.currentTime=0},clone:function(){var e;if(this._element instanceof Audio)e=Object.create(n.Sound.prototype,{_element:{value:this._element.cloneNode(!1)},duration:{value:this.duration}});else{if(n.ENV.USE_FLASH_SOUND)return this;e=Object.create(n.Sound.prototype)}return n.EventTarget.call(e),e},currentTime:{get:function(){return this._element?this._element.currentTime:0},set:function(e){this._element&&(this._element.currentTime=e)}},volume:{get:function(){return this._element?this._element.volume:1},set:function(e){this._element&&(this._element.volume=e)}}}),n.Sound.load=function(t,r){if(r==null){var i=n.Game.findExt(t);i?r="audio/"+i:r=""}r=r.replace("mp3","mpeg").replace("m4a","mp4");var s=Object.create(n.Sound.prototype);n.EventTarget.call(s);var o=new Audio;if(!n.ENV.SOUND_ENABLED_ON_MOBILE_SAFARI&&n.ENV.VENDOR_PREFIX==="webkit"&&n.ENV.TOUCH_ENABLED)e.setTimeout(function(){s.dispatchEvent(new n.Event("load"))},0);else if(!n.ENV.USE_FLASH_SOUND&&o.canPlayType(r))o.src=t,o.load(),o.autoplay=!1,o.onerror=function(){throw new Error("Cannot load an asset: "+o.src)},o.addEventListener("canplaythrough",function(){s.duration=o.duration,s.dispatchEvent(new n.Event("load"))},!1),s._element=o;else if(r==="audio/mpeg"){var u=document.createElement("embed"),a="enchant-audio"+n.Game.instance._soundID++;u.width=u.height=1,u.name=a,u.src="sound.swf?id="+a+"&src="+t,u.allowscriptaccess="always",u.style.position="absolute",u.style.left="-1px",s.addEventListener("load",function(){Object.defineProperties(u,{currentTime:{get:function(){return u.getCurrentTime()},set:function(e){u.setCurrentTime(e)}},volume:{get:function(){return u.getVolume()},set:function(e){u.setVolume(e)}}}),s._element=u,s.duration=u.getDuration()}),n.Game.instance._element.appendChild(u),n.Sound[a]=s}else e.setTimeout(function(){s.dispatchEvent(new n.Event("load"))},0);return s}),n.Easing={LINEAR:function(e,t,n,r){return n*e/r+t},SWING:function(e,t,n,r){return n*(.5-Math.cos(e/r*Math.PI)/2)+t},QUAD_EASEIN:function(e,t,n,r){return n*(e/=r)*e+t},QUAD_EASEOUT:function(e,t,n,r){return-n*(e/=r)*(e-2)+t},QUAD_EASEINOUT:function(e,t,n,r){return(e/=r/2)<1?n/2*e*e+t:-n/2*(--e*(e-2)-1)+t},CUBIC_EASEIN:function(e,t,n,r){return n*(e/=r)*e*e+t},CUBIC_EASEOUT:function(e,t,n,r){return n*((e=e/r-1)*e*e+1)+t},CUBIC_EASEINOUT:function(e,t,n,r){return(e/=r/2)<1?n/2*e*e*e+t:n/2*((e-=2)*e*e+2)+t},QUART_EASEIN:function(e,t,n,r){return n*(e/=r)*e*e*e+t},QUART_EASEOUT:function(e,t,n,r){return-n*((e=e/r-1)*e*e*e-1)+t},QUART_EASEINOUT:function(e,t,n,r){return(e/=r/2)<1?n/2*e*e*e*e+t:-n/2*((e-=2)*e*e*e-2)+t},QUINT_EASEIN:function(e,t,n,r){return n*(e/=r)*e*e*e*e+t},QUINT_EASEOUT:function(e,t,n,r){return n*((e=e/r-1)*e*e*e*e+1)+t},QUINT_EASEINOUT:function(e,t,n,r){return(e/=r/2)<1?n/2*e*e*e*e*e+t:n/2*((e-=2)*e*e*e*e+2)+t},SIN_EASEIN:function(e,t,n,r){return-n*Math.cos(e/r*(Math.PI/2))+n+t},SIN_EASEOUT:function(e,t,n,r){return n*Math.sin(e/r*(Math.PI/2))+t},SIN_EASEINOUT:function(e,t,n,r){return-n/2*(Math.cos(Math.PI*e/r)-1)+t},CIRC_EASEIN:function(e,t,n,r){return-n*(Math.sqrt(1-(e/=r)*e)-1)+t},CIRC_EASEOUT:function(e,t,n,r){return n*Math.sqrt(1-(e=e/r-1)*e)+t},CIRC_EASEINOUT:function(e,t,n,r){return(e/=r/2)<1?-n/2*(Math.sqrt(1-e*e)-1)+t:n/2*(Math.sqrt(1-(e-=2)*e)+1)+t},ELASTIC_EASEIN:function(e,t,n,r,i,s){if(e===0)return t;if((e/=r)===1)return t+n;s||(s=r*.3);var o;return!i||i<Math.abs(n)?(i=n,o=s/4):o=s/(2*Math.PI)*Math.asin(n/i),-(i*Math.pow(2,10*(e-=1))*Math.sin((e*r-o)*2*Math.PI/s))+t},ELASTIC_EASEOUT:function(e,t,n,r,i,s){if(e===0)return t;if((e/=r)===1)return t+n;s||(s=r*.3);var o;return!i||i<Math.abs(n)?(i=n,o=s/4):o=s/(2*Math.PI)*Math.asin(n/i),i*Math.pow(2,-10*e)*Math.sin((e*r-o)*2*Math.PI/s)+n+t},ELASTIC_EASEINOUT:function(e,t,n,r,i,s){if(e===0)return t;if((e/=r/2)===2)return t+n;s||(s=r*.3*1.5);var o;return!i||i<Math.abs(n)?(i=n,o=s/4):o=s/(2*Math.PI)*Math.asin(n/i),e<1?-0.5*i*Math.pow(2,10*(e-=1))*Math.sin((e*r-o)*2*Math.PI/s)+t:i*Math.pow(2,-10*(e-=1))*Math.sin((e*r-o)*2*Math.PI/s)*.5+n+t},BOUNCE_EASEOUT:function(e,t,n,r){return(e/=r)<1/2.75?n*7.5625*e*e+t:e<2/2.75?n*(7.5625*(e-=1.5/2.75)*e+.75)+t:e<2.5/2.75?n*(7.5625*(e-=2.25/2.75)*e+.9375)+t:n*(7.5625*(e-=2.625/2.75)*e+.984375)+t},BOUNCE_EASEIN:function(e,t,r,i){return r-n.Easing.BOUNCE_EASEOUT(i-e,0,r,i)+t},BOUNCE_EASEINOUT:function(e,t,r,i){return e<i/2?n.Easing.BOUNCE_EASEIN(e*2,0,r,i)*.5+t:n.Easing.BOUNCE_EASEOUT(e*2-i,0,r,i)*.5+r*.5+t},BACK_EASEIN:function(e,n,r,i,s){return s===t&&(s=1.70158),r*(e/=i)*e*((s+1)*e-s)+n},BACK_EASEOUT:function(e,n,r,i,s){return s===t&&(s=1.70158),r*((e=e/i-1)*e*((s+1)*e+s)+1)+n},BACK_EASEINOUT:function(e,n,r,i,s){return s===t&&(s=1.70158),(e/=i/2)<1?r/2*e*e*(((s*=1.525)+1)*e-s)+n:r/2*((e-=2)*e*(((s*=1.525)+1)*e+s)+2)+n},EXPO_EASEIN:function(e,t,n,r){return e===0?t:n*Math.pow(2,10*(e/r-1))+t},EXPO_EASEOUT:function(e,t,n,r){return e===r?t+n:n*(-Math.pow(2,-10*e/r)+1)+t},EXPO_EASEINOUT:function(e,t,n,r){return e===0?t:e===r?t+n:(e/=r/2)<1?n/2*Math.pow(2,10*(e-1))+t:n/2*(-Math.pow(2,-10*--e)+2)+t}},n.ActionEventTarget=n.Class.create(n.EventTarget,{initialize:function(){n.EventTarget.apply(this,arguments)},dispatchEvent:function(e){var t;this.node?(t=this.node,e.target=t,e.localX=e.x-t._offsetX,e.localY=e.y-t._offsetY):this.node=null,this["on"+e.type]!=null&&this["on"+e.type].call(t,e);var n=this._listeners[e.type];if(n!=null){n=n.slice();for(var r=0,i=n.length;r<i;r++)n[r].call(t,e)}}}),n.Timeline=n.Class.create(n.EventTarget,{initialize:function(e){n.EventTarget.call(this),this.node=e,this.queue=[],this.paused=!1,this.looped=!1,this.isFrameBased=!0,this._parallel=null,this._activated=!1,this.addEventListener(n.Event.ENTER_FRAME,this.tick)},_deactivateTimeline:function(){this._activated&&(this._activated=!1,this.node.removeEventListener("enterframe",this._nodeEventListener))},_activateTimeline:function(){!this._activated&&!this.paused&&(this.node.addEventListener("enterframe",this._nodeEventListener),this._activated=!0)},setFrameBased:function(){this.isFrameBased=!0},setTimeBased:function(){this.isFrameBased=!1},next:function(e){var t,r=this.queue.shift();t=new n.Event("actionend"),t.timeline=this,r.dispatchEvent(t);if(this.queue.length===0){this._activated=!1,this.node.removeEventListener("enterframe",this._nodeEventListener);return}this.looped?(t=new n.Event("removedfromtimeline"),t.timeline=this,r.dispatchEvent(t),r.frame=0,this.add(r)):(t=new n.Event("removedfromtimeline"),t.timeline=this,r.dispatchEvent(t));if(e>0||this.queue[0]&&this.queue[0].time===0){var i=new n.Event("enterframe");i.elapsed=e,this.dispatchEvent(i)}},tick:function(e){if(this.paused)return;if(this.queue.length>0){var t=this.queue[0];if(t.frame===0){var r;r=new n.Event("actionstart"),r.timeline=this,t.dispatchEvent(r)}var i=new n.Event("actiontick");i.timeline=this,this.isFrameBased?i.elapsed=1:i.elapsed=e.elapsed,t.dispatchEvent(i)}},add:function(e){if(!this._activated){var t=this;this._nodeEventListener=function(e){t.dispatchEvent(e)},this.node.addEventListener("enterframe",this._nodeEventListener),this._activated=!0}this._parallel?(this._parallel.actions.push(e),this._parallel=null):this.queue.push(e),e.frame=0;var r=new n.Event("addedtotimeline");return r.timeline=this,e.dispatchEvent(r),r=new n.Event("actionadded"),r.action=e,this.dispatchEvent(r),this},action:function(e){return this.add(new n.Action(e))},tween:function(e){return this.add(new n.Tween(e))},clear:function(){var e=new n.Event("removedfromtimeline");e.timeline=this;for(var t=0,r=this.queue.length;t<r;t++)this.queue[t].dispatchEvent(e);return this.queue=[],this._deactivateTimeline(),this},skip:function(e){var t=new n.Event("enterframe");this.isFrameBased?t.elapsed=1:(t.elapsed=e,e=1);while(e--)this.dispatchEvent(t);return this},pause:function(){return this.paused||(this.paused=!0,this._deactivateTimeline()),this},resume:function(){return this.paused&&(this.paused=!1,this._activateTimeline()),this},loop:function(){return this.looped=!0,this},unloop:function(){return this.looped=!1,this},delay:function(e){return this.add(new n.Action({time:e})),this},wait:function(e){return this},then:function(e){var t=this;return this.add(new n.Action({onactiontick:function(n){e.call(t.node)},time:0})),this},exec:function(e){this.then(e)},cue:function(e){var t=0;for(var n in e)e.hasOwnProperty(n)&&(this.delay(n-t),this.then(e[n]),t=n)},repeat:function(e,t){return this.add(new n.Action({onactiontick:function(t){e.call(this)},time:t})),this},and:function(){var e=this.queue.pop();if(e instanceof n.ParallelAction)this._parallel=e,this.queue.push(e);else{var t=new n.ParallelAction;t.actions.push(e),this.queue.push(t),this._parallel=t}return this},or:function(){return this},doAll:function(e){return this},waitAll:function(){return this},waitUntil:function(e){var t=this;return this.add(new n.Action({onactionstart:e,onactiontick:function(n){e.call(this)&&t.next()}})),this},fadeTo:function(e,t,n){return this.tween({opacity:e,time:t,easing:n}),this},fadeIn:function(e,t){return this.fadeTo(1,e,t)},fadeOut:function(e,t){return this.fadeTo(0,e,t)},moveTo:function(e,t,n,r){return this.tween({x:e,y:t,time:n,easing:r})},moveX:function(e,t,n){return this.tween({x:e,time:t,easing:n})},moveY:function(e,t,n){return this.tween({y:e,time:t,easing:n})},moveBy:function(e,t,n,r){return this.tween({x:function(){return this.x+e},y:function(){return this.y+t},time:n,easing:r})},hide:function(){return this.then(function(){this.opacity=0})},show:function(){return this.then(function(){this.opacity=1})},removeFromScene:function(){return this.then(function(){this.scene.removeChild(this)})},scaleTo:function(e,t,n){return typeof n=="number"?this.tween({scaleX:arguments[0],scaleY:arguments[1],time:arguments[2],easing:arguments[3]}):this.tween({scaleX:e,scaleY:e,time:t,easing:n})},scaleBy:function(e,t,n){return typeof n=="number"?this.tween({scaleX:function(){return this.scaleX*arguments[0]},scaleY:function(){return this.scaleY*arguments[1]},time:arguments[2],easing:arguments[3]}):this.tween({scaleX:function(){return this.scaleX*e},scaleY:function(){return this.scaleY*e},time:t,easing:n})},rotateTo:function(e,t,n){return this.tween({rotation:e,time:t,easing:n})},rotateBy:function(e,t,n){return this.tween({rotation:function(){return this.rotation+e},time:t,easing:n})}}),n.Action=n.Class.create(n.ActionEventTarget,{initialize:function(e){n.ActionEventTarget.call(this),this.time=null,this.frame=0;for(var t in e)e.hasOwnProperty(t)&&e[t]!=null&&(this[t]=e[t]);var r=this;this.timeline=null,this.node=null,this.addEventListener(n.Event.ADDED_TO_TIMELINE,function(e){r.timeline=e.timeline,r.node=e.timeline.node,r.frame=0}),this.addEventListener(n.Event.REMOVED_FROM_TIMELINE,function(){r.timeline=null,r.node=null,r.frame=0}),this.addEventListener(n.Event.ACTION_TICK,function(e){var t=r.time-(r.frame+e.elapsed);r.time!=null&&t<=0?(r.frame=r.time,e.timeline.next(-t)):r.frame+=e.elapsed})}}),n.ParallelAction=n.Class.create(n.Action,{initialize:function(e){n.Action.call(this,e);var t=this.timeline,r=this.node;this.actions=[],this.endedActions=[];var i=this;this.addEventListener(n.Event.ACTION_START,function(e){for(var t=0,n=i.actions.length;t<n;t++)i.actions[t].dispatchEvent(e)}),this.addEventListener(n.Event.ACTION_TICK,function(e){var t,r,s={next:function(e){var s=i.actions[t];i.actions.splice(t--,1),r=i.actions.length,i.endedActions.push(s);var o=new n.Event("actionend");o.timeline=this,s.dispatchEvent(o),o=new n.Event("removedfromtimeline"),o.timeline=this,s.dispatchEvent(o)}},o=new n.Event("actiontick");o.timeline=s,o.elapsed=e.elapsed;for(t=0,r=i.actions.length;t<r;t++)i.actions[t].dispatchEvent(o);i.actions.length===0&&e.timeline.next()}),this.addEventListener(n.Event.ADDED_TO_TIMELINE,function(e){for(var t=0,n=i.actions.length;t<n;t++)i.actions[t].dispatchEvent(e)}),this.addEventListener(n.Event.REMOVED_FROM_TIMELINE,function(){this.actions=this.endedActions,this.endedActions=[]})}}),n.Tween=n.Class.create(n.Action,{initialize:function(e){var t={},r={};n.Action.call(this,e),this.easing==null&&(this.easing=function(e,t,n,r){return n*e/r+t});var i=this;this.addEventListener(n.Event.ACTION_START,function(){var n=["frame","time","callback","onactiontick","onactionstart","onactionend"];for(var s in e)if(e.hasOwnProperty(s)){var o;typeof e[s]=="function"?o=e[s].call(i.node):o=e[s],n.indexOf(s)===-1&&(t[s]=i.node[s],r[s]=o)}}),this.addEventListener(n.Event.ACTION_TICK,function(e){var n=i.time===0?1:i.easing(Math.min(i.time,i.frame+e.elapsed),0,1,i.time)-i.easing(i.frame,0,1,i.time);for(var s in r)if(r.hasOwnProperty(s)){if(typeof this[s]=="undefined")continue;i.node[s]+=(r[s]-t[s])*n,Math.abs(i.node[s])<1e-7&&(i.node[s]=0)}})}})})(window);