diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 8804286..a0cc614 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -1,14 +1,14 @@ -/** - * @license - * pixi.js - v1.5.0 - * Copyright (c) 2012-2014, Mat Groves - * http://goodboydigital.com/ - * - * Compiled: 2014-03-22 - * - * pixi.js is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license.php - */ +/** + * @license + * pixi.js - v1.5.0 + * Copyright (c) 2012-2014, Mat Groves + * http://goodboydigital.com/ + * + * Compiled: 2014-03-22 + * + * pixi.js is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license.php + */ /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -16,7 +16,7 @@ (function(){ var root = this; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -70,7 +70,7 @@ PIXI.AUTO_PREVENT_DEFAULT = true; PIXI.RAD_TO_DEG = 180 / Math.PI; -PIXI.DEG_TO_RAD = Math.PI / 180; +PIXI.DEG_TO_RAD = Math.PI / 180; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -120,7 +120,7 @@ this.y = y || ( (y !== 0) ? this.x : 0 ) ; }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -207,7 +207,7 @@ // constructor PIXI.Rectangle.prototype.constructor = PIXI.Rectangle; -PIXI.EmptyRectangle = new PIXI.Rectangle(0,0,0,0); +PIXI.EmptyRectangle = new PIXI.Rectangle(0,0,0,0); /** * @author Adrien Brault */ @@ -285,7 +285,7 @@ // constructor PIXI.Polygon.prototype.constructor = PIXI.Polygon; - + /** * @author Chad Engler */ @@ -360,7 +360,7 @@ // constructor PIXI.Circle.prototype.constructor = PIXI.Circle; - + /** * @author Chad Engler */ @@ -453,7 +453,7 @@ // constructor PIXI.Ellipse.prototype.constructor = PIXI.Ellipse; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -545,7 +545,7 @@ return array;//[this.a, this.b, this.tx, this.c, this.d, this.ty, 0, 0, 1]; }; -PIXI.identityMatrix = new PIXI.Matrix(); +PIXI.identityMatrix = new PIXI.Matrix(); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1159,7 +1159,7 @@ this.position.y = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1605,7 +1605,7 @@ renderSession.maskManager.popMask(renderSession.context); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1690,7 +1690,7 @@ else { this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); + this.texture.on( 'update', this.onTextureUpdateBind ); } this.renderable = true; @@ -2077,7 +2077,7 @@ var texture = PIXI.Texture.fromImage(imageId, crossorigin, scaleMode); return new PIXI.Sprite(texture); }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -2254,7 +2254,7 @@ // context.restore(); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2421,7 +2421,7 @@ } } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2432,7 +2432,7 @@ this.visible = true; this.renderable = true; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2802,7 +2802,7 @@ }; PIXI.Text.heightCache = {}; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2999,7 +2999,7 @@ }; PIXI.BitmapText.fonts = {}; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3062,7 +3062,7 @@ }; // constructor -PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; +PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3280,18 +3280,18 @@ this.interactionDOMElement.style['-ms-content-zooming'] = ''; this.interactionDOMElement.style['-ms-touch-action'] = ''; - this.interactionDOMElement.removeEventListener('mousemove', this.onMouseMove, true); - this.interactionDOMElement.removeEventListener('mousedown', this.onMouseDown, true); - this.interactionDOMElement.removeEventListener('mouseout', this.onMouseOut, true); + this.interactionDOMElement.off('mousemove', this.onMouseMove, true); + this.interactionDOMElement.off('mousedown', this.onMouseDown, true); + this.interactionDOMElement.off('mouseout', this.onMouseOut, true); // aint no multi touch just yet! - this.interactionDOMElement.removeEventListener('touchstart', this.onTouchStart, true); - this.interactionDOMElement.removeEventListener('touchend', this.onTouchEnd, true); - this.interactionDOMElement.removeEventListener('touchmove', this.onTouchMove, true); + this.interactionDOMElement.off('touchstart', this.onTouchStart, true); + this.interactionDOMElement.off('touchend', this.onTouchEnd, true); + this.interactionDOMElement.off('touchmove', this.onTouchMove, true); this.interactionDOMElement = null; - window.removeEventListener('mouseup', this.onMouseUp, true); + window.off('mouseup', this.onMouseUp, true); }; /** @@ -3778,7 +3778,7 @@ this.touchs[touchEvent.identifier] = null; } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3914,7 +3914,7 @@ { return this.interactionManager.mouse.global; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4112,18 +4112,19 @@ return result; } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * https://github.com/mrdoob/eventtarget.js/ - * THankS mr DOob! + * @author Chad Engler https://github.com/englercj @Rolnaaba */ /** - * Adds event emitter functionality to a class + * Originally based on https://github.com/mrdoob/eventtarget.js/ from mr DOob. + * Currently takes inspiration from the nodejs EventEmitter, and EventEmitter3 + */ + +/** + * Mixins event emitter functionality to a class * * @class EventTarget * @example @@ -4132,95 +4133,156 @@ * } * * var em = new MyEmitter(); - * em.emit({ type: 'eventName', data: 'some data' }); + * em.emit('eventName', 'some data', 'some moar data', {}, null, ...); */ -PIXI.EventTarget = function () { +PIXI.EventTarget = function() { + this._listeners = this._listeners || {}; /** - * Holds all the listeners + * Return a list of assigned event listeners. * - * @property listeners - * @type Object + * @param eventName {String} The events that should be listed. + * @returns {Array} + * @api public */ - var listeners = {}; - - /** - * Adds a listener for a specific event - * - * @method addEventListener - * @param type {string} A string representing the event type to listen for. - * @param listener {function} The callback function that will be fired when the event occurs - */ - this.addEventListener = this.on = function ( type, listener ) { - - - if ( listeners[ type ] === undefined ) { - - listeners[ type ] = []; - - } - - if ( listeners[ type ].indexOf( listener ) === - 1 ) { - - listeners[ type ].push( listener ); - } - + this.listeners = function listeners(eventName) { + return Array.apply(this, this._listeners[eventName] || []); }; /** - * Fires the event, ie pretends that the event has happened + * Emit an event to all registered event listeners. * - * @method dispatchEvent - * @param event {Event} the event object + * @param eventName {String} The name of the event. + * @returns {Boolean} Indication if we've emitted an event. + * @api public */ - this.dispatchEvent = this.emit = function ( event ) { + this.emit = function emit(eventName, data) { + if(!data || data.__isEventObject !== true) + data = new PIXI.Event(this, eventName, data); - if ( !listeners[ event.type ] || !listeners[ event.type ].length ) { + if(this._listeners && this._listeners[eventName]) { + var listeners = this._listeners[eventName], + length = listeners.length, + fn = listeners[0], + i; - return; + for(i = 0; i < length; fn = listeners[++i]) { + //call the event listener + fn.call(this, data); + //remove the listener if this is a "once" event + if(fn.__isOnce) + this.off(eventName, fn); + + //if "stopImmediatePropagation" is called, stop calling all events + if(data.stoppedImmediate) + return; + } + + //if "stopPropagation" is called then don't bubble the event + if(data.stopped) + return; } - for(var i = 0, l = listeners[ event.type ].length; i < l; i++) { - - listeners[ event.type ][ i ]( event ); - + if(this.parent && this.parent.emit) { + this.parent.emit.call(this.parent, eventName, data); } + return true; }; /** - * Removes the specified listener that was assigned to the specified event type + * Register a new EventListener for the given event. * - * @method removeEventListener - * @param type {string} A string representing the event type which will have its listener removed - * @param listener {function} The callback function that was be fired when the event occured + * @param eventName {String} Name of the event. + * @param callback {Functon} fn Callback function. + * @api public */ - this.removeEventListener = this.off = function ( type, listener ) { + this.on = function on(eventName, fn) { + if(!this._listeners[eventName]) + this._listeners[eventName] = []; - var index = listeners[ type ].indexOf( listener ); + this._listeners[eventName].push(fn); - if ( index !== - 1 ) { - - listeners[ type ].splice( index, 1 ); - - } - + return this; }; /** - * Removes all the listeners that were active for the specified event type + * Add an EventListener that's only called once. * - * @method removeAllEventListeners - * @param type {string} A string representing the event type which will have all its listeners removed + * @param eventName {String} Name of the event. + * @param callback {Function} Callback function. + * @api public */ - this.removeAllEventListeners = function( type ) { - var a = listeners[type]; - if (a) - a.length = 0; - }; + this.once = function once(eventName, fn) { + fn.__isOnce = true; + return this.on(eventName, fn); + }; + + /** + * Remove event listeners. + * + * @param eventName {String} The event we want to remove. + * @param callback {Function} The listener that we need to find. + * @api public + */ + this.off = function off(eventName, fn) { + if(!this._listeners[eventName]) + return this; + + var index = this._listeners[eventName].indexOf(fn); + + if(index !== -1) { + this._listeners[eventName].splice(index, 1); + } + + return this; + }; + + /** + * Remove all listeners or only the listeners for the specified event. + * + * @param eventName {String} The event want to remove all listeners for. + * @api public + */ + this.removeAllListeners = function removeAllListeners(eventName) { + if(!this._listeners[eventName]) + return this; + + this._listeners[eventName].length = 0; + + return this; + }; + + /** + * Alias methods names because people roll like that. + */ + this.removeEventListener = this.off; + this.addEventListener = this.on; + this.dispatchEvent = this.emit; }; +PIXI.Event = function(target, name, data) { + this.__isEventObject = true; + + this.stopped = false; + this.stoppedImmediate = false; + + this.target = target; + this.type = name; + this.data = data; + + this.timeStamp = Date.now(); +}; + +PIXI.Event.prototype.stopPropagation = function() { + this.stopped = true; +}; + +PIXI.Event.prototype.stopImmediatePropagation = function() { + this.stoppedImmediate = true; +}; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4260,7 +4322,7 @@ return new PIXI.CanvasRenderer(width, height, view, transparent); }; - + /* PolyK library url: http://polyk.ivank.net @@ -4430,7 +4492,7 @@ { return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) === sign; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4488,7 +4550,7 @@ return shaderProgram; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * @author Richard Davey http://www.photonstorm.com @photonstorm @@ -4829,7 +4891,7 @@ ' vColor = vec4(color * aColor.x, aColor.x);', '}' ]; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * @author Richard Davey http://www.photonstorm.com @photonstorm @@ -4976,7 +5038,7 @@ this.attributes = null; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5057,7 +5119,7 @@ this.program = program; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5162,7 +5224,7 @@ this.attribute = null; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5703,7 +5765,7 @@ r, g, b, alpha); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6246,8 +6308,8 @@ // deal with losing context.. // remove listeners - this.view.removeEventListener('webglcontextlost', this.contextLost); - this.view.removeEventListener('webglcontextrestored', this.contextRestoredLost); + this.view.off('webglcontextlost', this.contextLost); + this.view.off('webglcontextrestored', this.contextRestoredLost); PIXI.glContexts[this.glContextId] = null; @@ -6272,7 +6334,7 @@ PIXI.WebGLRenderer.glContextId = 0; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6369,7 +6431,7 @@ { this.maskStack = null; this.gl = null; -}; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6528,7 +6590,7 @@ this.gl = null; }; - + /** * @author Mat Groves * @@ -7023,7 +7085,7 @@ this.gl = null; }; - + /** * @author Mat Groves * @@ -7374,7 +7436,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -7833,7 +7895,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -7918,7 +7980,7 @@ this.frameBuffer = null; this.texture = null; }; - + /** * @author Mat Groves * @@ -7966,7 +8028,7 @@ PIXI.CanvasMaskManager.prototype.popMask = function(context) { context.restore(); -}; +}; /** * @author Mat Groves @@ -8208,7 +8270,7 @@ PIXI.CanvasTinter.tintMethod = PIXI.CanvasTinter.canUseMultiply ? PIXI.CanvasTinter.tintWithMultiply : PIXI.CanvasTinter.tintWithPerPixel; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -8598,7 +8660,7 @@ this.height = this.canvas.height = height; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -8836,7 +8898,7 @@ } } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9485,7 +9547,7 @@ PIXI.Graphics.RECT = 1; PIXI.Graphics.CIRC = 2; PIXI.Graphics.ELIP = 3; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -9558,7 +9620,7 @@ else { this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); + this.texture.on( 'update', this.onTextureUpdateBind ); } this.renderable = true; @@ -9597,7 +9659,7 @@ PIXI.Strip.prototype.onTextureUpdate = function() { this.updateFrame = true; -}; +}; /* @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9787,7 +9849,7 @@ this.texture = texture; this.updateFrame = true; }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -10262,7 +10324,7 @@ } this.refreshTexture = false; this.tilingTexture.baseTexture._powerOf2 = true; -}; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi @@ -11733,7 +11795,7 @@ slot.sprites[descriptor.name] = sprite; return sprite; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11828,7 +11890,7 @@ // add it to somewhere... PIXI.texturesToUpdate.push(scope); - scope.dispatchEvent( { type: 'loaded', content: scope } ); + scope.emit('loaded', { content: scope }); }; } @@ -11925,7 +11987,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11995,7 +12057,7 @@ else { var scope = this; - baseTexture.addEventListener('loaded', function(){ scope.onBaseTextureLoaded(); }); + baseTexture.on('loaded', function(){ scope.onBaseTextureLoaded(); }); } }; @@ -12011,13 +12073,13 @@ PIXI.Texture.prototype.onBaseTextureLoaded = function() { var baseTexture = this.baseTexture; - baseTexture.removeEventListener( 'loaded', this.onLoaded ); + baseTexture.off( 'loaded', this.onLoaded ); if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); this.setFrame(this.frame); - this.scope.dispatchEvent( { type: 'update', content: this } ); + this.scope.emit('update', { content: this }); }; /** @@ -12053,7 +12115,7 @@ PIXI.Texture.frameUpdates.push(this); - //this.dispatchEvent( { type: 'update', content: this } ); + //this.emit('update', { content: this }); }; PIXI.Texture.prototype._updateWebGLuvs = function() @@ -12183,7 +12245,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12401,7 +12463,7 @@ PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12517,7 +12579,7 @@ var scope = this; function onLoad(evt) { - scope.onAssetLoaded(evt.content); + scope.onAssetLoaded(evt.data.content); } this.loadCount = this.assetURLs.length; @@ -12538,7 +12600,7 @@ var loader = new Constructor(fileName, this.crossorigin); - loader.addEventListener('loaded', onLoad); + loader.on('loaded', onLoad); loader.load(); } }; @@ -12552,16 +12614,16 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function(loader) { this.loadCount--; - this.dispatchEvent({ type: 'onProgress', content: this, loader: loader }); + this.emit('onProgress', { content: this, loader: loader }); if (this.onProgress) this.onProgress(loader); if (!this.loadCount) { - this.dispatchEvent({type: 'onComplete', content: this}); + this.emit('onComplete', { content: this }); if(this.onComplete) this.onComplete(); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12656,7 +12718,7 @@ var frameData = this.json.frames; this.texture = image.texture.baseTexture; - image.addEventListener('loaded', function() { + image.on('loaded', function() { scope.onLoaded(); }); @@ -12714,8 +12776,7 @@ */ PIXI.JsonLoader.prototype.onLoaded = function () { this.loaded = true; - this.dispatchEvent({ - type: 'loaded', + this.emit('loaded', { content: this }); }; @@ -12727,11 +12788,10 @@ * @private */ PIXI.JsonLoader.prototype.onError = function () { - this.dispatchEvent({ - type: 'error', + this.emit('error', { content: this }); -}; +}; /** * @author Martin Kelm http://mkelm.github.com */ @@ -12879,7 +12939,7 @@ this.currentImageId = 0; for (j = 0; j < this.images.length; j++) { - this.images[j].addEventListener('loaded', selfOnLoaded); + this.images[j].on('loaded', selfOnLoaded); } this.images[this.currentImageId].load(); @@ -12904,10 +12964,7 @@ this.images[this.currentImageId].load(); } else { this.loaded = true; - this.dispatchEvent({ - type: 'loaded', - content: this - }); + this.emit('loaded', { content: this }); } }; @@ -12917,12 +12974,9 @@ * @private */ PIXI.AtlasLoader.prototype.onError = function () { - this.dispatchEvent({ - type: 'error', - content: this - }); + this.emit('error', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13003,8 +13057,8 @@ PIXI.SpriteSheetLoader.prototype.load = function () { var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.addEventListener('loaded', function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); @@ -13017,12 +13071,11 @@ * @private */ PIXI.SpriteSheetLoader.prototype.onLoaded = function () { - this.dispatchEvent({ - type: 'loaded', + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13071,7 +13124,7 @@ if(!this.texture.baseTexture.hasLoaded) { var scope = this; - this.texture.baseTexture.addEventListener('loaded', function() + this.texture.baseTexture.on('loaded', function() { scope.onLoaded(); }); @@ -13090,7 +13143,7 @@ */ PIXI.ImageLoader.prototype.onLoaded = function() { - this.dispatchEvent({type: 'loaded', content: this}); + this.emit('loaded', { content: this }); }; /** @@ -13128,7 +13181,7 @@ if(!this.texture.baseTexture.hasLoaded) { var scope = this; - this.texture.baseTexture.addEventListener('loaded', function() { + this.texture.baseTexture.on('loaded', function() { scope.onLoaded(); }); } @@ -13137,7 +13190,7 @@ this.onLoaded(); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13294,7 +13347,7 @@ PIXI.BitmapText.fonts[data.font] = data; var scope = this; - image.addEventListener('loaded', function() { + image.on('loaded', function() { scope.onLoaded(); }); image.load(); @@ -13310,9 +13363,9 @@ */ PIXI.BitmapFontLoader.prototype.onLoaded = function() { - this.dispatchEvent({type: 'loaded', content: this}); + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi @@ -13377,8 +13430,8 @@ var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.addEventListener("loaded", function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); @@ -13392,10 +13445,10 @@ */ PIXI.SpineLoader.prototype.onLoaded = function () { this.loaded = true; - this.dispatchEvent({type: "loaded", content: this}); + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13442,7 +13495,7 @@ */ this.fragmentSrc = fragmentSrc || []; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13535,7 +13588,7 @@ } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13594,7 +13647,7 @@ set: function(value) { this.uniforms.matrix.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13646,7 +13699,7 @@ this.uniforms.gray.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13775,7 +13828,7 @@ this.uniforms.offset.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13837,7 +13890,7 @@ this.uniforms.pixelSize.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13891,7 +13944,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13944,7 +13997,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14012,7 +14065,7 @@ this.blurYFilter.blur = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14065,7 +14118,7 @@ this.uniforms.invert.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14119,7 +14172,7 @@ this.uniforms.sepia.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14220,7 +14273,7 @@ this.dirty = true; this.uniforms.angle.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14272,7 +14325,7 @@ this.uniforms.step.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * original filter: https://github.com/evanw/glfx.js/blob/master/src/filters/fun/dotscreen.js @@ -14358,7 +14411,7 @@ this.dirty = true; this.uniforms.angle.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14425,7 +14478,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14475,7 +14528,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 8804286..a0cc614 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -1,14 +1,14 @@ -/** - * @license - * pixi.js - v1.5.0 - * Copyright (c) 2012-2014, Mat Groves - * http://goodboydigital.com/ - * - * Compiled: 2014-03-22 - * - * pixi.js is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license.php - */ +/** + * @license + * pixi.js - v1.5.0 + * Copyright (c) 2012-2014, Mat Groves + * http://goodboydigital.com/ + * + * Compiled: 2014-03-22 + * + * pixi.js is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license.php + */ /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -16,7 +16,7 @@ (function(){ var root = this; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -70,7 +70,7 @@ PIXI.AUTO_PREVENT_DEFAULT = true; PIXI.RAD_TO_DEG = 180 / Math.PI; -PIXI.DEG_TO_RAD = Math.PI / 180; +PIXI.DEG_TO_RAD = Math.PI / 180; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -120,7 +120,7 @@ this.y = y || ( (y !== 0) ? this.x : 0 ) ; }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -207,7 +207,7 @@ // constructor PIXI.Rectangle.prototype.constructor = PIXI.Rectangle; -PIXI.EmptyRectangle = new PIXI.Rectangle(0,0,0,0); +PIXI.EmptyRectangle = new PIXI.Rectangle(0,0,0,0); /** * @author Adrien Brault */ @@ -285,7 +285,7 @@ // constructor PIXI.Polygon.prototype.constructor = PIXI.Polygon; - + /** * @author Chad Engler */ @@ -360,7 +360,7 @@ // constructor PIXI.Circle.prototype.constructor = PIXI.Circle; - + /** * @author Chad Engler */ @@ -453,7 +453,7 @@ // constructor PIXI.Ellipse.prototype.constructor = PIXI.Ellipse; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -545,7 +545,7 @@ return array;//[this.a, this.b, this.tx, this.c, this.d, this.ty, 0, 0, 1]; }; -PIXI.identityMatrix = new PIXI.Matrix(); +PIXI.identityMatrix = new PIXI.Matrix(); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1159,7 +1159,7 @@ this.position.y = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1605,7 +1605,7 @@ renderSession.maskManager.popMask(renderSession.context); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1690,7 +1690,7 @@ else { this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); + this.texture.on( 'update', this.onTextureUpdateBind ); } this.renderable = true; @@ -2077,7 +2077,7 @@ var texture = PIXI.Texture.fromImage(imageId, crossorigin, scaleMode); return new PIXI.Sprite(texture); }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -2254,7 +2254,7 @@ // context.restore(); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2421,7 +2421,7 @@ } } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2432,7 +2432,7 @@ this.visible = true; this.renderable = true; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2802,7 +2802,7 @@ }; PIXI.Text.heightCache = {}; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2999,7 +2999,7 @@ }; PIXI.BitmapText.fonts = {}; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3062,7 +3062,7 @@ }; // constructor -PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; +PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3280,18 +3280,18 @@ this.interactionDOMElement.style['-ms-content-zooming'] = ''; this.interactionDOMElement.style['-ms-touch-action'] = ''; - this.interactionDOMElement.removeEventListener('mousemove', this.onMouseMove, true); - this.interactionDOMElement.removeEventListener('mousedown', this.onMouseDown, true); - this.interactionDOMElement.removeEventListener('mouseout', this.onMouseOut, true); + this.interactionDOMElement.off('mousemove', this.onMouseMove, true); + this.interactionDOMElement.off('mousedown', this.onMouseDown, true); + this.interactionDOMElement.off('mouseout', this.onMouseOut, true); // aint no multi touch just yet! - this.interactionDOMElement.removeEventListener('touchstart', this.onTouchStart, true); - this.interactionDOMElement.removeEventListener('touchend', this.onTouchEnd, true); - this.interactionDOMElement.removeEventListener('touchmove', this.onTouchMove, true); + this.interactionDOMElement.off('touchstart', this.onTouchStart, true); + this.interactionDOMElement.off('touchend', this.onTouchEnd, true); + this.interactionDOMElement.off('touchmove', this.onTouchMove, true); this.interactionDOMElement = null; - window.removeEventListener('mouseup', this.onMouseUp, true); + window.off('mouseup', this.onMouseUp, true); }; /** @@ -3778,7 +3778,7 @@ this.touchs[touchEvent.identifier] = null; } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3914,7 +3914,7 @@ { return this.interactionManager.mouse.global; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4112,18 +4112,19 @@ return result; } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * https://github.com/mrdoob/eventtarget.js/ - * THankS mr DOob! + * @author Chad Engler https://github.com/englercj @Rolnaaba */ /** - * Adds event emitter functionality to a class + * Originally based on https://github.com/mrdoob/eventtarget.js/ from mr DOob. + * Currently takes inspiration from the nodejs EventEmitter, and EventEmitter3 + */ + +/** + * Mixins event emitter functionality to a class * * @class EventTarget * @example @@ -4132,95 +4133,156 @@ * } * * var em = new MyEmitter(); - * em.emit({ type: 'eventName', data: 'some data' }); + * em.emit('eventName', 'some data', 'some moar data', {}, null, ...); */ -PIXI.EventTarget = function () { +PIXI.EventTarget = function() { + this._listeners = this._listeners || {}; /** - * Holds all the listeners + * Return a list of assigned event listeners. * - * @property listeners - * @type Object + * @param eventName {String} The events that should be listed. + * @returns {Array} + * @api public */ - var listeners = {}; - - /** - * Adds a listener for a specific event - * - * @method addEventListener - * @param type {string} A string representing the event type to listen for. - * @param listener {function} The callback function that will be fired when the event occurs - */ - this.addEventListener = this.on = function ( type, listener ) { - - - if ( listeners[ type ] === undefined ) { - - listeners[ type ] = []; - - } - - if ( listeners[ type ].indexOf( listener ) === - 1 ) { - - listeners[ type ].push( listener ); - } - + this.listeners = function listeners(eventName) { + return Array.apply(this, this._listeners[eventName] || []); }; /** - * Fires the event, ie pretends that the event has happened + * Emit an event to all registered event listeners. * - * @method dispatchEvent - * @param event {Event} the event object + * @param eventName {String} The name of the event. + * @returns {Boolean} Indication if we've emitted an event. + * @api public */ - this.dispatchEvent = this.emit = function ( event ) { + this.emit = function emit(eventName, data) { + if(!data || data.__isEventObject !== true) + data = new PIXI.Event(this, eventName, data); - if ( !listeners[ event.type ] || !listeners[ event.type ].length ) { + if(this._listeners && this._listeners[eventName]) { + var listeners = this._listeners[eventName], + length = listeners.length, + fn = listeners[0], + i; - return; + for(i = 0; i < length; fn = listeners[++i]) { + //call the event listener + fn.call(this, data); + //remove the listener if this is a "once" event + if(fn.__isOnce) + this.off(eventName, fn); + + //if "stopImmediatePropagation" is called, stop calling all events + if(data.stoppedImmediate) + return; + } + + //if "stopPropagation" is called then don't bubble the event + if(data.stopped) + return; } - for(var i = 0, l = listeners[ event.type ].length; i < l; i++) { - - listeners[ event.type ][ i ]( event ); - + if(this.parent && this.parent.emit) { + this.parent.emit.call(this.parent, eventName, data); } + return true; }; /** - * Removes the specified listener that was assigned to the specified event type + * Register a new EventListener for the given event. * - * @method removeEventListener - * @param type {string} A string representing the event type which will have its listener removed - * @param listener {function} The callback function that was be fired when the event occured + * @param eventName {String} Name of the event. + * @param callback {Functon} fn Callback function. + * @api public */ - this.removeEventListener = this.off = function ( type, listener ) { + this.on = function on(eventName, fn) { + if(!this._listeners[eventName]) + this._listeners[eventName] = []; - var index = listeners[ type ].indexOf( listener ); + this._listeners[eventName].push(fn); - if ( index !== - 1 ) { - - listeners[ type ].splice( index, 1 ); - - } - + return this; }; /** - * Removes all the listeners that were active for the specified event type + * Add an EventListener that's only called once. * - * @method removeAllEventListeners - * @param type {string} A string representing the event type which will have all its listeners removed + * @param eventName {String} Name of the event. + * @param callback {Function} Callback function. + * @api public */ - this.removeAllEventListeners = function( type ) { - var a = listeners[type]; - if (a) - a.length = 0; - }; + this.once = function once(eventName, fn) { + fn.__isOnce = true; + return this.on(eventName, fn); + }; + + /** + * Remove event listeners. + * + * @param eventName {String} The event we want to remove. + * @param callback {Function} The listener that we need to find. + * @api public + */ + this.off = function off(eventName, fn) { + if(!this._listeners[eventName]) + return this; + + var index = this._listeners[eventName].indexOf(fn); + + if(index !== -1) { + this._listeners[eventName].splice(index, 1); + } + + return this; + }; + + /** + * Remove all listeners or only the listeners for the specified event. + * + * @param eventName {String} The event want to remove all listeners for. + * @api public + */ + this.removeAllListeners = function removeAllListeners(eventName) { + if(!this._listeners[eventName]) + return this; + + this._listeners[eventName].length = 0; + + return this; + }; + + /** + * Alias methods names because people roll like that. + */ + this.removeEventListener = this.off; + this.addEventListener = this.on; + this.dispatchEvent = this.emit; }; +PIXI.Event = function(target, name, data) { + this.__isEventObject = true; + + this.stopped = false; + this.stoppedImmediate = false; + + this.target = target; + this.type = name; + this.data = data; + + this.timeStamp = Date.now(); +}; + +PIXI.Event.prototype.stopPropagation = function() { + this.stopped = true; +}; + +PIXI.Event.prototype.stopImmediatePropagation = function() { + this.stoppedImmediate = true; +}; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4260,7 +4322,7 @@ return new PIXI.CanvasRenderer(width, height, view, transparent); }; - + /* PolyK library url: http://polyk.ivank.net @@ -4430,7 +4492,7 @@ { return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) === sign; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4488,7 +4550,7 @@ return shaderProgram; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * @author Richard Davey http://www.photonstorm.com @photonstorm @@ -4829,7 +4891,7 @@ ' vColor = vec4(color * aColor.x, aColor.x);', '}' ]; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * @author Richard Davey http://www.photonstorm.com @photonstorm @@ -4976,7 +5038,7 @@ this.attributes = null; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5057,7 +5119,7 @@ this.program = program; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5162,7 +5224,7 @@ this.attribute = null; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5703,7 +5765,7 @@ r, g, b, alpha); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6246,8 +6308,8 @@ // deal with losing context.. // remove listeners - this.view.removeEventListener('webglcontextlost', this.contextLost); - this.view.removeEventListener('webglcontextrestored', this.contextRestoredLost); + this.view.off('webglcontextlost', this.contextLost); + this.view.off('webglcontextrestored', this.contextRestoredLost); PIXI.glContexts[this.glContextId] = null; @@ -6272,7 +6334,7 @@ PIXI.WebGLRenderer.glContextId = 0; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6369,7 +6431,7 @@ { this.maskStack = null; this.gl = null; -}; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6528,7 +6590,7 @@ this.gl = null; }; - + /** * @author Mat Groves * @@ -7023,7 +7085,7 @@ this.gl = null; }; - + /** * @author Mat Groves * @@ -7374,7 +7436,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -7833,7 +7895,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -7918,7 +7980,7 @@ this.frameBuffer = null; this.texture = null; }; - + /** * @author Mat Groves * @@ -7966,7 +8028,7 @@ PIXI.CanvasMaskManager.prototype.popMask = function(context) { context.restore(); -}; +}; /** * @author Mat Groves @@ -8208,7 +8270,7 @@ PIXI.CanvasTinter.tintMethod = PIXI.CanvasTinter.canUseMultiply ? PIXI.CanvasTinter.tintWithMultiply : PIXI.CanvasTinter.tintWithPerPixel; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -8598,7 +8660,7 @@ this.height = this.canvas.height = height; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -8836,7 +8898,7 @@ } } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9485,7 +9547,7 @@ PIXI.Graphics.RECT = 1; PIXI.Graphics.CIRC = 2; PIXI.Graphics.ELIP = 3; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -9558,7 +9620,7 @@ else { this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); + this.texture.on( 'update', this.onTextureUpdateBind ); } this.renderable = true; @@ -9597,7 +9659,7 @@ PIXI.Strip.prototype.onTextureUpdate = function() { this.updateFrame = true; -}; +}; /* @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9787,7 +9849,7 @@ this.texture = texture; this.updateFrame = true; }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -10262,7 +10324,7 @@ } this.refreshTexture = false; this.tilingTexture.baseTexture._powerOf2 = true; -}; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi @@ -11733,7 +11795,7 @@ slot.sprites[descriptor.name] = sprite; return sprite; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11828,7 +11890,7 @@ // add it to somewhere... PIXI.texturesToUpdate.push(scope); - scope.dispatchEvent( { type: 'loaded', content: scope } ); + scope.emit('loaded', { content: scope }); }; } @@ -11925,7 +11987,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11995,7 +12057,7 @@ else { var scope = this; - baseTexture.addEventListener('loaded', function(){ scope.onBaseTextureLoaded(); }); + baseTexture.on('loaded', function(){ scope.onBaseTextureLoaded(); }); } }; @@ -12011,13 +12073,13 @@ PIXI.Texture.prototype.onBaseTextureLoaded = function() { var baseTexture = this.baseTexture; - baseTexture.removeEventListener( 'loaded', this.onLoaded ); + baseTexture.off( 'loaded', this.onLoaded ); if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); this.setFrame(this.frame); - this.scope.dispatchEvent( { type: 'update', content: this } ); + this.scope.emit('update', { content: this }); }; /** @@ -12053,7 +12115,7 @@ PIXI.Texture.frameUpdates.push(this); - //this.dispatchEvent( { type: 'update', content: this } ); + //this.emit('update', { content: this }); }; PIXI.Texture.prototype._updateWebGLuvs = function() @@ -12183,7 +12245,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12401,7 +12463,7 @@ PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12517,7 +12579,7 @@ var scope = this; function onLoad(evt) { - scope.onAssetLoaded(evt.content); + scope.onAssetLoaded(evt.data.content); } this.loadCount = this.assetURLs.length; @@ -12538,7 +12600,7 @@ var loader = new Constructor(fileName, this.crossorigin); - loader.addEventListener('loaded', onLoad); + loader.on('loaded', onLoad); loader.load(); } }; @@ -12552,16 +12614,16 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function(loader) { this.loadCount--; - this.dispatchEvent({ type: 'onProgress', content: this, loader: loader }); + this.emit('onProgress', { content: this, loader: loader }); if (this.onProgress) this.onProgress(loader); if (!this.loadCount) { - this.dispatchEvent({type: 'onComplete', content: this}); + this.emit('onComplete', { content: this }); if(this.onComplete) this.onComplete(); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12656,7 +12718,7 @@ var frameData = this.json.frames; this.texture = image.texture.baseTexture; - image.addEventListener('loaded', function() { + image.on('loaded', function() { scope.onLoaded(); }); @@ -12714,8 +12776,7 @@ */ PIXI.JsonLoader.prototype.onLoaded = function () { this.loaded = true; - this.dispatchEvent({ - type: 'loaded', + this.emit('loaded', { content: this }); }; @@ -12727,11 +12788,10 @@ * @private */ PIXI.JsonLoader.prototype.onError = function () { - this.dispatchEvent({ - type: 'error', + this.emit('error', { content: this }); -}; +}; /** * @author Martin Kelm http://mkelm.github.com */ @@ -12879,7 +12939,7 @@ this.currentImageId = 0; for (j = 0; j < this.images.length; j++) { - this.images[j].addEventListener('loaded', selfOnLoaded); + this.images[j].on('loaded', selfOnLoaded); } this.images[this.currentImageId].load(); @@ -12904,10 +12964,7 @@ this.images[this.currentImageId].load(); } else { this.loaded = true; - this.dispatchEvent({ - type: 'loaded', - content: this - }); + this.emit('loaded', { content: this }); } }; @@ -12917,12 +12974,9 @@ * @private */ PIXI.AtlasLoader.prototype.onError = function () { - this.dispatchEvent({ - type: 'error', - content: this - }); + this.emit('error', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13003,8 +13057,8 @@ PIXI.SpriteSheetLoader.prototype.load = function () { var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.addEventListener('loaded', function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); @@ -13017,12 +13071,11 @@ * @private */ PIXI.SpriteSheetLoader.prototype.onLoaded = function () { - this.dispatchEvent({ - type: 'loaded', + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13071,7 +13124,7 @@ if(!this.texture.baseTexture.hasLoaded) { var scope = this; - this.texture.baseTexture.addEventListener('loaded', function() + this.texture.baseTexture.on('loaded', function() { scope.onLoaded(); }); @@ -13090,7 +13143,7 @@ */ PIXI.ImageLoader.prototype.onLoaded = function() { - this.dispatchEvent({type: 'loaded', content: this}); + this.emit('loaded', { content: this }); }; /** @@ -13128,7 +13181,7 @@ if(!this.texture.baseTexture.hasLoaded) { var scope = this; - this.texture.baseTexture.addEventListener('loaded', function() { + this.texture.baseTexture.on('loaded', function() { scope.onLoaded(); }); } @@ -13137,7 +13190,7 @@ this.onLoaded(); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13294,7 +13347,7 @@ PIXI.BitmapText.fonts[data.font] = data; var scope = this; - image.addEventListener('loaded', function() { + image.on('loaded', function() { scope.onLoaded(); }); image.load(); @@ -13310,9 +13363,9 @@ */ PIXI.BitmapFontLoader.prototype.onLoaded = function() { - this.dispatchEvent({type: 'loaded', content: this}); + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi @@ -13377,8 +13430,8 @@ var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.addEventListener("loaded", function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); @@ -13392,10 +13445,10 @@ */ PIXI.SpineLoader.prototype.onLoaded = function () { this.loaded = true; - this.dispatchEvent({type: "loaded", content: this}); + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13442,7 +13495,7 @@ */ this.fragmentSrc = fragmentSrc || []; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13535,7 +13588,7 @@ } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13594,7 +13647,7 @@ set: function(value) { this.uniforms.matrix.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13646,7 +13699,7 @@ this.uniforms.gray.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13775,7 +13828,7 @@ this.uniforms.offset.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13837,7 +13890,7 @@ this.uniforms.pixelSize.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13891,7 +13944,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13944,7 +13997,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14012,7 +14065,7 @@ this.blurYFilter.blur = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14065,7 +14118,7 @@ this.uniforms.invert.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14119,7 +14172,7 @@ this.uniforms.sepia.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14220,7 +14273,7 @@ this.dirty = true; this.uniforms.angle.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14272,7 +14325,7 @@ this.uniforms.step.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * original filter: https://github.com/evanw/glfx.js/blob/master/src/filters/fun/dotscreen.js @@ -14358,7 +14411,7 @@ this.dirty = true; this.uniforms.angle.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14425,7 +14478,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14475,7 +14528,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index bbf6f47..027da65 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -195,16 +195,16 @@ this.interactionDOMElement = domElement; - domElement.on('mousemove', this.onMouseMove, true); - domElement.on('mousedown', this.onMouseDown, true); - domElement.on('mouseout', this.onMouseOut, true); + domElement.addEventListener('mousemove', this.onMouseMove, true); + domElement.addEventListener('mousedown', this.onMouseDown, true); + domElement.addEventListener('mouseout', this.onMouseOut, true); // aint no multi touch just yet! - domElement.on('touchstart', this.onTouchStart, true); - domElement.on('touchend', this.onTouchEnd, true); - domElement.on('touchmove', this.onTouchMove, true); + domElement.addEventListener('touchstart', this.onTouchStart, true); + domElement.addEventListener('touchend', this.onTouchEnd, true); + domElement.addEventListener('touchmove', this.onTouchMove, true); - window.on('mouseup', this.onMouseUp, true); + window.addEventListener('mouseup', this.onMouseUp, true); }; diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 8804286..a0cc614 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -1,14 +1,14 @@ -/** - * @license - * pixi.js - v1.5.0 - * Copyright (c) 2012-2014, Mat Groves - * http://goodboydigital.com/ - * - * Compiled: 2014-03-22 - * - * pixi.js is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license.php - */ +/** + * @license + * pixi.js - v1.5.0 + * Copyright (c) 2012-2014, Mat Groves + * http://goodboydigital.com/ + * + * Compiled: 2014-03-22 + * + * pixi.js is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license.php + */ /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -16,7 +16,7 @@ (function(){ var root = this; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -70,7 +70,7 @@ PIXI.AUTO_PREVENT_DEFAULT = true; PIXI.RAD_TO_DEG = 180 / Math.PI; -PIXI.DEG_TO_RAD = Math.PI / 180; +PIXI.DEG_TO_RAD = Math.PI / 180; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -120,7 +120,7 @@ this.y = y || ( (y !== 0) ? this.x : 0 ) ; }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -207,7 +207,7 @@ // constructor PIXI.Rectangle.prototype.constructor = PIXI.Rectangle; -PIXI.EmptyRectangle = new PIXI.Rectangle(0,0,0,0); +PIXI.EmptyRectangle = new PIXI.Rectangle(0,0,0,0); /** * @author Adrien Brault */ @@ -285,7 +285,7 @@ // constructor PIXI.Polygon.prototype.constructor = PIXI.Polygon; - + /** * @author Chad Engler */ @@ -360,7 +360,7 @@ // constructor PIXI.Circle.prototype.constructor = PIXI.Circle; - + /** * @author Chad Engler */ @@ -453,7 +453,7 @@ // constructor PIXI.Ellipse.prototype.constructor = PIXI.Ellipse; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -545,7 +545,7 @@ return array;//[this.a, this.b, this.tx, this.c, this.d, this.ty, 0, 0, 1]; }; -PIXI.identityMatrix = new PIXI.Matrix(); +PIXI.identityMatrix = new PIXI.Matrix(); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1159,7 +1159,7 @@ this.position.y = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1605,7 +1605,7 @@ renderSession.maskManager.popMask(renderSession.context); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1690,7 +1690,7 @@ else { this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); + this.texture.on( 'update', this.onTextureUpdateBind ); } this.renderable = true; @@ -2077,7 +2077,7 @@ var texture = PIXI.Texture.fromImage(imageId, crossorigin, scaleMode); return new PIXI.Sprite(texture); }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -2254,7 +2254,7 @@ // context.restore(); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2421,7 +2421,7 @@ } } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2432,7 +2432,7 @@ this.visible = true; this.renderable = true; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2802,7 +2802,7 @@ }; PIXI.Text.heightCache = {}; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2999,7 +2999,7 @@ }; PIXI.BitmapText.fonts = {}; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3062,7 +3062,7 @@ }; // constructor -PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; +PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3280,18 +3280,18 @@ this.interactionDOMElement.style['-ms-content-zooming'] = ''; this.interactionDOMElement.style['-ms-touch-action'] = ''; - this.interactionDOMElement.removeEventListener('mousemove', this.onMouseMove, true); - this.interactionDOMElement.removeEventListener('mousedown', this.onMouseDown, true); - this.interactionDOMElement.removeEventListener('mouseout', this.onMouseOut, true); + this.interactionDOMElement.off('mousemove', this.onMouseMove, true); + this.interactionDOMElement.off('mousedown', this.onMouseDown, true); + this.interactionDOMElement.off('mouseout', this.onMouseOut, true); // aint no multi touch just yet! - this.interactionDOMElement.removeEventListener('touchstart', this.onTouchStart, true); - this.interactionDOMElement.removeEventListener('touchend', this.onTouchEnd, true); - this.interactionDOMElement.removeEventListener('touchmove', this.onTouchMove, true); + this.interactionDOMElement.off('touchstart', this.onTouchStart, true); + this.interactionDOMElement.off('touchend', this.onTouchEnd, true); + this.interactionDOMElement.off('touchmove', this.onTouchMove, true); this.interactionDOMElement = null; - window.removeEventListener('mouseup', this.onMouseUp, true); + window.off('mouseup', this.onMouseUp, true); }; /** @@ -3778,7 +3778,7 @@ this.touchs[touchEvent.identifier] = null; } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3914,7 +3914,7 @@ { return this.interactionManager.mouse.global; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4112,18 +4112,19 @@ return result; } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * https://github.com/mrdoob/eventtarget.js/ - * THankS mr DOob! + * @author Chad Engler https://github.com/englercj @Rolnaaba */ /** - * Adds event emitter functionality to a class + * Originally based on https://github.com/mrdoob/eventtarget.js/ from mr DOob. + * Currently takes inspiration from the nodejs EventEmitter, and EventEmitter3 + */ + +/** + * Mixins event emitter functionality to a class * * @class EventTarget * @example @@ -4132,95 +4133,156 @@ * } * * var em = new MyEmitter(); - * em.emit({ type: 'eventName', data: 'some data' }); + * em.emit('eventName', 'some data', 'some moar data', {}, null, ...); */ -PIXI.EventTarget = function () { +PIXI.EventTarget = function() { + this._listeners = this._listeners || {}; /** - * Holds all the listeners + * Return a list of assigned event listeners. * - * @property listeners - * @type Object + * @param eventName {String} The events that should be listed. + * @returns {Array} + * @api public */ - var listeners = {}; - - /** - * Adds a listener for a specific event - * - * @method addEventListener - * @param type {string} A string representing the event type to listen for. - * @param listener {function} The callback function that will be fired when the event occurs - */ - this.addEventListener = this.on = function ( type, listener ) { - - - if ( listeners[ type ] === undefined ) { - - listeners[ type ] = []; - - } - - if ( listeners[ type ].indexOf( listener ) === - 1 ) { - - listeners[ type ].push( listener ); - } - + this.listeners = function listeners(eventName) { + return Array.apply(this, this._listeners[eventName] || []); }; /** - * Fires the event, ie pretends that the event has happened + * Emit an event to all registered event listeners. * - * @method dispatchEvent - * @param event {Event} the event object + * @param eventName {String} The name of the event. + * @returns {Boolean} Indication if we've emitted an event. + * @api public */ - this.dispatchEvent = this.emit = function ( event ) { + this.emit = function emit(eventName, data) { + if(!data || data.__isEventObject !== true) + data = new PIXI.Event(this, eventName, data); - if ( !listeners[ event.type ] || !listeners[ event.type ].length ) { + if(this._listeners && this._listeners[eventName]) { + var listeners = this._listeners[eventName], + length = listeners.length, + fn = listeners[0], + i; - return; + for(i = 0; i < length; fn = listeners[++i]) { + //call the event listener + fn.call(this, data); + //remove the listener if this is a "once" event + if(fn.__isOnce) + this.off(eventName, fn); + + //if "stopImmediatePropagation" is called, stop calling all events + if(data.stoppedImmediate) + return; + } + + //if "stopPropagation" is called then don't bubble the event + if(data.stopped) + return; } - for(var i = 0, l = listeners[ event.type ].length; i < l; i++) { - - listeners[ event.type ][ i ]( event ); - + if(this.parent && this.parent.emit) { + this.parent.emit.call(this.parent, eventName, data); } + return true; }; /** - * Removes the specified listener that was assigned to the specified event type + * Register a new EventListener for the given event. * - * @method removeEventListener - * @param type {string} A string representing the event type which will have its listener removed - * @param listener {function} The callback function that was be fired when the event occured + * @param eventName {String} Name of the event. + * @param callback {Functon} fn Callback function. + * @api public */ - this.removeEventListener = this.off = function ( type, listener ) { + this.on = function on(eventName, fn) { + if(!this._listeners[eventName]) + this._listeners[eventName] = []; - var index = listeners[ type ].indexOf( listener ); + this._listeners[eventName].push(fn); - if ( index !== - 1 ) { - - listeners[ type ].splice( index, 1 ); - - } - + return this; }; /** - * Removes all the listeners that were active for the specified event type + * Add an EventListener that's only called once. * - * @method removeAllEventListeners - * @param type {string} A string representing the event type which will have all its listeners removed + * @param eventName {String} Name of the event. + * @param callback {Function} Callback function. + * @api public */ - this.removeAllEventListeners = function( type ) { - var a = listeners[type]; - if (a) - a.length = 0; - }; + this.once = function once(eventName, fn) { + fn.__isOnce = true; + return this.on(eventName, fn); + }; + + /** + * Remove event listeners. + * + * @param eventName {String} The event we want to remove. + * @param callback {Function} The listener that we need to find. + * @api public + */ + this.off = function off(eventName, fn) { + if(!this._listeners[eventName]) + return this; + + var index = this._listeners[eventName].indexOf(fn); + + if(index !== -1) { + this._listeners[eventName].splice(index, 1); + } + + return this; + }; + + /** + * Remove all listeners or only the listeners for the specified event. + * + * @param eventName {String} The event want to remove all listeners for. + * @api public + */ + this.removeAllListeners = function removeAllListeners(eventName) { + if(!this._listeners[eventName]) + return this; + + this._listeners[eventName].length = 0; + + return this; + }; + + /** + * Alias methods names because people roll like that. + */ + this.removeEventListener = this.off; + this.addEventListener = this.on; + this.dispatchEvent = this.emit; }; +PIXI.Event = function(target, name, data) { + this.__isEventObject = true; + + this.stopped = false; + this.stoppedImmediate = false; + + this.target = target; + this.type = name; + this.data = data; + + this.timeStamp = Date.now(); +}; + +PIXI.Event.prototype.stopPropagation = function() { + this.stopped = true; +}; + +PIXI.Event.prototype.stopImmediatePropagation = function() { + this.stoppedImmediate = true; +}; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4260,7 +4322,7 @@ return new PIXI.CanvasRenderer(width, height, view, transparent); }; - + /* PolyK library url: http://polyk.ivank.net @@ -4430,7 +4492,7 @@ { return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) === sign; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4488,7 +4550,7 @@ return shaderProgram; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * @author Richard Davey http://www.photonstorm.com @photonstorm @@ -4829,7 +4891,7 @@ ' vColor = vec4(color * aColor.x, aColor.x);', '}' ]; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * @author Richard Davey http://www.photonstorm.com @photonstorm @@ -4976,7 +5038,7 @@ this.attributes = null; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5057,7 +5119,7 @@ this.program = program; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5162,7 +5224,7 @@ this.attribute = null; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5703,7 +5765,7 @@ r, g, b, alpha); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6246,8 +6308,8 @@ // deal with losing context.. // remove listeners - this.view.removeEventListener('webglcontextlost', this.contextLost); - this.view.removeEventListener('webglcontextrestored', this.contextRestoredLost); + this.view.off('webglcontextlost', this.contextLost); + this.view.off('webglcontextrestored', this.contextRestoredLost); PIXI.glContexts[this.glContextId] = null; @@ -6272,7 +6334,7 @@ PIXI.WebGLRenderer.glContextId = 0; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6369,7 +6431,7 @@ { this.maskStack = null; this.gl = null; -}; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6528,7 +6590,7 @@ this.gl = null; }; - + /** * @author Mat Groves * @@ -7023,7 +7085,7 @@ this.gl = null; }; - + /** * @author Mat Groves * @@ -7374,7 +7436,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -7833,7 +7895,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -7918,7 +7980,7 @@ this.frameBuffer = null; this.texture = null; }; - + /** * @author Mat Groves * @@ -7966,7 +8028,7 @@ PIXI.CanvasMaskManager.prototype.popMask = function(context) { context.restore(); -}; +}; /** * @author Mat Groves @@ -8208,7 +8270,7 @@ PIXI.CanvasTinter.tintMethod = PIXI.CanvasTinter.canUseMultiply ? PIXI.CanvasTinter.tintWithMultiply : PIXI.CanvasTinter.tintWithPerPixel; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -8598,7 +8660,7 @@ this.height = this.canvas.height = height; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -8836,7 +8898,7 @@ } } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9485,7 +9547,7 @@ PIXI.Graphics.RECT = 1; PIXI.Graphics.CIRC = 2; PIXI.Graphics.ELIP = 3; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -9558,7 +9620,7 @@ else { this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); + this.texture.on( 'update', this.onTextureUpdateBind ); } this.renderable = true; @@ -9597,7 +9659,7 @@ PIXI.Strip.prototype.onTextureUpdate = function() { this.updateFrame = true; -}; +}; /* @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9787,7 +9849,7 @@ this.texture = texture; this.updateFrame = true; }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -10262,7 +10324,7 @@ } this.refreshTexture = false; this.tilingTexture.baseTexture._powerOf2 = true; -}; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi @@ -11733,7 +11795,7 @@ slot.sprites[descriptor.name] = sprite; return sprite; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11828,7 +11890,7 @@ // add it to somewhere... PIXI.texturesToUpdate.push(scope); - scope.dispatchEvent( { type: 'loaded', content: scope } ); + scope.emit('loaded', { content: scope }); }; } @@ -11925,7 +11987,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11995,7 +12057,7 @@ else { var scope = this; - baseTexture.addEventListener('loaded', function(){ scope.onBaseTextureLoaded(); }); + baseTexture.on('loaded', function(){ scope.onBaseTextureLoaded(); }); } }; @@ -12011,13 +12073,13 @@ PIXI.Texture.prototype.onBaseTextureLoaded = function() { var baseTexture = this.baseTexture; - baseTexture.removeEventListener( 'loaded', this.onLoaded ); + baseTexture.off( 'loaded', this.onLoaded ); if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); this.setFrame(this.frame); - this.scope.dispatchEvent( { type: 'update', content: this } ); + this.scope.emit('update', { content: this }); }; /** @@ -12053,7 +12115,7 @@ PIXI.Texture.frameUpdates.push(this); - //this.dispatchEvent( { type: 'update', content: this } ); + //this.emit('update', { content: this }); }; PIXI.Texture.prototype._updateWebGLuvs = function() @@ -12183,7 +12245,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12401,7 +12463,7 @@ PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12517,7 +12579,7 @@ var scope = this; function onLoad(evt) { - scope.onAssetLoaded(evt.content); + scope.onAssetLoaded(evt.data.content); } this.loadCount = this.assetURLs.length; @@ -12538,7 +12600,7 @@ var loader = new Constructor(fileName, this.crossorigin); - loader.addEventListener('loaded', onLoad); + loader.on('loaded', onLoad); loader.load(); } }; @@ -12552,16 +12614,16 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function(loader) { this.loadCount--; - this.dispatchEvent({ type: 'onProgress', content: this, loader: loader }); + this.emit('onProgress', { content: this, loader: loader }); if (this.onProgress) this.onProgress(loader); if (!this.loadCount) { - this.dispatchEvent({type: 'onComplete', content: this}); + this.emit('onComplete', { content: this }); if(this.onComplete) this.onComplete(); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12656,7 +12718,7 @@ var frameData = this.json.frames; this.texture = image.texture.baseTexture; - image.addEventListener('loaded', function() { + image.on('loaded', function() { scope.onLoaded(); }); @@ -12714,8 +12776,7 @@ */ PIXI.JsonLoader.prototype.onLoaded = function () { this.loaded = true; - this.dispatchEvent({ - type: 'loaded', + this.emit('loaded', { content: this }); }; @@ -12727,11 +12788,10 @@ * @private */ PIXI.JsonLoader.prototype.onError = function () { - this.dispatchEvent({ - type: 'error', + this.emit('error', { content: this }); -}; +}; /** * @author Martin Kelm http://mkelm.github.com */ @@ -12879,7 +12939,7 @@ this.currentImageId = 0; for (j = 0; j < this.images.length; j++) { - this.images[j].addEventListener('loaded', selfOnLoaded); + this.images[j].on('loaded', selfOnLoaded); } this.images[this.currentImageId].load(); @@ -12904,10 +12964,7 @@ this.images[this.currentImageId].load(); } else { this.loaded = true; - this.dispatchEvent({ - type: 'loaded', - content: this - }); + this.emit('loaded', { content: this }); } }; @@ -12917,12 +12974,9 @@ * @private */ PIXI.AtlasLoader.prototype.onError = function () { - this.dispatchEvent({ - type: 'error', - content: this - }); + this.emit('error', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13003,8 +13057,8 @@ PIXI.SpriteSheetLoader.prototype.load = function () { var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.addEventListener('loaded', function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); @@ -13017,12 +13071,11 @@ * @private */ PIXI.SpriteSheetLoader.prototype.onLoaded = function () { - this.dispatchEvent({ - type: 'loaded', + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13071,7 +13124,7 @@ if(!this.texture.baseTexture.hasLoaded) { var scope = this; - this.texture.baseTexture.addEventListener('loaded', function() + this.texture.baseTexture.on('loaded', function() { scope.onLoaded(); }); @@ -13090,7 +13143,7 @@ */ PIXI.ImageLoader.prototype.onLoaded = function() { - this.dispatchEvent({type: 'loaded', content: this}); + this.emit('loaded', { content: this }); }; /** @@ -13128,7 +13181,7 @@ if(!this.texture.baseTexture.hasLoaded) { var scope = this; - this.texture.baseTexture.addEventListener('loaded', function() { + this.texture.baseTexture.on('loaded', function() { scope.onLoaded(); }); } @@ -13137,7 +13190,7 @@ this.onLoaded(); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13294,7 +13347,7 @@ PIXI.BitmapText.fonts[data.font] = data; var scope = this; - image.addEventListener('loaded', function() { + image.on('loaded', function() { scope.onLoaded(); }); image.load(); @@ -13310,9 +13363,9 @@ */ PIXI.BitmapFontLoader.prototype.onLoaded = function() { - this.dispatchEvent({type: 'loaded', content: this}); + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi @@ -13377,8 +13430,8 @@ var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.addEventListener("loaded", function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); @@ -13392,10 +13445,10 @@ */ PIXI.SpineLoader.prototype.onLoaded = function () { this.loaded = true; - this.dispatchEvent({type: "loaded", content: this}); + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13442,7 +13495,7 @@ */ this.fragmentSrc = fragmentSrc || []; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13535,7 +13588,7 @@ } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13594,7 +13647,7 @@ set: function(value) { this.uniforms.matrix.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13646,7 +13699,7 @@ this.uniforms.gray.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13775,7 +13828,7 @@ this.uniforms.offset.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13837,7 +13890,7 @@ this.uniforms.pixelSize.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13891,7 +13944,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13944,7 +13997,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14012,7 +14065,7 @@ this.blurYFilter.blur = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14065,7 +14118,7 @@ this.uniforms.invert.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14119,7 +14172,7 @@ this.uniforms.sepia.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14220,7 +14273,7 @@ this.dirty = true; this.uniforms.angle.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14272,7 +14325,7 @@ this.uniforms.step.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * original filter: https://github.com/evanw/glfx.js/blob/master/src/filters/fun/dotscreen.js @@ -14358,7 +14411,7 @@ this.dirty = true; this.uniforms.angle.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14425,7 +14478,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14475,7 +14528,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index bbf6f47..027da65 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -195,16 +195,16 @@ this.interactionDOMElement = domElement; - domElement.on('mousemove', this.onMouseMove, true); - domElement.on('mousedown', this.onMouseDown, true); - domElement.on('mouseout', this.onMouseOut, true); + domElement.addEventListener('mousemove', this.onMouseMove, true); + domElement.addEventListener('mousedown', this.onMouseDown, true); + domElement.addEventListener('mouseout', this.onMouseOut, true); // aint no multi touch just yet! - domElement.on('touchstart', this.onTouchStart, true); - domElement.on('touchend', this.onTouchEnd, true); - domElement.on('touchmove', this.onTouchMove, true); + domElement.addEventListener('touchstart', this.onTouchStart, true); + domElement.addEventListener('touchend', this.onTouchEnd, true); + domElement.addEventListener('touchmove', this.onTouchMove, true); - window.on('mouseup', this.onMouseUp, true); + window.addEventListener('mouseup', this.onMouseUp, true); }; diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 340f277..013eadb 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -113,7 +113,7 @@ var scope = this; function onLoad(evt) { - scope.onAssetLoaded(evt.content); + scope.onAssetLoaded(evt.data.content); } this.loadCount = this.assetURLs.length; diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 8804286..a0cc614 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -1,14 +1,14 @@ -/** - * @license - * pixi.js - v1.5.0 - * Copyright (c) 2012-2014, Mat Groves - * http://goodboydigital.com/ - * - * Compiled: 2014-03-22 - * - * pixi.js is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license.php - */ +/** + * @license + * pixi.js - v1.5.0 + * Copyright (c) 2012-2014, Mat Groves + * http://goodboydigital.com/ + * + * Compiled: 2014-03-22 + * + * pixi.js is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license.php + */ /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -16,7 +16,7 @@ (function(){ var root = this; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -70,7 +70,7 @@ PIXI.AUTO_PREVENT_DEFAULT = true; PIXI.RAD_TO_DEG = 180 / Math.PI; -PIXI.DEG_TO_RAD = Math.PI / 180; +PIXI.DEG_TO_RAD = Math.PI / 180; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -120,7 +120,7 @@ this.y = y || ( (y !== 0) ? this.x : 0 ) ; }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -207,7 +207,7 @@ // constructor PIXI.Rectangle.prototype.constructor = PIXI.Rectangle; -PIXI.EmptyRectangle = new PIXI.Rectangle(0,0,0,0); +PIXI.EmptyRectangle = new PIXI.Rectangle(0,0,0,0); /** * @author Adrien Brault */ @@ -285,7 +285,7 @@ // constructor PIXI.Polygon.prototype.constructor = PIXI.Polygon; - + /** * @author Chad Engler */ @@ -360,7 +360,7 @@ // constructor PIXI.Circle.prototype.constructor = PIXI.Circle; - + /** * @author Chad Engler */ @@ -453,7 +453,7 @@ // constructor PIXI.Ellipse.prototype.constructor = PIXI.Ellipse; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -545,7 +545,7 @@ return array;//[this.a, this.b, this.tx, this.c, this.d, this.ty, 0, 0, 1]; }; -PIXI.identityMatrix = new PIXI.Matrix(); +PIXI.identityMatrix = new PIXI.Matrix(); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1159,7 +1159,7 @@ this.position.y = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1605,7 +1605,7 @@ renderSession.maskManager.popMask(renderSession.context); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1690,7 +1690,7 @@ else { this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); + this.texture.on( 'update', this.onTextureUpdateBind ); } this.renderable = true; @@ -2077,7 +2077,7 @@ var texture = PIXI.Texture.fromImage(imageId, crossorigin, scaleMode); return new PIXI.Sprite(texture); }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -2254,7 +2254,7 @@ // context.restore(); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2421,7 +2421,7 @@ } } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2432,7 +2432,7 @@ this.visible = true; this.renderable = true; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2802,7 +2802,7 @@ }; PIXI.Text.heightCache = {}; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2999,7 +2999,7 @@ }; PIXI.BitmapText.fonts = {}; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3062,7 +3062,7 @@ }; // constructor -PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; +PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3280,18 +3280,18 @@ this.interactionDOMElement.style['-ms-content-zooming'] = ''; this.interactionDOMElement.style['-ms-touch-action'] = ''; - this.interactionDOMElement.removeEventListener('mousemove', this.onMouseMove, true); - this.interactionDOMElement.removeEventListener('mousedown', this.onMouseDown, true); - this.interactionDOMElement.removeEventListener('mouseout', this.onMouseOut, true); + this.interactionDOMElement.off('mousemove', this.onMouseMove, true); + this.interactionDOMElement.off('mousedown', this.onMouseDown, true); + this.interactionDOMElement.off('mouseout', this.onMouseOut, true); // aint no multi touch just yet! - this.interactionDOMElement.removeEventListener('touchstart', this.onTouchStart, true); - this.interactionDOMElement.removeEventListener('touchend', this.onTouchEnd, true); - this.interactionDOMElement.removeEventListener('touchmove', this.onTouchMove, true); + this.interactionDOMElement.off('touchstart', this.onTouchStart, true); + this.interactionDOMElement.off('touchend', this.onTouchEnd, true); + this.interactionDOMElement.off('touchmove', this.onTouchMove, true); this.interactionDOMElement = null; - window.removeEventListener('mouseup', this.onMouseUp, true); + window.off('mouseup', this.onMouseUp, true); }; /** @@ -3778,7 +3778,7 @@ this.touchs[touchEvent.identifier] = null; } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3914,7 +3914,7 @@ { return this.interactionManager.mouse.global; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4112,18 +4112,19 @@ return result; } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * https://github.com/mrdoob/eventtarget.js/ - * THankS mr DOob! + * @author Chad Engler https://github.com/englercj @Rolnaaba */ /** - * Adds event emitter functionality to a class + * Originally based on https://github.com/mrdoob/eventtarget.js/ from mr DOob. + * Currently takes inspiration from the nodejs EventEmitter, and EventEmitter3 + */ + +/** + * Mixins event emitter functionality to a class * * @class EventTarget * @example @@ -4132,95 +4133,156 @@ * } * * var em = new MyEmitter(); - * em.emit({ type: 'eventName', data: 'some data' }); + * em.emit('eventName', 'some data', 'some moar data', {}, null, ...); */ -PIXI.EventTarget = function () { +PIXI.EventTarget = function() { + this._listeners = this._listeners || {}; /** - * Holds all the listeners + * Return a list of assigned event listeners. * - * @property listeners - * @type Object + * @param eventName {String} The events that should be listed. + * @returns {Array} + * @api public */ - var listeners = {}; - - /** - * Adds a listener for a specific event - * - * @method addEventListener - * @param type {string} A string representing the event type to listen for. - * @param listener {function} The callback function that will be fired when the event occurs - */ - this.addEventListener = this.on = function ( type, listener ) { - - - if ( listeners[ type ] === undefined ) { - - listeners[ type ] = []; - - } - - if ( listeners[ type ].indexOf( listener ) === - 1 ) { - - listeners[ type ].push( listener ); - } - + this.listeners = function listeners(eventName) { + return Array.apply(this, this._listeners[eventName] || []); }; /** - * Fires the event, ie pretends that the event has happened + * Emit an event to all registered event listeners. * - * @method dispatchEvent - * @param event {Event} the event object + * @param eventName {String} The name of the event. + * @returns {Boolean} Indication if we've emitted an event. + * @api public */ - this.dispatchEvent = this.emit = function ( event ) { + this.emit = function emit(eventName, data) { + if(!data || data.__isEventObject !== true) + data = new PIXI.Event(this, eventName, data); - if ( !listeners[ event.type ] || !listeners[ event.type ].length ) { + if(this._listeners && this._listeners[eventName]) { + var listeners = this._listeners[eventName], + length = listeners.length, + fn = listeners[0], + i; - return; + for(i = 0; i < length; fn = listeners[++i]) { + //call the event listener + fn.call(this, data); + //remove the listener if this is a "once" event + if(fn.__isOnce) + this.off(eventName, fn); + + //if "stopImmediatePropagation" is called, stop calling all events + if(data.stoppedImmediate) + return; + } + + //if "stopPropagation" is called then don't bubble the event + if(data.stopped) + return; } - for(var i = 0, l = listeners[ event.type ].length; i < l; i++) { - - listeners[ event.type ][ i ]( event ); - + if(this.parent && this.parent.emit) { + this.parent.emit.call(this.parent, eventName, data); } + return true; }; /** - * Removes the specified listener that was assigned to the specified event type + * Register a new EventListener for the given event. * - * @method removeEventListener - * @param type {string} A string representing the event type which will have its listener removed - * @param listener {function} The callback function that was be fired when the event occured + * @param eventName {String} Name of the event. + * @param callback {Functon} fn Callback function. + * @api public */ - this.removeEventListener = this.off = function ( type, listener ) { + this.on = function on(eventName, fn) { + if(!this._listeners[eventName]) + this._listeners[eventName] = []; - var index = listeners[ type ].indexOf( listener ); + this._listeners[eventName].push(fn); - if ( index !== - 1 ) { - - listeners[ type ].splice( index, 1 ); - - } - + return this; }; /** - * Removes all the listeners that were active for the specified event type + * Add an EventListener that's only called once. * - * @method removeAllEventListeners - * @param type {string} A string representing the event type which will have all its listeners removed + * @param eventName {String} Name of the event. + * @param callback {Function} Callback function. + * @api public */ - this.removeAllEventListeners = function( type ) { - var a = listeners[type]; - if (a) - a.length = 0; - }; + this.once = function once(eventName, fn) { + fn.__isOnce = true; + return this.on(eventName, fn); + }; + + /** + * Remove event listeners. + * + * @param eventName {String} The event we want to remove. + * @param callback {Function} The listener that we need to find. + * @api public + */ + this.off = function off(eventName, fn) { + if(!this._listeners[eventName]) + return this; + + var index = this._listeners[eventName].indexOf(fn); + + if(index !== -1) { + this._listeners[eventName].splice(index, 1); + } + + return this; + }; + + /** + * Remove all listeners or only the listeners for the specified event. + * + * @param eventName {String} The event want to remove all listeners for. + * @api public + */ + this.removeAllListeners = function removeAllListeners(eventName) { + if(!this._listeners[eventName]) + return this; + + this._listeners[eventName].length = 0; + + return this; + }; + + /** + * Alias methods names because people roll like that. + */ + this.removeEventListener = this.off; + this.addEventListener = this.on; + this.dispatchEvent = this.emit; }; +PIXI.Event = function(target, name, data) { + this.__isEventObject = true; + + this.stopped = false; + this.stoppedImmediate = false; + + this.target = target; + this.type = name; + this.data = data; + + this.timeStamp = Date.now(); +}; + +PIXI.Event.prototype.stopPropagation = function() { + this.stopped = true; +}; + +PIXI.Event.prototype.stopImmediatePropagation = function() { + this.stoppedImmediate = true; +}; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4260,7 +4322,7 @@ return new PIXI.CanvasRenderer(width, height, view, transparent); }; - + /* PolyK library url: http://polyk.ivank.net @@ -4430,7 +4492,7 @@ { return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) === sign; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4488,7 +4550,7 @@ return shaderProgram; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * @author Richard Davey http://www.photonstorm.com @photonstorm @@ -4829,7 +4891,7 @@ ' vColor = vec4(color * aColor.x, aColor.x);', '}' ]; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * @author Richard Davey http://www.photonstorm.com @photonstorm @@ -4976,7 +5038,7 @@ this.attributes = null; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5057,7 +5119,7 @@ this.program = program; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5162,7 +5224,7 @@ this.attribute = null; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5703,7 +5765,7 @@ r, g, b, alpha); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6246,8 +6308,8 @@ // deal with losing context.. // remove listeners - this.view.removeEventListener('webglcontextlost', this.contextLost); - this.view.removeEventListener('webglcontextrestored', this.contextRestoredLost); + this.view.off('webglcontextlost', this.contextLost); + this.view.off('webglcontextrestored', this.contextRestoredLost); PIXI.glContexts[this.glContextId] = null; @@ -6272,7 +6334,7 @@ PIXI.WebGLRenderer.glContextId = 0; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6369,7 +6431,7 @@ { this.maskStack = null; this.gl = null; -}; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6528,7 +6590,7 @@ this.gl = null; }; - + /** * @author Mat Groves * @@ -7023,7 +7085,7 @@ this.gl = null; }; - + /** * @author Mat Groves * @@ -7374,7 +7436,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -7833,7 +7895,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -7918,7 +7980,7 @@ this.frameBuffer = null; this.texture = null; }; - + /** * @author Mat Groves * @@ -7966,7 +8028,7 @@ PIXI.CanvasMaskManager.prototype.popMask = function(context) { context.restore(); -}; +}; /** * @author Mat Groves @@ -8208,7 +8270,7 @@ PIXI.CanvasTinter.tintMethod = PIXI.CanvasTinter.canUseMultiply ? PIXI.CanvasTinter.tintWithMultiply : PIXI.CanvasTinter.tintWithPerPixel; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -8598,7 +8660,7 @@ this.height = this.canvas.height = height; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -8836,7 +8898,7 @@ } } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9485,7 +9547,7 @@ PIXI.Graphics.RECT = 1; PIXI.Graphics.CIRC = 2; PIXI.Graphics.ELIP = 3; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -9558,7 +9620,7 @@ else { this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); + this.texture.on( 'update', this.onTextureUpdateBind ); } this.renderable = true; @@ -9597,7 +9659,7 @@ PIXI.Strip.prototype.onTextureUpdate = function() { this.updateFrame = true; -}; +}; /* @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9787,7 +9849,7 @@ this.texture = texture; this.updateFrame = true; }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -10262,7 +10324,7 @@ } this.refreshTexture = false; this.tilingTexture.baseTexture._powerOf2 = true; -}; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi @@ -11733,7 +11795,7 @@ slot.sprites[descriptor.name] = sprite; return sprite; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11828,7 +11890,7 @@ // add it to somewhere... PIXI.texturesToUpdate.push(scope); - scope.dispatchEvent( { type: 'loaded', content: scope } ); + scope.emit('loaded', { content: scope }); }; } @@ -11925,7 +11987,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11995,7 +12057,7 @@ else { var scope = this; - baseTexture.addEventListener('loaded', function(){ scope.onBaseTextureLoaded(); }); + baseTexture.on('loaded', function(){ scope.onBaseTextureLoaded(); }); } }; @@ -12011,13 +12073,13 @@ PIXI.Texture.prototype.onBaseTextureLoaded = function() { var baseTexture = this.baseTexture; - baseTexture.removeEventListener( 'loaded', this.onLoaded ); + baseTexture.off( 'loaded', this.onLoaded ); if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); this.setFrame(this.frame); - this.scope.dispatchEvent( { type: 'update', content: this } ); + this.scope.emit('update', { content: this }); }; /** @@ -12053,7 +12115,7 @@ PIXI.Texture.frameUpdates.push(this); - //this.dispatchEvent( { type: 'update', content: this } ); + //this.emit('update', { content: this }); }; PIXI.Texture.prototype._updateWebGLuvs = function() @@ -12183,7 +12245,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12401,7 +12463,7 @@ PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12517,7 +12579,7 @@ var scope = this; function onLoad(evt) { - scope.onAssetLoaded(evt.content); + scope.onAssetLoaded(evt.data.content); } this.loadCount = this.assetURLs.length; @@ -12538,7 +12600,7 @@ var loader = new Constructor(fileName, this.crossorigin); - loader.addEventListener('loaded', onLoad); + loader.on('loaded', onLoad); loader.load(); } }; @@ -12552,16 +12614,16 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function(loader) { this.loadCount--; - this.dispatchEvent({ type: 'onProgress', content: this, loader: loader }); + this.emit('onProgress', { content: this, loader: loader }); if (this.onProgress) this.onProgress(loader); if (!this.loadCount) { - this.dispatchEvent({type: 'onComplete', content: this}); + this.emit('onComplete', { content: this }); if(this.onComplete) this.onComplete(); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12656,7 +12718,7 @@ var frameData = this.json.frames; this.texture = image.texture.baseTexture; - image.addEventListener('loaded', function() { + image.on('loaded', function() { scope.onLoaded(); }); @@ -12714,8 +12776,7 @@ */ PIXI.JsonLoader.prototype.onLoaded = function () { this.loaded = true; - this.dispatchEvent({ - type: 'loaded', + this.emit('loaded', { content: this }); }; @@ -12727,11 +12788,10 @@ * @private */ PIXI.JsonLoader.prototype.onError = function () { - this.dispatchEvent({ - type: 'error', + this.emit('error', { content: this }); -}; +}; /** * @author Martin Kelm http://mkelm.github.com */ @@ -12879,7 +12939,7 @@ this.currentImageId = 0; for (j = 0; j < this.images.length; j++) { - this.images[j].addEventListener('loaded', selfOnLoaded); + this.images[j].on('loaded', selfOnLoaded); } this.images[this.currentImageId].load(); @@ -12904,10 +12964,7 @@ this.images[this.currentImageId].load(); } else { this.loaded = true; - this.dispatchEvent({ - type: 'loaded', - content: this - }); + this.emit('loaded', { content: this }); } }; @@ -12917,12 +12974,9 @@ * @private */ PIXI.AtlasLoader.prototype.onError = function () { - this.dispatchEvent({ - type: 'error', - content: this - }); + this.emit('error', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13003,8 +13057,8 @@ PIXI.SpriteSheetLoader.prototype.load = function () { var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.addEventListener('loaded', function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); @@ -13017,12 +13071,11 @@ * @private */ PIXI.SpriteSheetLoader.prototype.onLoaded = function () { - this.dispatchEvent({ - type: 'loaded', + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13071,7 +13124,7 @@ if(!this.texture.baseTexture.hasLoaded) { var scope = this; - this.texture.baseTexture.addEventListener('loaded', function() + this.texture.baseTexture.on('loaded', function() { scope.onLoaded(); }); @@ -13090,7 +13143,7 @@ */ PIXI.ImageLoader.prototype.onLoaded = function() { - this.dispatchEvent({type: 'loaded', content: this}); + this.emit('loaded', { content: this }); }; /** @@ -13128,7 +13181,7 @@ if(!this.texture.baseTexture.hasLoaded) { var scope = this; - this.texture.baseTexture.addEventListener('loaded', function() { + this.texture.baseTexture.on('loaded', function() { scope.onLoaded(); }); } @@ -13137,7 +13190,7 @@ this.onLoaded(); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13294,7 +13347,7 @@ PIXI.BitmapText.fonts[data.font] = data; var scope = this; - image.addEventListener('loaded', function() { + image.on('loaded', function() { scope.onLoaded(); }); image.load(); @@ -13310,9 +13363,9 @@ */ PIXI.BitmapFontLoader.prototype.onLoaded = function() { - this.dispatchEvent({type: 'loaded', content: this}); + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi @@ -13377,8 +13430,8 @@ var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.addEventListener("loaded", function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); @@ -13392,10 +13445,10 @@ */ PIXI.SpineLoader.prototype.onLoaded = function () { this.loaded = true; - this.dispatchEvent({type: "loaded", content: this}); + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13442,7 +13495,7 @@ */ this.fragmentSrc = fragmentSrc || []; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13535,7 +13588,7 @@ } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13594,7 +13647,7 @@ set: function(value) { this.uniforms.matrix.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13646,7 +13699,7 @@ this.uniforms.gray.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13775,7 +13828,7 @@ this.uniforms.offset.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13837,7 +13890,7 @@ this.uniforms.pixelSize.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13891,7 +13944,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13944,7 +13997,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14012,7 +14065,7 @@ this.blurYFilter.blur = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14065,7 +14118,7 @@ this.uniforms.invert.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14119,7 +14172,7 @@ this.uniforms.sepia.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14220,7 +14273,7 @@ this.dirty = true; this.uniforms.angle.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14272,7 +14325,7 @@ this.uniforms.step.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * original filter: https://github.com/evanw/glfx.js/blob/master/src/filters/fun/dotscreen.js @@ -14358,7 +14411,7 @@ this.dirty = true; this.uniforms.angle.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14425,7 +14478,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14475,7 +14528,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index bbf6f47..027da65 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -195,16 +195,16 @@ this.interactionDOMElement = domElement; - domElement.on('mousemove', this.onMouseMove, true); - domElement.on('mousedown', this.onMouseDown, true); - domElement.on('mouseout', this.onMouseOut, true); + domElement.addEventListener('mousemove', this.onMouseMove, true); + domElement.addEventListener('mousedown', this.onMouseDown, true); + domElement.addEventListener('mouseout', this.onMouseOut, true); // aint no multi touch just yet! - domElement.on('touchstart', this.onTouchStart, true); - domElement.on('touchend', this.onTouchEnd, true); - domElement.on('touchmove', this.onTouchMove, true); + domElement.addEventListener('touchstart', this.onTouchStart, true); + domElement.addEventListener('touchend', this.onTouchEnd, true); + domElement.addEventListener('touchmove', this.onTouchMove, true); - window.on('mouseup', this.onMouseUp, true); + window.addEventListener('mouseup', this.onMouseUp, true); }; diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 340f277..013eadb 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -113,7 +113,7 @@ var scope = this; function onLoad(evt) { - scope.onAssetLoaded(evt.content); + scope.onAssetLoaded(evt.data.content); } this.loadCount = this.assetURLs.length; diff --git a/src/pixi/loaders/SpineLoader.js b/src/pixi/loaders/SpineLoader.js index 93caf5a..d4ade0e 100644 --- a/src/pixi/loaders/SpineLoader.js +++ b/src/pixi/loaders/SpineLoader.js @@ -62,8 +62,8 @@ var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.on("loaded", function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 8804286..a0cc614 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -1,14 +1,14 @@ -/** - * @license - * pixi.js - v1.5.0 - * Copyright (c) 2012-2014, Mat Groves - * http://goodboydigital.com/ - * - * Compiled: 2014-03-22 - * - * pixi.js is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license.php - */ +/** + * @license + * pixi.js - v1.5.0 + * Copyright (c) 2012-2014, Mat Groves + * http://goodboydigital.com/ + * + * Compiled: 2014-03-22 + * + * pixi.js is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license.php + */ /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -16,7 +16,7 @@ (function(){ var root = this; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -70,7 +70,7 @@ PIXI.AUTO_PREVENT_DEFAULT = true; PIXI.RAD_TO_DEG = 180 / Math.PI; -PIXI.DEG_TO_RAD = Math.PI / 180; +PIXI.DEG_TO_RAD = Math.PI / 180; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -120,7 +120,7 @@ this.y = y || ( (y !== 0) ? this.x : 0 ) ; }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -207,7 +207,7 @@ // constructor PIXI.Rectangle.prototype.constructor = PIXI.Rectangle; -PIXI.EmptyRectangle = new PIXI.Rectangle(0,0,0,0); +PIXI.EmptyRectangle = new PIXI.Rectangle(0,0,0,0); /** * @author Adrien Brault */ @@ -285,7 +285,7 @@ // constructor PIXI.Polygon.prototype.constructor = PIXI.Polygon; - + /** * @author Chad Engler */ @@ -360,7 +360,7 @@ // constructor PIXI.Circle.prototype.constructor = PIXI.Circle; - + /** * @author Chad Engler */ @@ -453,7 +453,7 @@ // constructor PIXI.Ellipse.prototype.constructor = PIXI.Ellipse; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -545,7 +545,7 @@ return array;//[this.a, this.b, this.tx, this.c, this.d, this.ty, 0, 0, 1]; }; -PIXI.identityMatrix = new PIXI.Matrix(); +PIXI.identityMatrix = new PIXI.Matrix(); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1159,7 +1159,7 @@ this.position.y = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1605,7 +1605,7 @@ renderSession.maskManager.popMask(renderSession.context); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1690,7 +1690,7 @@ else { this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); + this.texture.on( 'update', this.onTextureUpdateBind ); } this.renderable = true; @@ -2077,7 +2077,7 @@ var texture = PIXI.Texture.fromImage(imageId, crossorigin, scaleMode); return new PIXI.Sprite(texture); }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -2254,7 +2254,7 @@ // context.restore(); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2421,7 +2421,7 @@ } } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2432,7 +2432,7 @@ this.visible = true; this.renderable = true; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2802,7 +2802,7 @@ }; PIXI.Text.heightCache = {}; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2999,7 +2999,7 @@ }; PIXI.BitmapText.fonts = {}; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3062,7 +3062,7 @@ }; // constructor -PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; +PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3280,18 +3280,18 @@ this.interactionDOMElement.style['-ms-content-zooming'] = ''; this.interactionDOMElement.style['-ms-touch-action'] = ''; - this.interactionDOMElement.removeEventListener('mousemove', this.onMouseMove, true); - this.interactionDOMElement.removeEventListener('mousedown', this.onMouseDown, true); - this.interactionDOMElement.removeEventListener('mouseout', this.onMouseOut, true); + this.interactionDOMElement.off('mousemove', this.onMouseMove, true); + this.interactionDOMElement.off('mousedown', this.onMouseDown, true); + this.interactionDOMElement.off('mouseout', this.onMouseOut, true); // aint no multi touch just yet! - this.interactionDOMElement.removeEventListener('touchstart', this.onTouchStart, true); - this.interactionDOMElement.removeEventListener('touchend', this.onTouchEnd, true); - this.interactionDOMElement.removeEventListener('touchmove', this.onTouchMove, true); + this.interactionDOMElement.off('touchstart', this.onTouchStart, true); + this.interactionDOMElement.off('touchend', this.onTouchEnd, true); + this.interactionDOMElement.off('touchmove', this.onTouchMove, true); this.interactionDOMElement = null; - window.removeEventListener('mouseup', this.onMouseUp, true); + window.off('mouseup', this.onMouseUp, true); }; /** @@ -3778,7 +3778,7 @@ this.touchs[touchEvent.identifier] = null; } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3914,7 +3914,7 @@ { return this.interactionManager.mouse.global; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4112,18 +4112,19 @@ return result; } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * https://github.com/mrdoob/eventtarget.js/ - * THankS mr DOob! + * @author Chad Engler https://github.com/englercj @Rolnaaba */ /** - * Adds event emitter functionality to a class + * Originally based on https://github.com/mrdoob/eventtarget.js/ from mr DOob. + * Currently takes inspiration from the nodejs EventEmitter, and EventEmitter3 + */ + +/** + * Mixins event emitter functionality to a class * * @class EventTarget * @example @@ -4132,95 +4133,156 @@ * } * * var em = new MyEmitter(); - * em.emit({ type: 'eventName', data: 'some data' }); + * em.emit('eventName', 'some data', 'some moar data', {}, null, ...); */ -PIXI.EventTarget = function () { +PIXI.EventTarget = function() { + this._listeners = this._listeners || {}; /** - * Holds all the listeners + * Return a list of assigned event listeners. * - * @property listeners - * @type Object + * @param eventName {String} The events that should be listed. + * @returns {Array} + * @api public */ - var listeners = {}; - - /** - * Adds a listener for a specific event - * - * @method addEventListener - * @param type {string} A string representing the event type to listen for. - * @param listener {function} The callback function that will be fired when the event occurs - */ - this.addEventListener = this.on = function ( type, listener ) { - - - if ( listeners[ type ] === undefined ) { - - listeners[ type ] = []; - - } - - if ( listeners[ type ].indexOf( listener ) === - 1 ) { - - listeners[ type ].push( listener ); - } - + this.listeners = function listeners(eventName) { + return Array.apply(this, this._listeners[eventName] || []); }; /** - * Fires the event, ie pretends that the event has happened + * Emit an event to all registered event listeners. * - * @method dispatchEvent - * @param event {Event} the event object + * @param eventName {String} The name of the event. + * @returns {Boolean} Indication if we've emitted an event. + * @api public */ - this.dispatchEvent = this.emit = function ( event ) { + this.emit = function emit(eventName, data) { + if(!data || data.__isEventObject !== true) + data = new PIXI.Event(this, eventName, data); - if ( !listeners[ event.type ] || !listeners[ event.type ].length ) { + if(this._listeners && this._listeners[eventName]) { + var listeners = this._listeners[eventName], + length = listeners.length, + fn = listeners[0], + i; - return; + for(i = 0; i < length; fn = listeners[++i]) { + //call the event listener + fn.call(this, data); + //remove the listener if this is a "once" event + if(fn.__isOnce) + this.off(eventName, fn); + + //if "stopImmediatePropagation" is called, stop calling all events + if(data.stoppedImmediate) + return; + } + + //if "stopPropagation" is called then don't bubble the event + if(data.stopped) + return; } - for(var i = 0, l = listeners[ event.type ].length; i < l; i++) { - - listeners[ event.type ][ i ]( event ); - + if(this.parent && this.parent.emit) { + this.parent.emit.call(this.parent, eventName, data); } + return true; }; /** - * Removes the specified listener that was assigned to the specified event type + * Register a new EventListener for the given event. * - * @method removeEventListener - * @param type {string} A string representing the event type which will have its listener removed - * @param listener {function} The callback function that was be fired when the event occured + * @param eventName {String} Name of the event. + * @param callback {Functon} fn Callback function. + * @api public */ - this.removeEventListener = this.off = function ( type, listener ) { + this.on = function on(eventName, fn) { + if(!this._listeners[eventName]) + this._listeners[eventName] = []; - var index = listeners[ type ].indexOf( listener ); + this._listeners[eventName].push(fn); - if ( index !== - 1 ) { - - listeners[ type ].splice( index, 1 ); - - } - + return this; }; /** - * Removes all the listeners that were active for the specified event type + * Add an EventListener that's only called once. * - * @method removeAllEventListeners - * @param type {string} A string representing the event type which will have all its listeners removed + * @param eventName {String} Name of the event. + * @param callback {Function} Callback function. + * @api public */ - this.removeAllEventListeners = function( type ) { - var a = listeners[type]; - if (a) - a.length = 0; - }; + this.once = function once(eventName, fn) { + fn.__isOnce = true; + return this.on(eventName, fn); + }; + + /** + * Remove event listeners. + * + * @param eventName {String} The event we want to remove. + * @param callback {Function} The listener that we need to find. + * @api public + */ + this.off = function off(eventName, fn) { + if(!this._listeners[eventName]) + return this; + + var index = this._listeners[eventName].indexOf(fn); + + if(index !== -1) { + this._listeners[eventName].splice(index, 1); + } + + return this; + }; + + /** + * Remove all listeners or only the listeners for the specified event. + * + * @param eventName {String} The event want to remove all listeners for. + * @api public + */ + this.removeAllListeners = function removeAllListeners(eventName) { + if(!this._listeners[eventName]) + return this; + + this._listeners[eventName].length = 0; + + return this; + }; + + /** + * Alias methods names because people roll like that. + */ + this.removeEventListener = this.off; + this.addEventListener = this.on; + this.dispatchEvent = this.emit; }; +PIXI.Event = function(target, name, data) { + this.__isEventObject = true; + + this.stopped = false; + this.stoppedImmediate = false; + + this.target = target; + this.type = name; + this.data = data; + + this.timeStamp = Date.now(); +}; + +PIXI.Event.prototype.stopPropagation = function() { + this.stopped = true; +}; + +PIXI.Event.prototype.stopImmediatePropagation = function() { + this.stoppedImmediate = true; +}; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4260,7 +4322,7 @@ return new PIXI.CanvasRenderer(width, height, view, transparent); }; - + /* PolyK library url: http://polyk.ivank.net @@ -4430,7 +4492,7 @@ { return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) === sign; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4488,7 +4550,7 @@ return shaderProgram; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * @author Richard Davey http://www.photonstorm.com @photonstorm @@ -4829,7 +4891,7 @@ ' vColor = vec4(color * aColor.x, aColor.x);', '}' ]; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * @author Richard Davey http://www.photonstorm.com @photonstorm @@ -4976,7 +5038,7 @@ this.attributes = null; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5057,7 +5119,7 @@ this.program = program; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5162,7 +5224,7 @@ this.attribute = null; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5703,7 +5765,7 @@ r, g, b, alpha); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6246,8 +6308,8 @@ // deal with losing context.. // remove listeners - this.view.removeEventListener('webglcontextlost', this.contextLost); - this.view.removeEventListener('webglcontextrestored', this.contextRestoredLost); + this.view.off('webglcontextlost', this.contextLost); + this.view.off('webglcontextrestored', this.contextRestoredLost); PIXI.glContexts[this.glContextId] = null; @@ -6272,7 +6334,7 @@ PIXI.WebGLRenderer.glContextId = 0; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6369,7 +6431,7 @@ { this.maskStack = null; this.gl = null; -}; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6528,7 +6590,7 @@ this.gl = null; }; - + /** * @author Mat Groves * @@ -7023,7 +7085,7 @@ this.gl = null; }; - + /** * @author Mat Groves * @@ -7374,7 +7436,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -7833,7 +7895,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -7918,7 +7980,7 @@ this.frameBuffer = null; this.texture = null; }; - + /** * @author Mat Groves * @@ -7966,7 +8028,7 @@ PIXI.CanvasMaskManager.prototype.popMask = function(context) { context.restore(); -}; +}; /** * @author Mat Groves @@ -8208,7 +8270,7 @@ PIXI.CanvasTinter.tintMethod = PIXI.CanvasTinter.canUseMultiply ? PIXI.CanvasTinter.tintWithMultiply : PIXI.CanvasTinter.tintWithPerPixel; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -8598,7 +8660,7 @@ this.height = this.canvas.height = height; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -8836,7 +8898,7 @@ } } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9485,7 +9547,7 @@ PIXI.Graphics.RECT = 1; PIXI.Graphics.CIRC = 2; PIXI.Graphics.ELIP = 3; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -9558,7 +9620,7 @@ else { this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); + this.texture.on( 'update', this.onTextureUpdateBind ); } this.renderable = true; @@ -9597,7 +9659,7 @@ PIXI.Strip.prototype.onTextureUpdate = function() { this.updateFrame = true; -}; +}; /* @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9787,7 +9849,7 @@ this.texture = texture; this.updateFrame = true; }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -10262,7 +10324,7 @@ } this.refreshTexture = false; this.tilingTexture.baseTexture._powerOf2 = true; -}; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi @@ -11733,7 +11795,7 @@ slot.sprites[descriptor.name] = sprite; return sprite; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11828,7 +11890,7 @@ // add it to somewhere... PIXI.texturesToUpdate.push(scope); - scope.dispatchEvent( { type: 'loaded', content: scope } ); + scope.emit('loaded', { content: scope }); }; } @@ -11925,7 +11987,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11995,7 +12057,7 @@ else { var scope = this; - baseTexture.addEventListener('loaded', function(){ scope.onBaseTextureLoaded(); }); + baseTexture.on('loaded', function(){ scope.onBaseTextureLoaded(); }); } }; @@ -12011,13 +12073,13 @@ PIXI.Texture.prototype.onBaseTextureLoaded = function() { var baseTexture = this.baseTexture; - baseTexture.removeEventListener( 'loaded', this.onLoaded ); + baseTexture.off( 'loaded', this.onLoaded ); if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); this.setFrame(this.frame); - this.scope.dispatchEvent( { type: 'update', content: this } ); + this.scope.emit('update', { content: this }); }; /** @@ -12053,7 +12115,7 @@ PIXI.Texture.frameUpdates.push(this); - //this.dispatchEvent( { type: 'update', content: this } ); + //this.emit('update', { content: this }); }; PIXI.Texture.prototype._updateWebGLuvs = function() @@ -12183,7 +12245,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12401,7 +12463,7 @@ PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12517,7 +12579,7 @@ var scope = this; function onLoad(evt) { - scope.onAssetLoaded(evt.content); + scope.onAssetLoaded(evt.data.content); } this.loadCount = this.assetURLs.length; @@ -12538,7 +12600,7 @@ var loader = new Constructor(fileName, this.crossorigin); - loader.addEventListener('loaded', onLoad); + loader.on('loaded', onLoad); loader.load(); } }; @@ -12552,16 +12614,16 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function(loader) { this.loadCount--; - this.dispatchEvent({ type: 'onProgress', content: this, loader: loader }); + this.emit('onProgress', { content: this, loader: loader }); if (this.onProgress) this.onProgress(loader); if (!this.loadCount) { - this.dispatchEvent({type: 'onComplete', content: this}); + this.emit('onComplete', { content: this }); if(this.onComplete) this.onComplete(); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12656,7 +12718,7 @@ var frameData = this.json.frames; this.texture = image.texture.baseTexture; - image.addEventListener('loaded', function() { + image.on('loaded', function() { scope.onLoaded(); }); @@ -12714,8 +12776,7 @@ */ PIXI.JsonLoader.prototype.onLoaded = function () { this.loaded = true; - this.dispatchEvent({ - type: 'loaded', + this.emit('loaded', { content: this }); }; @@ -12727,11 +12788,10 @@ * @private */ PIXI.JsonLoader.prototype.onError = function () { - this.dispatchEvent({ - type: 'error', + this.emit('error', { content: this }); -}; +}; /** * @author Martin Kelm http://mkelm.github.com */ @@ -12879,7 +12939,7 @@ this.currentImageId = 0; for (j = 0; j < this.images.length; j++) { - this.images[j].addEventListener('loaded', selfOnLoaded); + this.images[j].on('loaded', selfOnLoaded); } this.images[this.currentImageId].load(); @@ -12904,10 +12964,7 @@ this.images[this.currentImageId].load(); } else { this.loaded = true; - this.dispatchEvent({ - type: 'loaded', - content: this - }); + this.emit('loaded', { content: this }); } }; @@ -12917,12 +12974,9 @@ * @private */ PIXI.AtlasLoader.prototype.onError = function () { - this.dispatchEvent({ - type: 'error', - content: this - }); + this.emit('error', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13003,8 +13057,8 @@ PIXI.SpriteSheetLoader.prototype.load = function () { var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.addEventListener('loaded', function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); @@ -13017,12 +13071,11 @@ * @private */ PIXI.SpriteSheetLoader.prototype.onLoaded = function () { - this.dispatchEvent({ - type: 'loaded', + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13071,7 +13124,7 @@ if(!this.texture.baseTexture.hasLoaded) { var scope = this; - this.texture.baseTexture.addEventListener('loaded', function() + this.texture.baseTexture.on('loaded', function() { scope.onLoaded(); }); @@ -13090,7 +13143,7 @@ */ PIXI.ImageLoader.prototype.onLoaded = function() { - this.dispatchEvent({type: 'loaded', content: this}); + this.emit('loaded', { content: this }); }; /** @@ -13128,7 +13181,7 @@ if(!this.texture.baseTexture.hasLoaded) { var scope = this; - this.texture.baseTexture.addEventListener('loaded', function() { + this.texture.baseTexture.on('loaded', function() { scope.onLoaded(); }); } @@ -13137,7 +13190,7 @@ this.onLoaded(); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13294,7 +13347,7 @@ PIXI.BitmapText.fonts[data.font] = data; var scope = this; - image.addEventListener('loaded', function() { + image.on('loaded', function() { scope.onLoaded(); }); image.load(); @@ -13310,9 +13363,9 @@ */ PIXI.BitmapFontLoader.prototype.onLoaded = function() { - this.dispatchEvent({type: 'loaded', content: this}); + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi @@ -13377,8 +13430,8 @@ var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.addEventListener("loaded", function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); @@ -13392,10 +13445,10 @@ */ PIXI.SpineLoader.prototype.onLoaded = function () { this.loaded = true; - this.dispatchEvent({type: "loaded", content: this}); + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13442,7 +13495,7 @@ */ this.fragmentSrc = fragmentSrc || []; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13535,7 +13588,7 @@ } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13594,7 +13647,7 @@ set: function(value) { this.uniforms.matrix.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13646,7 +13699,7 @@ this.uniforms.gray.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13775,7 +13828,7 @@ this.uniforms.offset.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13837,7 +13890,7 @@ this.uniforms.pixelSize.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13891,7 +13944,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13944,7 +13997,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14012,7 +14065,7 @@ this.blurYFilter.blur = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14065,7 +14118,7 @@ this.uniforms.invert.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14119,7 +14172,7 @@ this.uniforms.sepia.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14220,7 +14273,7 @@ this.dirty = true; this.uniforms.angle.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14272,7 +14325,7 @@ this.uniforms.step.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * original filter: https://github.com/evanw/glfx.js/blob/master/src/filters/fun/dotscreen.js @@ -14358,7 +14411,7 @@ this.dirty = true; this.uniforms.angle.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14425,7 +14478,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14475,7 +14528,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index bbf6f47..027da65 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -195,16 +195,16 @@ this.interactionDOMElement = domElement; - domElement.on('mousemove', this.onMouseMove, true); - domElement.on('mousedown', this.onMouseDown, true); - domElement.on('mouseout', this.onMouseOut, true); + domElement.addEventListener('mousemove', this.onMouseMove, true); + domElement.addEventListener('mousedown', this.onMouseDown, true); + domElement.addEventListener('mouseout', this.onMouseOut, true); // aint no multi touch just yet! - domElement.on('touchstart', this.onTouchStart, true); - domElement.on('touchend', this.onTouchEnd, true); - domElement.on('touchmove', this.onTouchMove, true); + domElement.addEventListener('touchstart', this.onTouchStart, true); + domElement.addEventListener('touchend', this.onTouchEnd, true); + domElement.addEventListener('touchmove', this.onTouchMove, true); - window.on('mouseup', this.onMouseUp, true); + window.addEventListener('mouseup', this.onMouseUp, true); }; diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 340f277..013eadb 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -113,7 +113,7 @@ var scope = this; function onLoad(evt) { - scope.onAssetLoaded(evt.content); + scope.onAssetLoaded(evt.data.content); } this.loadCount = this.assetURLs.length; diff --git a/src/pixi/loaders/SpineLoader.js b/src/pixi/loaders/SpineLoader.js index 93caf5a..d4ade0e 100644 --- a/src/pixi/loaders/SpineLoader.js +++ b/src/pixi/loaders/SpineLoader.js @@ -62,8 +62,8 @@ var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.on("loaded", function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); diff --git a/src/pixi/loaders/SpriteSheetLoader.js b/src/pixi/loaders/SpriteSheetLoader.js index c7cc9d1..431c092 100644 --- a/src/pixi/loaders/SpriteSheetLoader.js +++ b/src/pixi/loaders/SpriteSheetLoader.js @@ -79,7 +79,7 @@ var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); jsonLoader.on('loaded', function (event) { - scope.json = event.content.json; + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); diff --git a/bin/pixi.dev.js b/bin/pixi.dev.js index 8804286..a0cc614 100644 --- a/bin/pixi.dev.js +++ b/bin/pixi.dev.js @@ -1,14 +1,14 @@ -/** - * @license - * pixi.js - v1.5.0 - * Copyright (c) 2012-2014, Mat Groves - * http://goodboydigital.com/ - * - * Compiled: 2014-03-22 - * - * pixi.js is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license.php - */ +/** + * @license + * pixi.js - v1.5.0 + * Copyright (c) 2012-2014, Mat Groves + * http://goodboydigital.com/ + * + * Compiled: 2014-03-22 + * + * pixi.js is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license.php + */ /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -16,7 +16,7 @@ (function(){ var root = this; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -70,7 +70,7 @@ PIXI.AUTO_PREVENT_DEFAULT = true; PIXI.RAD_TO_DEG = 180 / Math.PI; -PIXI.DEG_TO_RAD = Math.PI / 180; +PIXI.DEG_TO_RAD = Math.PI / 180; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -120,7 +120,7 @@ this.y = y || ( (y !== 0) ? this.x : 0 ) ; }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -207,7 +207,7 @@ // constructor PIXI.Rectangle.prototype.constructor = PIXI.Rectangle; -PIXI.EmptyRectangle = new PIXI.Rectangle(0,0,0,0); +PIXI.EmptyRectangle = new PIXI.Rectangle(0,0,0,0); /** * @author Adrien Brault */ @@ -285,7 +285,7 @@ // constructor PIXI.Polygon.prototype.constructor = PIXI.Polygon; - + /** * @author Chad Engler */ @@ -360,7 +360,7 @@ // constructor PIXI.Circle.prototype.constructor = PIXI.Circle; - + /** * @author Chad Engler */ @@ -453,7 +453,7 @@ // constructor PIXI.Ellipse.prototype.constructor = PIXI.Ellipse; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -545,7 +545,7 @@ return array;//[this.a, this.b, this.tx, this.c, this.d, this.ty, 0, 0, 1]; }; -PIXI.identityMatrix = new PIXI.Matrix(); +PIXI.identityMatrix = new PIXI.Matrix(); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1159,7 +1159,7 @@ this.position.y = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1605,7 +1605,7 @@ renderSession.maskManager.popMask(renderSession.context); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -1690,7 +1690,7 @@ else { this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); + this.texture.on( 'update', this.onTextureUpdateBind ); } this.renderable = true; @@ -2077,7 +2077,7 @@ var texture = PIXI.Texture.fromImage(imageId, crossorigin, scaleMode); return new PIXI.Sprite(texture); }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -2254,7 +2254,7 @@ // context.restore(); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2421,7 +2421,7 @@ } } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2432,7 +2432,7 @@ this.visible = true; this.renderable = true; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2802,7 +2802,7 @@ }; PIXI.Text.heightCache = {}; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -2999,7 +2999,7 @@ }; PIXI.BitmapText.fonts = {}; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3062,7 +3062,7 @@ }; // constructor -PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; +PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3280,18 +3280,18 @@ this.interactionDOMElement.style['-ms-content-zooming'] = ''; this.interactionDOMElement.style['-ms-touch-action'] = ''; - this.interactionDOMElement.removeEventListener('mousemove', this.onMouseMove, true); - this.interactionDOMElement.removeEventListener('mousedown', this.onMouseDown, true); - this.interactionDOMElement.removeEventListener('mouseout', this.onMouseOut, true); + this.interactionDOMElement.off('mousemove', this.onMouseMove, true); + this.interactionDOMElement.off('mousedown', this.onMouseDown, true); + this.interactionDOMElement.off('mouseout', this.onMouseOut, true); // aint no multi touch just yet! - this.interactionDOMElement.removeEventListener('touchstart', this.onTouchStart, true); - this.interactionDOMElement.removeEventListener('touchend', this.onTouchEnd, true); - this.interactionDOMElement.removeEventListener('touchmove', this.onTouchMove, true); + this.interactionDOMElement.off('touchstart', this.onTouchStart, true); + this.interactionDOMElement.off('touchend', this.onTouchEnd, true); + this.interactionDOMElement.off('touchmove', this.onTouchMove, true); this.interactionDOMElement = null; - window.removeEventListener('mouseup', this.onMouseUp, true); + window.off('mouseup', this.onMouseUp, true); }; /** @@ -3778,7 +3778,7 @@ this.touchs[touchEvent.identifier] = null; } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -3914,7 +3914,7 @@ { return this.interactionManager.mouse.global; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4112,18 +4112,19 @@ return result; } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * https://github.com/mrdoob/eventtarget.js/ - * THankS mr DOob! + * @author Chad Engler https://github.com/englercj @Rolnaaba */ /** - * Adds event emitter functionality to a class + * Originally based on https://github.com/mrdoob/eventtarget.js/ from mr DOob. + * Currently takes inspiration from the nodejs EventEmitter, and EventEmitter3 + */ + +/** + * Mixins event emitter functionality to a class * * @class EventTarget * @example @@ -4132,95 +4133,156 @@ * } * * var em = new MyEmitter(); - * em.emit({ type: 'eventName', data: 'some data' }); + * em.emit('eventName', 'some data', 'some moar data', {}, null, ...); */ -PIXI.EventTarget = function () { +PIXI.EventTarget = function() { + this._listeners = this._listeners || {}; /** - * Holds all the listeners + * Return a list of assigned event listeners. * - * @property listeners - * @type Object + * @param eventName {String} The events that should be listed. + * @returns {Array} + * @api public */ - var listeners = {}; - - /** - * Adds a listener for a specific event - * - * @method addEventListener - * @param type {string} A string representing the event type to listen for. - * @param listener {function} The callback function that will be fired when the event occurs - */ - this.addEventListener = this.on = function ( type, listener ) { - - - if ( listeners[ type ] === undefined ) { - - listeners[ type ] = []; - - } - - if ( listeners[ type ].indexOf( listener ) === - 1 ) { - - listeners[ type ].push( listener ); - } - + this.listeners = function listeners(eventName) { + return Array.apply(this, this._listeners[eventName] || []); }; /** - * Fires the event, ie pretends that the event has happened + * Emit an event to all registered event listeners. * - * @method dispatchEvent - * @param event {Event} the event object + * @param eventName {String} The name of the event. + * @returns {Boolean} Indication if we've emitted an event. + * @api public */ - this.dispatchEvent = this.emit = function ( event ) { + this.emit = function emit(eventName, data) { + if(!data || data.__isEventObject !== true) + data = new PIXI.Event(this, eventName, data); - if ( !listeners[ event.type ] || !listeners[ event.type ].length ) { + if(this._listeners && this._listeners[eventName]) { + var listeners = this._listeners[eventName], + length = listeners.length, + fn = listeners[0], + i; - return; + for(i = 0; i < length; fn = listeners[++i]) { + //call the event listener + fn.call(this, data); + //remove the listener if this is a "once" event + if(fn.__isOnce) + this.off(eventName, fn); + + //if "stopImmediatePropagation" is called, stop calling all events + if(data.stoppedImmediate) + return; + } + + //if "stopPropagation" is called then don't bubble the event + if(data.stopped) + return; } - for(var i = 0, l = listeners[ event.type ].length; i < l; i++) { - - listeners[ event.type ][ i ]( event ); - + if(this.parent && this.parent.emit) { + this.parent.emit.call(this.parent, eventName, data); } + return true; }; /** - * Removes the specified listener that was assigned to the specified event type + * Register a new EventListener for the given event. * - * @method removeEventListener - * @param type {string} A string representing the event type which will have its listener removed - * @param listener {function} The callback function that was be fired when the event occured + * @param eventName {String} Name of the event. + * @param callback {Functon} fn Callback function. + * @api public */ - this.removeEventListener = this.off = function ( type, listener ) { + this.on = function on(eventName, fn) { + if(!this._listeners[eventName]) + this._listeners[eventName] = []; - var index = listeners[ type ].indexOf( listener ); + this._listeners[eventName].push(fn); - if ( index !== - 1 ) { - - listeners[ type ].splice( index, 1 ); - - } - + return this; }; /** - * Removes all the listeners that were active for the specified event type + * Add an EventListener that's only called once. * - * @method removeAllEventListeners - * @param type {string} A string representing the event type which will have all its listeners removed + * @param eventName {String} Name of the event. + * @param callback {Function} Callback function. + * @api public */ - this.removeAllEventListeners = function( type ) { - var a = listeners[type]; - if (a) - a.length = 0; - }; + this.once = function once(eventName, fn) { + fn.__isOnce = true; + return this.on(eventName, fn); + }; + + /** + * Remove event listeners. + * + * @param eventName {String} The event we want to remove. + * @param callback {Function} The listener that we need to find. + * @api public + */ + this.off = function off(eventName, fn) { + if(!this._listeners[eventName]) + return this; + + var index = this._listeners[eventName].indexOf(fn); + + if(index !== -1) { + this._listeners[eventName].splice(index, 1); + } + + return this; + }; + + /** + * Remove all listeners or only the listeners for the specified event. + * + * @param eventName {String} The event want to remove all listeners for. + * @api public + */ + this.removeAllListeners = function removeAllListeners(eventName) { + if(!this._listeners[eventName]) + return this; + + this._listeners[eventName].length = 0; + + return this; + }; + + /** + * Alias methods names because people roll like that. + */ + this.removeEventListener = this.off; + this.addEventListener = this.on; + this.dispatchEvent = this.emit; }; +PIXI.Event = function(target, name, data) { + this.__isEventObject = true; + + this.stopped = false; + this.stoppedImmediate = false; + + this.target = target; + this.type = name; + this.data = data; + + this.timeStamp = Date.now(); +}; + +PIXI.Event.prototype.stopPropagation = function() { + this.stopped = true; +}; + +PIXI.Event.prototype.stopImmediatePropagation = function() { + this.stoppedImmediate = true; +}; + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4260,7 +4322,7 @@ return new PIXI.CanvasRenderer(width, height, view, transparent); }; - + /* PolyK library url: http://polyk.ivank.net @@ -4430,7 +4492,7 @@ { return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) === sign; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -4488,7 +4550,7 @@ return shaderProgram; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * @author Richard Davey http://www.photonstorm.com @photonstorm @@ -4829,7 +4891,7 @@ ' vColor = vec4(color * aColor.x, aColor.x);', '}' ]; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * @author Richard Davey http://www.photonstorm.com @photonstorm @@ -4976,7 +5038,7 @@ this.attributes = null; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5057,7 +5119,7 @@ this.program = program; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5162,7 +5224,7 @@ this.attribute = null; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -5703,7 +5765,7 @@ r, g, b, alpha); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6246,8 +6308,8 @@ // deal with losing context.. // remove listeners - this.view.removeEventListener('webglcontextlost', this.contextLost); - this.view.removeEventListener('webglcontextrestored', this.contextRestoredLost); + this.view.off('webglcontextlost', this.contextLost); + this.view.off('webglcontextrestored', this.contextRestoredLost); PIXI.glContexts[this.glContextId] = null; @@ -6272,7 +6334,7 @@ PIXI.WebGLRenderer.glContextId = 0; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6369,7 +6431,7 @@ { this.maskStack = null; this.gl = null; -}; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -6528,7 +6590,7 @@ this.gl = null; }; - + /** * @author Mat Groves * @@ -7023,7 +7085,7 @@ this.gl = null; }; - + /** * @author Mat Groves * @@ -7374,7 +7436,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -7833,7 +7895,7 @@ gl.deleteBuffer(this.colorBuffer); gl.deleteBuffer(this.indexBuffer); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -7918,7 +7980,7 @@ this.frameBuffer = null; this.texture = null; }; - + /** * @author Mat Groves * @@ -7966,7 +8028,7 @@ PIXI.CanvasMaskManager.prototype.popMask = function(context) { context.restore(); -}; +}; /** * @author Mat Groves @@ -8208,7 +8270,7 @@ PIXI.CanvasTinter.tintMethod = PIXI.CanvasTinter.canUseMultiply ? PIXI.CanvasTinter.tintWithMultiply : PIXI.CanvasTinter.tintWithPerPixel; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -8598,7 +8660,7 @@ this.height = this.canvas.height = height; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -8836,7 +8898,7 @@ } } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9485,7 +9547,7 @@ PIXI.Graphics.RECT = 1; PIXI.Graphics.CIRC = 2; PIXI.Graphics.ELIP = 3; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -9558,7 +9620,7 @@ else { this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); + this.texture.on( 'update', this.onTextureUpdateBind ); } this.renderable = true; @@ -9597,7 +9659,7 @@ PIXI.Strip.prototype.onTextureUpdate = function() { this.updateFrame = true; -}; +}; /* @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -9787,7 +9849,7 @@ this.texture = texture; this.updateFrame = true; }; - + /** * @author Mat Groves http://matgroves.com/ */ @@ -10262,7 +10324,7 @@ } this.refreshTexture = false; this.tilingTexture.baseTexture._powerOf2 = true; -}; +}; /** * @author Mat Groves http://matgroves.com/ @Doormat23 * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi @@ -11733,7 +11795,7 @@ slot.sprites[descriptor.name] = sprite; return sprite; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11828,7 +11890,7 @@ // add it to somewhere... PIXI.texturesToUpdate.push(scope); - scope.dispatchEvent( { type: 'loaded', content: scope } ); + scope.emit('loaded', { content: scope }); }; } @@ -11925,7 +11987,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -11995,7 +12057,7 @@ else { var scope = this; - baseTexture.addEventListener('loaded', function(){ scope.onBaseTextureLoaded(); }); + baseTexture.on('loaded', function(){ scope.onBaseTextureLoaded(); }); } }; @@ -12011,13 +12073,13 @@ PIXI.Texture.prototype.onBaseTextureLoaded = function() { var baseTexture = this.baseTexture; - baseTexture.removeEventListener( 'loaded', this.onLoaded ); + baseTexture.off( 'loaded', this.onLoaded ); if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); this.setFrame(this.frame); - this.scope.dispatchEvent( { type: 'update', content: this } ); + this.scope.emit('update', { content: this }); }; /** @@ -12053,7 +12115,7 @@ PIXI.Texture.frameUpdates.push(this); - //this.dispatchEvent( { type: 'update', content: this } ); + //this.emit('update', { content: this }); }; PIXI.Texture.prototype._updateWebGLuvs = function() @@ -12183,7 +12245,7 @@ }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12401,7 +12463,7 @@ PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12517,7 +12579,7 @@ var scope = this; function onLoad(evt) { - scope.onAssetLoaded(evt.content); + scope.onAssetLoaded(evt.data.content); } this.loadCount = this.assetURLs.length; @@ -12538,7 +12600,7 @@ var loader = new Constructor(fileName, this.crossorigin); - loader.addEventListener('loaded', onLoad); + loader.on('loaded', onLoad); loader.load(); } }; @@ -12552,16 +12614,16 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function(loader) { this.loadCount--; - this.dispatchEvent({ type: 'onProgress', content: this, loader: loader }); + this.emit('onProgress', { content: this, loader: loader }); if (this.onProgress) this.onProgress(loader); if (!this.loadCount) { - this.dispatchEvent({type: 'onComplete', content: this}); + this.emit('onComplete', { content: this }); if(this.onComplete) this.onComplete(); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -12656,7 +12718,7 @@ var frameData = this.json.frames; this.texture = image.texture.baseTexture; - image.addEventListener('loaded', function() { + image.on('loaded', function() { scope.onLoaded(); }); @@ -12714,8 +12776,7 @@ */ PIXI.JsonLoader.prototype.onLoaded = function () { this.loaded = true; - this.dispatchEvent({ - type: 'loaded', + this.emit('loaded', { content: this }); }; @@ -12727,11 +12788,10 @@ * @private */ PIXI.JsonLoader.prototype.onError = function () { - this.dispatchEvent({ - type: 'error', + this.emit('error', { content: this }); -}; +}; /** * @author Martin Kelm http://mkelm.github.com */ @@ -12879,7 +12939,7 @@ this.currentImageId = 0; for (j = 0; j < this.images.length; j++) { - this.images[j].addEventListener('loaded', selfOnLoaded); + this.images[j].on('loaded', selfOnLoaded); } this.images[this.currentImageId].load(); @@ -12904,10 +12964,7 @@ this.images[this.currentImageId].load(); } else { this.loaded = true; - this.dispatchEvent({ - type: 'loaded', - content: this - }); + this.emit('loaded', { content: this }); } }; @@ -12917,12 +12974,9 @@ * @private */ PIXI.AtlasLoader.prototype.onError = function () { - this.dispatchEvent({ - type: 'error', - content: this - }); + this.emit('error', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13003,8 +13057,8 @@ PIXI.SpriteSheetLoader.prototype.load = function () { var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.addEventListener('loaded', function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); @@ -13017,12 +13071,11 @@ * @private */ PIXI.SpriteSheetLoader.prototype.onLoaded = function () { - this.dispatchEvent({ - type: 'loaded', + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13071,7 +13124,7 @@ if(!this.texture.baseTexture.hasLoaded) { var scope = this; - this.texture.baseTexture.addEventListener('loaded', function() + this.texture.baseTexture.on('loaded', function() { scope.onLoaded(); }); @@ -13090,7 +13143,7 @@ */ PIXI.ImageLoader.prototype.onLoaded = function() { - this.dispatchEvent({type: 'loaded', content: this}); + this.emit('loaded', { content: this }); }; /** @@ -13128,7 +13181,7 @@ if(!this.texture.baseTexture.hasLoaded) { var scope = this; - this.texture.baseTexture.addEventListener('loaded', function() { + this.texture.baseTexture.on('loaded', function() { scope.onLoaded(); }); } @@ -13137,7 +13190,7 @@ this.onLoaded(); } }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13294,7 +13347,7 @@ PIXI.BitmapText.fonts[data.font] = data; var scope = this; - image.addEventListener('loaded', function() { + image.on('loaded', function() { scope.onLoaded(); }); image.load(); @@ -13310,9 +13363,9 @@ */ PIXI.BitmapFontLoader.prototype.onLoaded = function() { - this.dispatchEvent({type: 'loaded', content: this}); + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi @@ -13377,8 +13430,8 @@ var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.addEventListener("loaded", function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); @@ -13392,10 +13445,10 @@ */ PIXI.SpineLoader.prototype.onLoaded = function () { this.loaded = true; - this.dispatchEvent({type: "loaded", content: this}); + this.emit('loaded', { content: this }); }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13442,7 +13495,7 @@ */ this.fragmentSrc = fragmentSrc || []; }; - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13535,7 +13588,7 @@ } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13594,7 +13647,7 @@ set: function(value) { this.uniforms.matrix.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13646,7 +13699,7 @@ this.uniforms.gray.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13775,7 +13828,7 @@ this.uniforms.offset.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13837,7 +13890,7 @@ this.uniforms.pixelSize.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13891,7 +13944,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -13944,7 +13997,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14012,7 +14065,7 @@ this.blurYFilter.blur = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14065,7 +14118,7 @@ this.uniforms.invert.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14119,7 +14172,7 @@ this.uniforms.sepia.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14220,7 +14273,7 @@ this.dirty = true; this.uniforms.angle.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14272,7 +14325,7 @@ this.uniforms.step.value = value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 * original filter: https://github.com/evanw/glfx.js/blob/master/src/filters/fun/dotscreen.js @@ -14358,7 +14411,7 @@ this.dirty = true; this.uniforms.angle.value = value; } -}); +}); /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14425,7 +14478,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ @@ -14475,7 +14528,7 @@ this.uniforms.blur.value = (1/7000) * value; } }); - + /** * @author Mat Groves http://matgroves.com/ @Doormat23 */ diff --git a/src/pixi/InteractionManager.js b/src/pixi/InteractionManager.js index bbf6f47..027da65 100644 --- a/src/pixi/InteractionManager.js +++ b/src/pixi/InteractionManager.js @@ -195,16 +195,16 @@ this.interactionDOMElement = domElement; - domElement.on('mousemove', this.onMouseMove, true); - domElement.on('mousedown', this.onMouseDown, true); - domElement.on('mouseout', this.onMouseOut, true); + domElement.addEventListener('mousemove', this.onMouseMove, true); + domElement.addEventListener('mousedown', this.onMouseDown, true); + domElement.addEventListener('mouseout', this.onMouseOut, true); // aint no multi touch just yet! - domElement.on('touchstart', this.onTouchStart, true); - domElement.on('touchend', this.onTouchEnd, true); - domElement.on('touchmove', this.onTouchMove, true); + domElement.addEventListener('touchstart', this.onTouchStart, true); + domElement.addEventListener('touchend', this.onTouchEnd, true); + domElement.addEventListener('touchmove', this.onTouchMove, true); - window.on('mouseup', this.onMouseUp, true); + window.addEventListener('mouseup', this.onMouseUp, true); }; diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 340f277..013eadb 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -113,7 +113,7 @@ var scope = this; function onLoad(evt) { - scope.onAssetLoaded(evt.content); + scope.onAssetLoaded(evt.data.content); } this.loadCount = this.assetURLs.length; diff --git a/src/pixi/loaders/SpineLoader.js b/src/pixi/loaders/SpineLoader.js index 93caf5a..d4ade0e 100644 --- a/src/pixi/loaders/SpineLoader.js +++ b/src/pixi/loaders/SpineLoader.js @@ -62,8 +62,8 @@ var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); - jsonLoader.on("loaded", function (event) { - scope.json = event.content.json; + jsonLoader.on('loaded', function (event) { + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); diff --git a/src/pixi/loaders/SpriteSheetLoader.js b/src/pixi/loaders/SpriteSheetLoader.js index c7cc9d1..431c092 100644 --- a/src/pixi/loaders/SpriteSheetLoader.js +++ b/src/pixi/loaders/SpriteSheetLoader.js @@ -79,7 +79,7 @@ var scope = this; var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin); jsonLoader.on('loaded', function (event) { - scope.json = event.content.json; + scope.json = event.data.content.json; scope.onLoaded(); }); jsonLoader.load(); diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index 178468e..7e2d9ac 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -66,8 +66,8 @@ this.contextLost = this.handleContextLost.bind(this); this.contextRestoredLost = this.handleContextRestored.bind(this); - this.view.on('webglcontextlost', this.contextLost, false); - this.view.on('webglcontextrestored', this.contextRestoredLost, false); + this.view.addEventListener('webglcontextlost', this.contextLost, false); + this.view.addEventListener('webglcontextrestored', this.contextRestoredLost, false); this.options = { alpha: this.transparent,