Upgraded the CreateJS suite, handling its slight changes.

This commit is contained in:
Scott Erickson 2014-11-18 15:26:26 -08:00
parent 9f79b3ba3e
commit 1444d84aea
10 changed files with 6403 additions and 6423 deletions

View file

@ -104,6 +104,7 @@ class AudioPlayer extends CocoClass
hasLoadedSound: (filename, name) ->
return false unless filename of cache
console.info 'has loaded sound? well it is in the cache...', filename, name
return false unless createjs.Sound.loadComplete filename
true
@ -123,7 +124,7 @@ class AudioPlayer extends CocoClass
return if filename of cache
name ?= filename
# SoundJS flips out if you try to register the same file twice
createjs.Sound.registerSound(filename, name, 1, true) # 1: 1 channel, true: should preload
result = createjs.Sound.registerSound(filename, name, 1) # 1: 1 channel
cache[filename] = new Media(name)
# PROGRESS CALLBACKS

View file

@ -13,7 +13,7 @@ module.exports = class SegmentedSprite extends createjs.SpriteContainer
constructor: (@spriteSheet, @thangType, @spriteSheetPrefix, @resolutionFactor=SPRITE_RESOLUTION_FACTOR) ->
@spriteSheet.mcPool ?= {}
@initialize(@spriteSheet)
super(@spriteSheet)
@addEventListener 'tick', @handleTick
destroy: ->

View file

@ -6,7 +6,7 @@ module.exports = class SingularSprite extends createjs.Sprite
childMovieClips: null
constructor: (@spriteSheet, @thangType, @spriteSheetPrefix, @resolutionFactor=SPRITE_RESOLUTION_FACTOR) ->
@initialize(@spriteSheet)
super(@spriteSheet)
destroy: ->
@removeAllEventListeners()

View file

@ -125,7 +125,7 @@ module.exports = Surface = class Surface extends CocoClass
@webGLCanvas[0].addEventListener 'mouseup', @onMouseUp
@webGLCanvas.on 'mousewheel', @onMouseWheel
@hookUpChooseControls() if @options.choosing # TODO: figure this stuff out
createjs.Ticker.timingMode = createjs.Ticker.RAF_SYNCHED
# createjs.Ticker.timingMode = createjs.Ticker.RAF_SYNCHED # TODO: Reenable once this is fixed: https://github.com/CreateJS/EaselJS/issues/516
createjs.Ticker.setFPS @options.frameRate
@onResize()

View file

@ -3,7 +3,7 @@
* Visit http://createjs.com/ for documentation, updates and examples.
*
* Copyright (c) 2010 gskinner.com, inc.
*
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@ -12,10 +12,10 @@
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@ -30,71 +30,55 @@
this.createjs = this.createjs||{};
(function() {
"use strict";
/**
* A SpriteContainer is a nestable display list that enables aggressively optimized rendering of bitmap content.
* In order to accomplish these optimizations, SpriteContainer enforces a few restrictions on its content.
*
* Restrictions:
* - only Sprite, SpriteContainer, BitmapText and DOMElement are allowed to be added as children.
* - a spriteSheet MUST be either be passed into the constructor or defined on the first child added.
* - all children (with the exception of DOMElement) MUST use the same spriteSheet.
*
* <h4>Example</h4>
* var data = {
* images: ["sprites.jpg"],
* frames: {width:50, height:50},
* animations: {run:[0,4], jump:[5,8,"run"]}
* };
* var spriteSheet = new createjs.SpriteSheet(data);
* var container = new createjs.SpriteContainer(spriteSheet);
* container.addChild(spriteInstance, spriteInstance2);
* container.x = 100;
*
* <strong>Note:</strong> SpriteContainer is not included in the minified version of EaselJS.
*
* @class SpriteContainer
* @extends Container
* @constructor
* @param {SpriteSheet} [spriteSheet] The spriteSheet to use for this SpriteContainer and its children.
**/
var SpriteContainer = function(spriteSheet) {
this.initialize(spriteSheet);
};
var p = SpriteContainer.prototype = new createjs.Container();
// public properties:
/**
* The SpriteSheet that this container enforces use of.
* @property spriteSheet
* @type {SpriteSheet}
* @readonly
* A SpriteContainer is a nestable display list that enables aggressively optimized rendering of bitmap content.
* In order to accomplish these optimizations, SpriteContainer enforces a few restrictions on its content.
*
* Restrictions:
* - only Sprite, SpriteContainer, BitmapText and DOMElement are allowed to be added as children.
* - a spriteSheet MUST be either be passed into the constructor or defined on the first child added.
* - all children (with the exception of DOMElement) MUST use the same spriteSheet.
*
* <h4>Example</h4>
*
* var data = {
* images: ["sprites.jpg"],
* frames: {width:50, height:50},
* animations: {run:[0,4], jump:[5,8,"run"]}
* };
* var spriteSheet = new createjs.SpriteSheet(data);
* var container = new createjs.SpriteContainer(spriteSheet);
* container.addChild(spriteInstance, spriteInstance2);
* container.x = 100;
*
* <strong>Note:</strong> SpriteContainer is not included in the minified version of EaselJS.
*
* @class SpriteContainer
* @extends Container
* @constructor
* @param {SpriteSheet} [spriteSheet] The spriteSheet to use for this SpriteContainer and its children.
**/
p.spriteSheet = null;
// constructor:
/**
* @property Container_initialize
* @type Function
* @private
**/
p.Container_initialize = p.initialize;
/**
* Initialization method.
* @method initialize
* @param {SpriteSheet} spriteSheet Optional. The spriteSheet to use for this SpriteContainer and its children.
* @protected
*/
p.initialize = function(spriteSheet) {
this.Container_initialize();
function SpriteContainer(spriteSheet) {
this.Container_constructor();
// public properties:
/**
* The SpriteSheet that this container enforces use of.
* @property spriteSheet
* @type {SpriteSheet}
* @readonly
**/
this.spriteSheet = spriteSheet;
};
}
var p = createjs.extend(SpriteContainer, createjs.Container);
// public methods:
/**
* Adds a child to the top of the display list.
* Only children of type SpriteContainer, Sprite, Bitmap, BitmapText, or DOMElement are allowed.
@ -127,7 +111,7 @@ var p = SpriteContainer.prototype = new createjs.Container();
* Only children of type SpriteContainer, Sprite, Bitmap, BitmapText, or DOMElement are allowed.
* The child must have the same spritesheet as this container (unless it's a DOMElement).
* If a spritesheet hasn't been defined, this container uses this child's spritesheet.
*
*
* <h4>Example</h4>
* addChildAt(child1, index);
*
@ -163,7 +147,7 @@ var p = SpriteContainer.prototype = new createjs.Container();
}
if (child._spritestage_compatibility <= 4) {
var spriteSheet = child.spriteSheet;
if ((!spriteSheet || !spriteSheet._images || spriteSheet._images.length > 1) || (this.spritesheet && spritesheet !== spritesheet)) {
if ((!spriteSheet || !spriteSheet._images || spriteSheet._images.length > 1) || (this.spriteSheet && this.spriteSheet !== spriteSheet)) {
console && console.log("Error: A child's spriteSheet must be equal to its parent spriteSheet and only use one image. [" + child.toString() + "]");
return child;
}
@ -184,5 +168,6 @@ var p = SpriteContainer.prototype = new createjs.Container();
return "[SpriteContainer (name="+ this.name +")]";
};
createjs.SpriteContainer = SpriteContainer;
}());
createjs.SpriteContainer = createjs.promote(SpriteContainer, "Container");
}());

View file

@ -36,54 +36,237 @@ this.createjs = this.createjs||{};
(function() {
"use strict";
// Set which classes are compatible with SpriteStage.
// The order is important!!! If it's changed/appended, make sure that any logic that
// checks _spritestage_compatibility accounts for it!
[createjs.SpriteContainer, createjs.Sprite, createjs.BitmapText, createjs.Bitmap, createjs.DOMElement].forEach(function(_class, index) {
_class.prototype._spritestage_compatibility = index + 1;
});
/**
* A sprite stage is the root level {{#crossLink "Container"}}{{/crossLink}} for an aggressively optimized display list. Each time its {{#crossLink "Stage/tick"}}{{/crossLink}}
* method is called, it will render its display list to its target canvas. WebGL content is fully compatible with the existing Context2D renderer.
* On devices or browsers that don't support WebGL, content will automatically be rendered via canvas 2D.
*
* Restrictions:
* - only Sprite, SpriteContainer, BitmapText, Bitmap and DOMElement are allowed to be added to the display list.
* - a child being added (with the exception of DOMElement) MUST have an image or spriteSheet defined on it.
* - a child's image/spriteSheet MUST never change while being on the display list.
*
* <h4>Example</h4>
* This example creates a sprite stage, adds a child to it, then uses {{#crossLink "Ticker"}}{{/crossLink}} to update the child
* and redraw the stage using {{#crossLink "SpriteStage/update"}}{{/crossLink}}.
*
* var stage = new createjs.SpriteStage("canvasElementId", false, false);
* stage.updateViewport(800, 600);
* var image = new createjs.Bitmap("imagePath.png");
* stage.addChild(image);
* createjs.Ticker.addEventListener("tick", handleTick);
* function handleTick(event) {
* image.x += 10;
* stage.update();
* }
*
* <strong>Note:</strong> SpriteStage is not included in the minified version of EaselJS.
*
* @class SpriteStage
* @extends Stage
* @constructor
* @param {HTMLCanvasElement | String | Object} canvas A canvas object that the SpriteStage will render to, or the string id
* of a canvas object in the current document.
* @param {Boolean} preserveDrawingBuffer If true, the canvas is NOT auto-cleared by WebGL (spec discourages true). Useful if you want to use p.autoClear = false.
* @param {Boolean} antialias Specifies whether or not the browser's WebGL implementation should try to perform antialiasing.
**/
var SpriteStage = function(canvas, preserveDrawingBuffer, antialias) {
this.initialize(canvas, preserveDrawingBuffer, antialias);
};
var p = SpriteStage.prototype = new createjs.Stage();
// Set which classes are compatible with SpriteStage.
// The order is important!!! If it's changed/appended, make sure that any logic that
// checks _spritestage_compatibility accounts for it!
[createjs.SpriteContainer, createjs.Sprite, createjs.BitmapText, createjs.Bitmap, createjs.DOMElement].forEach(function(_class, index) {
_class.prototype._spritestage_compatibility = index + 1;
});
// static properties:
// constructor:
/**
* A sprite stage is the root level {{#crossLink "Container"}}{{/crossLink}} for an aggressively optimized display list. Each time its {{#crossLink "Stage/tick"}}{{/crossLink}}
* method is called, it will render its display list to its target canvas. WebGL content is fully compatible with the existing Context2D renderer.
* On devices or browsers that don't support WebGL, content will automatically be rendered via canvas 2D.
*
* Restrictions:
* - only Sprite, SpriteContainer, BitmapText, Bitmap and DOMElement are allowed to be added to the display list.
* - a child being added (with the exception of DOMElement) MUST have an image or spriteSheet defined on it.
* - a child's image/spriteSheet MUST never change while being on the display list.
*
* <h4>Example</h4>
* This example creates a sprite stage, adds a child to it, then uses {{#crossLink "Ticker"}}{{/crossLink}} to update the child
* and redraw the stage using {{#crossLink "SpriteStage/update"}}{{/crossLink}}.
*
* var stage = new createjs.SpriteStage("canvasElementId", false, false);
* stage.updateViewport(800, 600);
* var image = new createjs.Bitmap("imagePath.png");
* stage.addChild(image);
* createjs.Ticker.addEventListener("tick", handleTick);
* function handleTick(event) {
* image.x += 10;
* stage.update();
* }
*
* <strong>Note:</strong> SpriteStage is not included in the minified version of EaselJS.
*
* @class SpriteStage
* @extends Stage
* @constructor
* @param {HTMLCanvasElement | String | Object} canvas A canvas object that the SpriteStage will render to, or the string id
* of a canvas object in the current document.
* @param {Boolean} preserveDrawingBuffer If true, the canvas is NOT auto-cleared by WebGL (spec discourages true). Useful if you want to use p.autoClear = false.
* @param {Boolean} antialias Specifies whether or not the browser's WebGL implementation should try to perform antialiasing.
**/
function SpriteStage(canvas, preserveDrawingBuffer, antialias) {
this.Stage_constructor(canvas);
// private properties:
/**
* Specifies whether or not the canvas is auto-cleared by WebGL. Spec discourages true.
* If true, the canvas is NOT auto-cleared by WebGL. Value is ignored if `_alphaEnabled` is false.
* Useful if you want to use `autoClear = false`.
* @property _preserveDrawingBuffer
* @protected
* @type {Boolean}
* @default false
**/
this._preserveDrawingBuffer = preserveDrawingBuffer||false;
/**
* Specifies whether or not the browser's WebGL implementation should try to perform antialiasing.
* @property _antialias
* @protected
* @type {Boolean}
* @default false
**/
this._antialias = antialias||false;
/**
* The width of the canvas element.
* @property _viewportWidth
* @protected
* @type {Number}
* @default 0
**/
this._viewportWidth = 0;
/**
* The height of the canvas element.
* @property _viewportHeight
* @protected
* @type {Number}
* @default 0
**/
this._viewportHeight = 0;
/**
* A 2D projection matrix used to convert WebGL's clipspace into normal pixels.
* @property _projectionMatrix
* @protected
* @type {Float32Array}
* @default null
**/
this._projectionMatrix = null;
/**
* The current WebGL canvas context.
* @property _webGLContext
* @protected
* @type {WebGLRenderingContext}
* @default null
**/
this._webGLContext = null;
/**
* Indicates whether or not an error has been detected when dealing with WebGL.
* If the is true, the behavior should be to use Canvas 2D rendering instead.
* @property _webGLErrorDetected
* @protected
* @type {Boolean}
* @default false
**/
this._webGLErrorDetected = false;
/**
* The color to use when the WebGL canvas has been cleared.
* @property _clearColor
* @protected
* @type {Object}
* @default null
**/
this._clearColor = null;
/**
* The maximum number of textures WebGL can work with per draw call.
* @property _maxTexturesPerDraw
* @protected
* @type {Number}
* @default 1
**/
this._maxTexturesPerDraw = 1; // TODO: this is currently unused.
/**
* The maximum total number of boxes points that can be defined per draw call.
* @property _maxBoxesPointsPerDraw
* @protected
* @type {Number}
* @default null
**/
this._maxBoxesPointsPerDraw = null;
/**
* The maximum number of boxes (sprites) that can be drawn in one draw call.
* @property _maxBoxesPerDraw
* @protected
* @type {Number}
* @default null
**/
this._maxBoxesPerDraw = null;
/**
* The maximum number of indices that can be drawn in one draw call.
* @property _maxIndicesPerDraw
* @protected
* @type {Number}
* @default null
**/
this._maxIndicesPerDraw = null;
/**
* The shader program used to draw everything.
* @property _shaderProgram
* @protected
* @type {WebGLProgram}
* @default null
**/
this._shaderProgram = null;
/**
* The vertices data for the current draw call.
* @property _vertices
* @protected
* @type {Float32Array}
* @default null
**/
this._vertices = null;
/**
* The buffer that contains all the vertices data.
* @property _verticesBuffer
* @protected
* @type {WebGLBuffer}
* @default null
**/
this._verticesBuffer = null;
/**
* The indices to the vertices defined in this._vertices.
* @property _indices
* @protected
* @type {Uint16Array}
* @default null
**/
this._indices = null;
/**
* The buffer that contains all the indices data.
* @property _indicesBuffer
* @protected
* @type {WebGLBuffer}
* @default null
**/
this._indicesBuffer = null;
/**
* The current box index being defined for drawing.
* @property _currentBoxIndex
* @protected
* @type {Number}
* @default -1
**/
this._currentBoxIndex = -1;
/**
* The current texture that will be used to draw into the GPU.
* @property _drawTexture
* @protected
* @type {WebGLTexture}
* @default null
**/
this._drawTexture = null;
// setup:
this._initializeWebGL();
}
var p = createjs.extend(SpriteStage, createjs.Stage);
// constants:
/**
* The number of properties defined per vertex in p._verticesBuffer.
* x, y, textureU, textureV, alpha
@ -149,7 +332,8 @@ var p = SpriteStage.prototype = new createjs.Stage();
* @readonly
**/
SpriteStage.MAX_BOXES_POINTS_INCREMENT = SpriteStage.MAX_INDEX_SIZE / 4;
// getter / setters:
/**
* Indicates whether WebGL is being used for rendering. For example, this would be false if WebGL is not
@ -168,209 +352,8 @@ var p = SpriteStage.prototype = new createjs.Stage();
});
} catch (e) {} // TODO: use Log
// private properties:
/**
* Specifies whether or not the canvas is auto-cleared by WebGL. Spec discourages true.
* If true, the canvas is NOT auto-cleared by WebGL. Value is ignored if p._alphaEnabled is false.
* Useful if you want to use p.autoClear = false.
* @property _preserveDrawingBuffer
* @protected
* @type {Boolean}
* @default false
**/
p._preserveDrawingBuffer = false;
/**
* Specifies whether or not the browser's WebGL implementation should try to perform antialiasing.
* @property _antialias
* @protected
* @type {Boolean}
* @default false
**/
p._antialias = false;
/**
* The width of the canvas element.
* @property _viewportWidth
* @protected
* @type {Number}
* @default 0
**/
p._viewportWidth = 0;
/**
* The height of the canvas element.
* @property _viewportHeight
* @protected
* @type {Number}
* @default 0
**/
p._viewportHeight = 0;
/**
* A 2D projection matrix used to convert WebGL's clipspace into normal pixels.
* @property _projectionMatrix
* @protected
* @type {Float32Array}
* @default null
**/
p._projectionMatrix = null;
/**
* The current WebGL canvas context.
* @property _webGLContext
* @protected
* @type {WebGLRenderingContext}
* @default null
**/
p._webGLContext = null;
/**
* Indicates whether or not an error has been detected when dealing with WebGL.
* If the is true, the behavior should be to use Canvas 2D rendering instead.
* @property _webGLErrorDetected
* @protected
* @type {Boolean}
* @default false
**/
p._webGLErrorDetected = false;
/**
* The color to use when the WebGL canvas has been cleared.
* @property _clearColor
* @protected
* @type {Object}
* @default null
**/
p._clearColor = null;
/**
* The maximum number of textures WebGL can work with per draw call.
* @property _maxTexturesPerDraw
* @protected
* @type {Number}
* @default 1
**/
p._maxTexturesPerDraw = 1;
/**
* The maximum total number of boxes points that can be defined per draw call.
* @property _maxBoxesPointsPerDraw
* @protected
* @type {Number}
* @default null
**/
p._maxBoxesPointsPerDraw = null;
/**
* The maximum number of boxes (sprites) that can be drawn in one draw call.
* @property _maxBoxesPerDraw
* @protected
* @type {Number}
* @default null
**/
p._maxBoxesPerDraw = null;
/**
* The maximum number of indices that can be drawn in one draw call.
* @property _maxIndicesPerDraw
* @protected
* @type {Number}
* @default null
**/
p._maxIndicesPerDraw = null;
/**
* The shader program used to draw everything.
* @property _shaderProgram
* @protected
* @type {WebGLProgram}
* @default null
**/
p._shaderProgram = null;
/**
* The vertices data for the current draw call.
* @property _vertices
* @protected
* @type {Float32Array}
* @default null
**/
p._vertices = null;
/**
* The buffer that contains all the vertices data.
* @property _verticesBuffer
* @protected
* @type {WebGLBuffer}
* @default null
**/
p._verticesBuffer = null;
/**
* The indices to the vertices defined in p._vertices.
* @property _indices
* @protected
* @type {Uint16Array}
* @default null
**/
p._indices = null;
/**
* The buffer that contains all the indices data.
* @property _indicesBuffer
* @protected
* @type {WebGLBuffer}
* @default null
**/
p._indicesBuffer = null;
/**
* The current box index being defined for drawing.
* @property _currentBoxIndex
* @protected
* @type {Number}
* @default -1
**/
p._currentBoxIndex = -1;
/**
* The current texture that will be used to draw into the GPU.
* @property _drawTexture
* @protected
* @type {WebGLTexture}
* @default null
**/
p._drawTexture = null;
// constructor:
/**
* @property Stage_initialize
* @type Function
* @private
**/
p.Stage_initialize = p.initialize;
/**
* Initialization method.
* @method initialize
* @param {HTMLCanvasElement | String | Object} canvas A canvas object, or the string id of a canvas object in the current document.
* @param {Boolean} preserveDrawingBuffer If true, the canvas is NOT auto-cleared by WebGL (spec discourages true). Useful if you want to use p.autoClear = false.
* @param {Boolean} antialias Specifies whether or not the browser's WebGL implementation should try to perform antialiasing.
* @protected
**/
p.initialize = function(canvas, preserveDrawingBuffer, antialias) {
this._preserveDrawingBuffer = preserveDrawingBuffer !== undefined ? preserveDrawingBuffer : this._preserveDrawingBuffer;
this._antialias = antialias !== undefined ? antialias : this._antialias;
this.Stage_initialize(canvas);
this._initializeWebGL();
};
// public methods:
/**
* Adds a child to the top of the display list.
* Only children of type SpriteContainer, Sprite, Bitmap, BitmapText, or DOMElement are allowed.
@ -403,6 +386,7 @@ var p = SpriteStage.prototype = new createjs.Stage();
* Children also MUST have either an image or spriteSheet defined on them (unless it's a DOMElement).
*
* <h4>Example</h4>
*
* addChildAt(child1, index);
*
* You can also add multiple children, such as:
@ -432,7 +416,6 @@ var p = SpriteStage.prototype = new createjs.Stage();
if (child._spritestage_compatibility >= 1) {
// The child is compatible with SpriteStage.
} else {
console.trace();
console && console.log("Error: You can only add children of type SpriteContainer, Sprite, Bitmap, BitmapText, or DOMElement. [" + child.toString() + "]");
return child;
}
@ -447,32 +430,10 @@ var p = SpriteStage.prototype = new createjs.Stage();
return child;
};
/**
* Each time the update method is called, the stage will tick all descendants (see: {{#crossLink "DisplayObject/tick"}}{{/crossLink}})
* and then render the display list to the canvas using WebGL. If WebGL is not supported in the browser, it will default to a 2D context.
*
* Any parameters passed to `update()` will be passed on to any
* {{#crossLink "DisplayObject/tick:event"}}{{/crossLink}} event handlers.
*
* Some time-based features in EaselJS (for example {{#crossLink "Sprite/framerate"}}{{/crossLink}} require that
* a tick event object (or equivalent) be passed as the first parameter to update(). For example:
*
* Ticker.addEventListener("tick", handleTick);
* function handleTick(evtObj) {
* // do some work here, then update the stage, passing through the event object:
* myStage.update(evtObj);
* }
*
* @method update
* @param {*} [params]* Params to include when ticking descendants. The first param should usually be a tick event.
**/
p.update = function(params) {
/** docced in super class **/
p.update = function(props) {
if (!this.canvas) { return; }
if (this.tickOnUpdate) {
this.dispatchEvent("tickstart"); // TODO: make cancellable?
this._tick((arguments.length ? arguments : null));
this.dispatchEvent("tickend");
}
if (this.tickOnUpdate) { this.tick(props); }
this.dispatchEvent("drawstart"); // TODO: make cancellable?
if (this.autoClear) { this.clear(); }
var ctx = this._setWebGLContext();
@ -508,13 +469,6 @@ var p = SpriteStage.prototype = new createjs.Stage();
}
};
/**
* @property Stage_draw
* @type {Function}
* @private
**/
p.Stage_draw = p.draw;
/**
* Draws the stage into the specified context (using WebGL) ignoring its visible, alpha, shadow, and transform.
* If WebGL is not supported in the browser, it will default to a 2D context.
@ -881,11 +835,10 @@ var p = SpriteStage.prototype = new createjs.Stage();
for (var i = 0, l = kids.length; i < l; i++) {
kid = kids[i];
if (!kid.isVisible()) { continue; }
mtx = kid._matrix;
mtx = kid._props.matrix;
// Get the kid's global matrix (relative to the stage):
mtx = (parentMVMatrix ? mtx.copy(parentMVMatrix) : mtx.identity())
.appendTransform(kid.x, kid.y, kid.scaleX, kid.scaleY, kid.rotation, kid.skewX, kid.skewY, kid.regX, kid.regY);
mtx = (parentMVMatrix ? mtx.copy(parentMVMatrix) : mtx.identity()).prependTransform(kid.x, kid.y, kid.scaleX, kid.scaleY, kid.rotation, kid.skewX, kid.skewY, kid.regX, kid.regY);
// Set default texture coordinates:
var uStart = 0, uEnd = 1,
@ -1027,5 +980,6 @@ var p = SpriteStage.prototype = new createjs.Stage();
this._drawTexture = null;
};
createjs.SpriteStage = SpriteStage;
createjs.SpriteStage = createjs.promote(SpriteStage, "Stage");
}());

File diff suppressed because it is too large Load diff

View file

@ -27,7 +27,7 @@ this.createjs = this.createjs||{};
* @type String
* @static
**/
s.buildDate = /*date*/"Thu, 06 Mar 2014 22:58:10 GMT"; // injected by build process
s.buildDate = /*date*/"Wed, 22 Oct 2014 16:11:35 GMT"; // injected by build process
})();
/*
@ -78,7 +78,7 @@ this.createjs = this.createjs||{};
/**
* Contains properties and methods shared by all events for use with
* {{#crossLink "EventDispatcher"}}{{/crossLink}}.
*
*
* Note that Event objects are often reused, so you should never
* rely on an event object's state outside of the call stack it was received in.
* @class Event
@ -91,6 +91,7 @@ var Event = function(type, bubbles, cancelable) {
this.initialize(type, bubbles, cancelable);
};
var p = Event.prototype;
Event.prototype.constructor = Event;
// events:
@ -194,7 +195,7 @@ var p = Event.prototype;
* @readonly
*/
p.immediatePropagationStopped = false;
/**
* Indicates if {{#crossLink "Event/remove"}}{{/crossLink}} has been called on this event.
* @property removed
@ -249,21 +250,21 @@ var p = Event.prototype;
p.stopImmediatePropagation = function() {
this.immediatePropagationStopped = this.propagationStopped = true;
};
/**
* Causes the active listener to be removed via removeEventListener();
*
*
* myBtn.addEventListener("click", function(evt) {
* // do stuff...
* evt.remove(); // removes this listener.
* });
*
*
* @method remove
**/
p.remove = function() {
this.removed = true;
};
/**
* Returns a clone of the Event instance.
* @method clone
@ -375,6 +376,7 @@ var EventDispatcher = function() {
/* this.initialize(); */ // not needed.
};
var p = EventDispatcher.prototype;
EventDispatcher.prototype.constructor = EventDispatcher;
/**
@ -579,19 +581,19 @@ var p = EventDispatcher.prototype;
* @param {Object | String | Event} eventObj An object with a "type" property, or a string type.
* While a generic object will work, it is recommended to use a CreateJS Event instance. If a string is used,
* dispatchEvent will construct an Event instance with the specified type.
* @param {Object} [target] The object to use as the target property of the event object. This will default to the
* dispatching object. <b>This parameter is deprecated and will be removed.</b>
* @return {Boolean} Returns the value of eventObj.defaultPrevented.
**/
p.dispatchEvent = function(eventObj, target) {
p.dispatchEvent = function(eventObj) {
if (typeof eventObj == "string") {
// won't bubble, so skip everything if there's no listeners:
var listeners = this._listeners;
if (!listeners || !listeners[eventObj]) { return false; }
eventObj = new createjs.Event(eventObj);
} else if (eventObj.target && eventObj.clone) {
// redispatching an active event object, so clone it:
eventObj = eventObj.clone();
}
// TODO: deprecated. Target param is deprecated, only use case is MouseEvent/mousemove, remove.
eventObj.target = target||this;
try { eventObj.target = this; } catch (e) {} // try/catch allows redispatching of native events
if (!eventObj.bubbles || !this.parent) {
this._dispatchEvent(eventObj, 2);
@ -663,8 +665,8 @@ var p = EventDispatcher.prototype;
if (eventObj && listeners) {
var arr = listeners[eventObj.type];
if (!arr||!(l=arr.length)) { return; }
eventObj.currentTarget = this;
eventObj.eventPhase = eventPhase;
try { eventObj.currentTarget = this; } catch (e) {}
try { eventObj.eventPhase = eventPhase; } catch (e) {}
eventObj.removed = false;
arr = arr.slice(); // to avoid issues with items being removed or added during the dispatch
for (var i=0; i<l && !eventObj.immediatePropagationStopped; i++) {
@ -904,29 +906,37 @@ this.createjs = this.createjs||{};
this.init();
};
AbstractLoader.prototype = new createjs.EventDispatcher(); //TODO: TEST!
var p = AbstractLoader.prototype;
var p = AbstractLoader.prototype = new createjs.EventDispatcher();
AbstractLoader.prototype.constructor = AbstractLoader;
var s = AbstractLoader;
/**
* The RegExp pattern to use to parse file URIs. This supports simple file names, as well as full domain URIs with
* query strings. The resulting match is: protocol:$1 domain:$2 relativePath:$3 path:$4 file:$5 extension:$6 query:$7.
* @property FILE_PATTERN
* @type {RegExp}
* The Regular Expression used to test file URLS for an absolute path.
* @property ABSOLUTE_PATH
* @static
* @protected
* @type {RegExp}
* @since 0.4.2
*/
s.FILE_PATTERN = /^(?:(\w+:)\/{2}(\w+(?:\.\w+)*\/?)|(.{0,2}\/{1}))?([/.]*?(?:[^?]+)?\/)?((?:[^/?]+)\.(\w+))(?:\?(\S+)?)?$/;
s.ABSOLUTE_PATT = /^(?:\w+:)?\/{2}/i;
/**
* The RegExp pattern to use to parse path URIs. This supports protocols, relative files, and paths. The resulting
* match is: protocol:$1 relativePath:$2 path$3.
* @property PATH_PATTERN
* @type {RegExp}
* The Regular Expression used to test file URLS for an absolute path.
* @property RELATIVE_PATH
* @static
* @protected
* @type {RegExp}
* @since 0.4.2
*/
s.PATH_PATTERN = /^(?:(\w+:)\/{2})|(.{0,2}\/{1})?([/.]*?(?:[^?]+)?\/?)?$/;
s.RELATIVE_PATT = (/^[./]*?\//i);
/**
* The Regular Expression used to test file URLS for an extension. Note that URIs must already have the query string
* removed.
* @property EXTENSION_PATT
* @static
* @type {RegExp}
* @since 0.4.2
*/
s.EXTENSION_PATT = /\/?[^/]+\.(\w{1,5})$/i;
/**
* If the loader has completed loading. This provides a quick check, but also ensures that the different approaches
@ -1164,29 +1174,49 @@ this.createjs = this.createjs||{};
};
/**
* Parse a file URI using the {{#crossLink "AbstractLoader/FILE_PATTERN:property"}}{{/crossLink}} RegExp pattern.
* @method _parseURI
* @param {String} path The file path to parse.
* @return {Array} The matched file contents. Please see the FILE_PATTERN property for details on the return value.
* This will return null if it does not match.
* @protected
* Parse a file path to determine the information we need to work with it. Currently, PreloadJS needs to know:
* <ul>
* <li>If the path is absolute. Absolute paths start with a protocol (such as `http://`, `file://`, or
* `//networkPath`)</li>
* <li>If the path is relative. Relative paths start with `../` or `/path` (or similar)</li>
* <li>The file extension. This is determined by the filename with an extension. Query strings are dropped, and
* the file path is expected to follow the format `name.ext`.</li>
* </ul>
*
* <strong>Note:</strong> This has changed from earlier versions, which used a single, complicated Regular Expression, which
* was difficult to maintain, and over-aggressive in determining all file properties. It has been simplified to
* only pull out what it needs.
* @param path
* @returns {Object} An Object with an `absolute` and `relative` Boolean, as well as an optional 'extension` String
* property, which is the lowercase extension.
* @private
*/
p._parseURI = function(path) {
if (!path) { return null; }
return path.match(s.FILE_PATTERN);
};
var info = { absolute: false, relative:false };
if (path == null) { return info; };
/**
* Parse a file URI using the {{#crossLink "AbstractLoader/PATH_PATTERN"}}{{/crossLink}} RegExp pattern.
* @method _parsePath
* @param {String} path The file path to parse.
* @return {Array} The matched path contents. Please see the PATH_PATTERN property for details on the return value.
* This will return null if it does not match.
* @protected
*/
p._parsePath = function(path) {
if (!path) { return null; }
return path.match(s.PATH_PATTERN);
// Drop the query string
var queryIndex = path.indexOf("?");
if (queryIndex > -1) {
path = path.substr(0,queryIndex);
}
// Absolute
var match;
if (s.ABSOLUTE_PATT.test(path)) {
info.absolute = true;
// Relative
} else if (s.RELATIVE_PATT.test(path)) {
info.relative = true;
}
// Extension
if (match = path.match(s.EXTENSION_PATT)) {
info.extension = match[1].toLowerCase();
}
return info;
};
/**
@ -1541,6 +1571,7 @@ TODO: WINDOWS ISSUES
};
var p = LoadQueue.prototype = new createjs.AbstractLoader();
LoadQueue.prototype.constructor = LoadQueue;
var s = LoadQueue;
/**
@ -2078,7 +2109,7 @@ TODO: WINDOWS ISSUES
for (var n in this._loadItemsById) {
this._disposeItem(this._loadItemsById[n]);
}
this.init(this.useXHR);
this.init(this.useXHR, this._basePath, this._crossOrigin);
// Remove specific items
} else {
@ -2593,7 +2624,7 @@ TODO: WINDOWS ISSUES
// Determine Extension, etc.
var match = this._parseURI(item.src);
if (match != null) { item.ext = match[6]; }
if (match.extension) { item.ext = match.extension; }
if (item.type == null) {
item.type = this._getTypeByExtension(item.ext);
}
@ -2602,13 +2633,13 @@ TODO: WINDOWS ISSUES
var bp = ""; // Store the generated basePath
var useBasePath = basePath || this._basePath;
var autoId = item.src;
if (match && match[1] == null && match[3] == null) {
if (!match.absolute && !match.relative) {
if (path) {
bp = path;
var pathMatch = this._parsePath(path);
var pathMatch = this._parseURI(path);
autoId = path + autoId;
// Also append basePath
if (useBasePath != null && pathMatch && pathMatch[1] == null && pathMatch[2] == null) {
if (useBasePath != null && !pathMatch.absolute && !pathMatch.relative) {
bp = useBasePath + bp;
}
} else if (useBasePath != null) {
@ -2666,8 +2697,8 @@ TODO: WINDOWS ISSUES
// Update the extension in case the type changed:
match = this._parseURI(item.src);
if (match != null && match[6] != null) {
item.ext = match[6].toLowerCase();
if (match.extension != null) {
item.ext = match.extension;
}
}
}
@ -3252,6 +3283,7 @@ this.createjs = this.createjs||{};
};
var p = TagLoader.prototype = new createjs.AbstractLoader();
TagLoader.prototype.constructor = TagLoader;
// Protected
@ -3396,7 +3428,16 @@ this.createjs = this.createjs||{};
item.type == createjs.LoadQueue.CSS) {
this._startTagVisibility = tag.style.visibility;
tag.style.visibility = "hidden";
(document.body || document.getElementsByTagName("body")[0]).appendChild(tag);
var node = document.body || document.getElementsByTagName("body")[0];
if (node == null) {
if (item.type == createjs.LoadQueue.SVG) {
this._handleSVGError();
return;
} else {
node = document.head || document.getElementsByTagName("head");
}
}
node.appendChild(tag);
}
// Note: Previous versions didn't seem to work when we called load() for OGG tags in Firefox. Seems fixed in 15.0.1
@ -3405,6 +3446,13 @@ this.createjs = this.createjs||{};
}
};
p._handleSVGError = function() {
this._clean();
var event = new createjs.Event("error");
event.text = "SVG_NO_BODY";
this._sendError(event);
};
p._handleJSONPLoad = function(data) {
this._jsonResult = data;
};
@ -3488,8 +3536,8 @@ this.createjs = this.createjs||{};
// case createjs.LoadQueue.CSS:
//LM: We may need to remove CSS tags loaded using a LINK
tag.style.visibility = this._startTagVisibility;
(document.body || document.getElementsByTagName("body")[0]).removeChild(tag);
break;
tag.parentNode && tag.parentNode.contains(tag) && tag.parentNode.removeChild(tag);
break;
default:
}
@ -3618,6 +3666,7 @@ this.createjs = this.createjs || {};
];
var p = XHRLoader.prototype = new createjs.AbstractLoader();
XHRLoader.prototype.constructor = XHRLoader;
//Protected
/**

File diff suppressed because it is too large Load diff

View file

@ -46,7 +46,7 @@ this.createjs = this.createjs||{};
/**
* Contains properties and methods shared by all events for use with
* {{#crossLink "EventDispatcher"}}{{/crossLink}}.
*
*
* Note that Event objects are often reused, so you should never
* rely on an event object's state outside of the call stack it was received in.
* @class Event
@ -59,6 +59,7 @@ var Event = function(type, bubbles, cancelable) {
this.initialize(type, bubbles, cancelable);
};
var p = Event.prototype;
Event.prototype.constructor = Event;
// events:
@ -162,7 +163,7 @@ var p = Event.prototype;
* @readonly
*/
p.immediatePropagationStopped = false;
/**
* Indicates if {{#crossLink "Event/remove"}}{{/crossLink}} has been called on this event.
* @property removed
@ -217,21 +218,21 @@ var p = Event.prototype;
p.stopImmediatePropagation = function() {
this.immediatePropagationStopped = this.propagationStopped = true;
};
/**
* Causes the active listener to be removed via removeEventListener();
*
*
* myBtn.addEventListener("click", function(evt) {
* // do stuff...
* evt.remove(); // removes this listener.
* });
*
*
* @method remove
**/
p.remove = function() {
this.removed = true;
};
/**
* Returns a clone of the Event instance.
* @method clone
@ -343,6 +344,7 @@ var EventDispatcher = function() {
/* this.initialize(); */ // not needed.
};
var p = EventDispatcher.prototype;
EventDispatcher.prototype.constructor = EventDispatcher;
/**
@ -547,19 +549,19 @@ var p = EventDispatcher.prototype;
* @param {Object | String | Event} eventObj An object with a "type" property, or a string type.
* While a generic object will work, it is recommended to use a CreateJS Event instance. If a string is used,
* dispatchEvent will construct an Event instance with the specified type.
* @param {Object} [target] The object to use as the target property of the event object. This will default to the
* dispatching object. <b>This parameter is deprecated and will be removed.</b>
* @return {Boolean} Returns the value of eventObj.defaultPrevented.
**/
p.dispatchEvent = function(eventObj, target) {
p.dispatchEvent = function(eventObj) {
if (typeof eventObj == "string") {
// won't bubble, so skip everything if there's no listeners:
var listeners = this._listeners;
if (!listeners || !listeners[eventObj]) { return false; }
eventObj = new createjs.Event(eventObj);
} else if (eventObj.target && eventObj.clone) {
// redispatching an active event object, so clone it:
eventObj = eventObj.clone();
}
// TODO: deprecated. Target param is deprecated, only use case is MouseEvent/mousemove, remove.
eventObj.target = target||this;
try { eventObj.target = this; } catch (e) {} // try/catch allows redispatching of native events
if (!eventObj.bubbles || !this.parent) {
this._dispatchEvent(eventObj, 2);
@ -631,8 +633,8 @@ var p = EventDispatcher.prototype;
if (eventObj && listeners) {
var arr = listeners[eventObj.type];
if (!arr||!(l=arr.length)) { return; }
eventObj.currentTarget = this;
eventObj.eventPhase = eventPhase;
try { eventObj.currentTarget = this; } catch (e) {}
try { eventObj.eventPhase = eventPhase; } catch (e) {}
eventObj.removed = false;
arr = arr.slice(); // to avoid issues with items being removed or added during the dispatch
for (var i=0; i<l && !eventObj.immediatePropagationStopped; i++) {
@ -651,6 +653,608 @@ var p = EventDispatcher.prototype;
createjs.EventDispatcher = EventDispatcher;
}());
/*
* Ticker
* Visit http://createjs.com/ for documentation, updates and examples.
*
* Copyright (c) 2010 gskinner.com, inc.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @module CreateJS
*/
// namespace:
this.createjs = this.createjs||{};
(function() {
"use strict";
// constructor:
/**
* The Ticker provides a centralized tick or heartbeat broadcast at a set interval. Listeners can subscribe to the tick
* event to be notified when a set time interval has elapsed.
*
* Note that the interval that the tick event is called is a target interval, and may be broadcast at a slower interval
* during times of high CPU load. The Ticker class uses a static interface (ex. <code>Ticker.getPaused()</code>) and
* should not be instantiated.
*
* <h4>Example</h4>
*
* createjs.Ticker.addEventListener("tick", handleTick);
* function handleTick(event) {
* // Actions carried out each frame
* if (!event.paused) {
* // Actions carried out when the Ticker is not paused.
* }
* }
*
* To update a stage every tick, the {{#crossLink "Stage"}}{{/crossLink}} instance can also be used as a listener, as
* it will automatically update when it receives a tick event:
*
* createjs.Ticker.addEventListener("tick", stage);
*
* @class Ticker
* @uses EventDispatcher
* @static
**/
var Ticker = function() {
throw "Ticker cannot be instantiated.";
};
// constants:
/**
* In this mode, Ticker uses the requestAnimationFrame API, but attempts to synch the ticks to target framerate. It
* uses a simple heuristic that compares the time of the RAF return to the target time for the current frame and
* dispatches the tick when the time is within a certain threshold.
*
* This mode has a higher variance for time between frames than TIMEOUT, but does not require that content be time
* based as with RAF while gaining the benefits of that API (screen synch, background throttling).
*
* Variance is usually lowest for framerates that are a divisor of the RAF frequency. This is usually 60, so
* framerates of 10, 12, 15, 20, and 30 work well.
*
* Falls back on TIMEOUT if the requestAnimationFrame API is not supported.
* @property RAF_SYNCHED
* @static
* @type {String}
* @default "synched"
* @readonly
**/
Ticker.RAF_SYNCHED = "synched";
/**
* In this mode, Ticker passes through the requestAnimationFrame heartbeat, ignoring the target framerate completely.
* Because requestAnimationFrame frequency is not deterministic, any content using this mode should be time based.
* You can leverage {{#crossLink "Ticker/getTime"}}{{/crossLink}} and the tick event object's "delta" properties
* to make this easier.
*
* Falls back on TIMEOUT if the requestAnimationFrame API is not supported.
* @property RAF
* @static
* @type {String}
* @default "raf"
* @readonly
**/
Ticker.RAF = "raf";
/**
* In this mode, Ticker uses the setTimeout API. This provides predictable, adaptive frame timing, but does not
* provide the benefits of requestAnimationFrame (screen synch, background throttling).
* @property TIMEOUT
* @static
* @type {String}
* @default "timer"
* @readonly
**/
Ticker.TIMEOUT = "timeout";
// events:
/**
* Dispatched each tick. The event will be dispatched to each listener even when the Ticker has been paused using
* {{#crossLink "Ticker/setPaused"}}{{/crossLink}}.
*
* <h4>Example</h4>
*
* createjs.Ticker.addEventListener("tick", handleTick);
* function handleTick(event) {
* console.log("Paused:", event.paused, event.delta);
* }
*
* @event tick
* @param {Object} target The object that dispatched the event.
* @param {String} type The event type.
* @param {Boolean} paused Indicates whether the ticker is currently paused.
* @param {Number} delta The time elapsed in ms since the last tick.
* @param {Number} time The total time in ms since Ticker was initialized.
* @param {Number} runTime The total time in ms that Ticker was not paused since it was initialized. For example,
* you could determine the amount of time that the Ticker has been paused since initialization with time-runTime.
* @since 0.6.0
*/
// public static properties:
/**
* Deprecated in favour of {{#crossLink "Ticker/timingMode"}}{{/crossLink}}, and will be removed in a future version. If true, timingMode will
* use {{#crossLink "Ticker/RAF_SYNCHED"}}{{/crossLink}} by default.
* @deprecated Deprecated in favour of {{#crossLink "Ticker/timingMode"}}{{/crossLink}}.
* @property useRAF
* @static
* @type {Boolean}
* @default false
**/
Ticker.useRAF = false;
/**
* Specifies the timing api (setTimeout or requestAnimationFrame) and mode to use. See
* {{#crossLink "Ticker/TIMEOUT"}}{{/crossLink}}, {{#crossLink "Ticker/RAF"}}{{/crossLink}}, and
* {{#crossLink "Ticker/RAF_SYNCHED"}}{{/crossLink}} for mode details.
* @property timingMode
* @static
* @type {String}
* @default Ticker.TIMEOUT
**/
Ticker.timingMode = null;
/**
* Specifies a maximum value for the delta property in the tick event object. This is useful when building time
* based animations and systems to prevent issues caused by large time gaps caused by background tabs, system sleep,
* alert dialogs, or other blocking routines. Double the expected frame duration is often an effective value
* (ex. maxDelta=50 when running at 40fps).
*
* This does not impact any other values (ex. time, runTime, etc), so you may experience issues if you enable maxDelta
* when using both delta and other values.
*
* If 0, there is no maximum.
* @property maxDelta
* @static
* @type {number}
* @default 0
*/
Ticker.maxDelta = 0;
// mix-ins:
// EventDispatcher methods:
Ticker.removeEventListener = null;
Ticker.removeAllEventListeners = null;
Ticker.dispatchEvent = null;
Ticker.hasEventListener = null;
Ticker._listeners = null;
createjs.EventDispatcher.initialize(Ticker); // inject EventDispatcher methods.
Ticker._addEventListener = Ticker.addEventListener;
Ticker.addEventListener = function() {
!Ticker._inited&&Ticker.init();
return Ticker._addEventListener.apply(Ticker, arguments);
};
// private static properties:
/**
* @property _paused
* @type {Boolean}
* @protected
**/
Ticker._paused = false;
/**
* @property _inited
* @type {Boolean}
* @protected
**/
Ticker._inited = false;
/**
* @property _startTime
* @type {Number}
* @protected
**/
Ticker._startTime = 0;
/**
* @property _pausedTime
* @type {Number}
* @protected
**/
Ticker._pausedTime=0;
/**
* The number of ticks that have passed
* @property _ticks
* @type {Number}
* @protected
**/
Ticker._ticks = 0;
/**
* The number of ticks that have passed while Ticker has been paused
* @property _pausedTicks
* @type {Number}
* @protected
**/
Ticker._pausedTicks = 0;
/**
* @property _interval
* @type {Number}
* @protected
**/
Ticker._interval = 50;
/**
* @property _lastTime
* @type {Number}
* @protected
**/
Ticker._lastTime = 0;
/**
* @property _times
* @type {Array}
* @protected
**/
Ticker._times = null;
/**
* @property _tickTimes
* @type {Array}
* @protected
**/
Ticker._tickTimes = null;
/**
* Stores the timeout or requestAnimationFrame id.
* @property _timerId
* @type {Number}
* @protected
**/
Ticker._timerId = null;
/**
* True if currently using requestAnimationFrame, false if using setTimeout.
* @property _raf
* @type {Boolean}
* @protected
**/
Ticker._raf = true;
// public static methods:
/**
* Starts the tick. This is called automatically when the first listener is added.
* @method init
* @static
**/
Ticker.init = function() {
if (Ticker._inited) { return; }
Ticker._inited = true;
Ticker._times = [];
Ticker._tickTimes = [];
Ticker._startTime = Ticker._getTime();
Ticker._times.push(Ticker._lastTime = 0);
Ticker.setInterval(Ticker._interval);
};
/**
* Stops the Ticker and removes all listeners. Use init() to restart the Ticker.
* @method reset
* @static
**/
Ticker.reset = function() {
if (Ticker._raf) {
var f = window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.oCancelAnimationFrame || window.msCancelAnimationFrame;
f&&f(Ticker._timerId);
} else {
clearTimeout(Ticker._timerId);
}
Ticker.removeAllEventListeners("tick");
Ticker._timerId = null;
Ticker._inited = false;
};
/**
* Sets the target time (in milliseconds) between ticks. Default is 50 (20 FPS).
*
* Note actual time between ticks may be more than requested depending on CPU load.
* @method setInterval
* @static
* @param {Number} interval Time in milliseconds between ticks. Default value is 50.
**/
Ticker.setInterval = function(interval) {
Ticker._interval = interval;
if (!Ticker._inited) { return; }
Ticker._setupTick();
};
/**
* Returns the current target time between ticks, as set with {{#crossLink "Ticker/setInterval"}}{{/crossLink}}.
* @method getInterval
* @static
* @return {Number} The current target interval in milliseconds between tick events.
**/
Ticker.getInterval = function() {
return Ticker._interval;
};
/**
* Sets the target frame rate in frames per second (FPS). For example, with an interval of 40, <code>getFPS()</code>
* will return 25 (1000ms per second divided by 40 ms per tick = 25fps).
* @method setFPS
* @static
* @param {Number} value Target number of ticks broadcast per second.
**/
Ticker.setFPS = function(value) {
Ticker.setInterval(1000/value);
};
/**
* Returns the target frame rate in frames per second (FPS). For example, with an interval of 40, <code>getFPS()</code>
* will return 25 (1000ms per second divided by 40 ms per tick = 25fps).
* @method getFPS
* @static
* @return {Number} The current target number of frames / ticks broadcast per second.
**/
Ticker.getFPS = function() {
return 1000/Ticker._interval;
};
/**
* Returns the average time spent within a tick. This can vary significantly from the value provided by getMeasuredFPS
* because it only measures the time spent within the tick execution stack.
*
* Example 1: With a target FPS of 20, getMeasuredFPS() returns 20fps, which indicates an average of 50ms between
* the end of one tick and the end of the next. However, getMeasuredTickTime() returns 15ms. This indicates that
* there may be up to 35ms of "idle" time between the end of one tick and the start of the next.
*
* Example 2: With a target FPS of 30, getFPS() returns 10fps, which indicates an average of 100ms between the end of
* one tick and the end of the next. However, getMeasuredTickTime() returns 20ms. This would indicate that something
* other than the tick is using ~80ms (another script, DOM rendering, etc).
* @method getMeasuredTickTime
* @static
* @param {Number} [ticks] The number of previous ticks over which to measure the average time spent in a tick.
* Defaults to the number of ticks per second. To get only the last tick's time, pass in 1.
* @return {Number} The average time spent in a tick in milliseconds.
**/
Ticker.getMeasuredTickTime = function(ticks) {
var ttl=0, times=Ticker._tickTimes;
if (!times || times.length < 1) { return -1; }
// by default, calculate average for the past ~1 second:
ticks = Math.min(times.length, ticks||(Ticker.getFPS()|0));
for (var i=0; i<ticks; i++) { ttl += times[i]; }
return ttl/ticks;
};
/**
* Returns the actual frames / ticks per second.
* @method getMeasuredFPS
* @static
* @param {Number} [ticks] The number of previous ticks over which to measure the actual frames / ticks per second.
* Defaults to the number of ticks per second.
* @return {Number} The actual frames / ticks per second. Depending on performance, this may differ
* from the target frames per second.
**/
Ticker.getMeasuredFPS = function(ticks) {
var times = Ticker._times;
if (!times || times.length < 2) { return -1; }
// by default, calculate fps for the past ~1 second:
ticks = Math.min(times.length-1, ticks||(Ticker.getFPS()|0));
return 1000/((times[0]-times[ticks])/ticks);
};
/**
* Changes the "paused" state of the Ticker, which can be retrieved by the {{#crossLink "Ticker/getPaused"}}{{/crossLink}}
* method, and is passed as the "paused" property of the <code>tick</code> event. When the ticker is paused, all
* listeners will still receive a tick event, but the <code>paused</code> property will be false.
*
* Note that in EaselJS v0.5.0 and earlier, "pauseable" listeners would <strong>not</strong> receive the tick
* callback when Ticker was paused. This is no longer the case.
*
* <h4>Example</h4>
*
* createjs.Ticker.addEventListener("tick", handleTick);
* createjs.Ticker.setPaused(true);
* function handleTick(event) {
* console.log("Paused:", event.paused, createjs.Ticker.getPaused());
* }
*
* @method setPaused
* @static
* @param {Boolean} value Indicates whether to pause (true) or unpause (false) Ticker.
**/
Ticker.setPaused = function(value) {
Ticker._paused = value;
};
/**
* Returns a boolean indicating whether Ticker is currently paused, as set with {{#crossLink "Ticker/setPaused"}}{{/crossLink}}.
* When the ticker is paused, all listeners will still receive a tick event, but this value will be false.
*
* Note that in EaselJS v0.5.0 and earlier, "pauseable" listeners would <strong>not</strong> receive the tick
* callback when Ticker was paused. This is no longer the case.
*
* <h4>Example</h4>
*
* createjs.Ticker.addEventListener("tick", handleTick);
* createjs.Ticker.setPaused(true);
* function handleTick(event) {
* console.log("Paused:", createjs.Ticker.getPaused());
* }
*
* @method getPaused
* @static
* @return {Boolean} Whether the Ticker is currently paused.
**/
Ticker.getPaused = function() {
return Ticker._paused;
};
/**
* Returns the number of milliseconds that have elapsed since Ticker was initialized via {{#crossLink "Ticker/init"}}.
* Returns -1 if Ticker has not been initialized. For example, you could use
* this in a time synchronized animation to determine the exact amount of time that has elapsed.
* @method getTime
* @static
* @param {Boolean} [runTime=false] If true only time elapsed while Ticker was not paused will be returned.
* If false, the value returned will be total time elapsed since the first tick event listener was added.
* @return {Number} Number of milliseconds that have elapsed since Ticker was initialized or -1.
**/
Ticker.getTime = function(runTime) {
return Ticker._startTime ? Ticker._getTime() - Ticker._startTime - (runTime ? Ticker._pausedTime : 0) : -1;
};
/**
* Similar to getTime(), but returns the time included with the current (or most recent) tick event object.
* @method getEventTime
* @param runTime {Boolean} [runTime=false] If true, the runTime property will be returned instead of time.
* @returns {number} The time or runTime property from the most recent tick event or -1.
*/
Ticker.getEventTime = function(runTime) {
return Ticker._startTime ? (Ticker._lastTime || Ticker._startTime) - (runTime ? Ticker._pausedTime : 0) : -1;
};
/**
* Returns the number of ticks that have been broadcast by Ticker.
* @method getTicks
* @static
* @param {Boolean} pauseable Indicates whether to include ticks that would have been broadcast
* while Ticker was paused. If true only tick events broadcast while Ticker is not paused will be returned.
* If false, tick events that would have been broadcast while Ticker was paused will be included in the return
* value. The default value is false.
* @return {Number} of ticks that have been broadcast.
**/
Ticker.getTicks = function(pauseable) {
return Ticker._ticks - (pauseable ?Ticker._pausedTicks : 0);
};
// private static methods:
/**
* @method _handleSynch
* @static
* @protected
**/
Ticker._handleSynch = function() {
var time = Ticker._getTime() - Ticker._startTime;
Ticker._timerId = null;
Ticker._setupTick();
// run if enough time has elapsed, with a little bit of flexibility to be early:
if (time - Ticker._lastTime >= (Ticker._interval-1)*0.97) {
Ticker._tick();
}
};
/**
* @method _handleRAF
* @static
* @protected
**/
Ticker._handleRAF = function() {
Ticker._timerId = null;
Ticker._setupTick();
Ticker._tick();
};
/**
* @method _handleTimeout
* @static
* @protected
**/
Ticker._handleTimeout = function() {
Ticker._timerId = null;
Ticker._setupTick();
Ticker._tick();
};
/**
* @method _setupTick
* @static
* @protected
**/
Ticker._setupTick = function() {
if (Ticker._timerId != null) { return; } // avoid duplicates
var mode = Ticker.timingMode||(Ticker.useRAF&&Ticker.RAF_SYNCHED);
if (mode == Ticker.RAF_SYNCHED || mode == Ticker.RAF) {
var f = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame;
if (f) {
Ticker._timerId = f(mode == Ticker.RAF ? Ticker._handleRAF : Ticker._handleSynch);
Ticker._raf = true;
return;
}
}
Ticker._raf = false;
Ticker._timerId = setTimeout(Ticker._handleTimeout, Ticker._interval);
};
/**
* @method _tick
* @static
* @protected
**/
Ticker._tick = function() {
var time = Ticker._getTime();
var adjTime = time-Ticker._startTime;
var elapsedTime = time-Ticker._lastTime;
var paused = Ticker._paused;
Ticker._ticks++;
if (paused) {
Ticker._pausedTicks++;
Ticker._pausedTime += elapsedTime;
}
Ticker._lastTime = time;
if (Ticker.hasEventListener("tick")) {
var event = new createjs.Event("tick");
var maxDelta = Ticker.maxDelta;
event.delta = (maxDelta && elapsedTime > maxDelta) ? maxDelta : elapsedTime;
event.paused = paused;
event.time = adjTime;
event.runTime = adjTime-Ticker._pausedTime;
Ticker.dispatchEvent(event);
}
Ticker._tickTimes.unshift(Ticker._getTime()-time);
while (Ticker._tickTimes.length > 100) { Ticker._tickTimes.pop(); }
Ticker._times.unshift(adjTime);
while (Ticker._times.length > 100) { Ticker._times.pop(); }
};
/**
* @method _getTime
* @static
* @protected
**/
var now = window.performance && (performance.now || performance.mozNow || performance.msNow || performance.oNow || performance.webkitNow);
Ticker._getTime = function() {
return (now&&now.call(performance))||(new Date().getTime());
};
createjs.Ticker = Ticker;
}());
/*
* Tween
* Visit http://createjs.com/ for documentation, updates and examples.
*
@ -710,11 +1314,6 @@ createjs.EventDispatcher = EventDispatcher;
* //Tween complete
* }
*
* <h4>Required Support<h4>
* Tweenjs requires a ticker function, which is included in <a href="http://www.easeljs.com">EaselJS</a>.
* If you are not using EaselJS, you must build your own ticker function that calls {{#crossLink "Tween/tick"}}{{/crossLink}}
* on the tweens.
*
* <h4>Browser Support</h4>
* TweenJS will work in all browsers.
*
@ -764,7 +1363,7 @@ this.createjs = this.createjs||{};
* All properties default to false. Supported props are:<UL>
* <LI> loop: sets the loop property on this tween.</LI>
* <LI> useTicks: uses ticks for all durations instead of milliseconds.</LI>
* <LI> ignoreGlobalPause: sets the ignoreGlobalPause property on this tween.</LI>
* <LI> ignoreGlobalPause: sets the {{#crossLink "Tween/ignoreGlobalPause:property"}}{{/crossLink}} property on this tween.</LI>
* <LI> override: if true, `Tween.removeTweens(target)` will be called to remove any other tweens with the same target.
* <LI> paused: indicates whether to start the tween paused.</LI>
* <LI> position: indicates the initial position for this tween.</LI>
@ -779,6 +1378,7 @@ var Tween = function(target, props, pluginData) {
this.initialize(target, props, pluginData);
};
var p = Tween.prototype = new createjs.EventDispatcher();
Tween.prototype.constructor = Tween;
// static interface:
/**
@ -843,7 +1443,7 @@ var p = Tween.prototype = new createjs.EventDispatcher();
* All properties default to false. Supported props are:<UL>
* <LI> loop: sets the loop property on this tween.</LI>
* <LI> useTicks: uses ticks for all durations instead of milliseconds.</LI>
* <LI> ignoreGlobalPause: sets the ignoreGlobalPause property on this tween.</LI>
* <LI> ignoreGlobalPause: sets the {{#crossLink "Tween/ignoreGlobalPause:property"}}{{/crossLink}} property on this tween.</LI>
* <LI> override: if true, Tween.removeTweens(target) will be called to remove any other tweens with the same target.
* <LI> paused: indicates whether to start the tween paused.</LI>
* <LI> position: indicates the initial position for this tween.</LI>
@ -863,15 +1463,13 @@ var p = Tween.prototype = new createjs.EventDispatcher();
};
/**
* Advances all tweens. This typically uses the Ticker class (available in the EaselJS library), but you can call it
* Advances all tweens. This typically uses the {{#crossLink "Ticker"}}{{/crossLink}} class, but you can call it
* manually if you prefer to use your own "heartbeat" implementation.
*
* Note: Currently, EaselJS must be included <em>before</em> TweenJS to ensure Ticker exists during initialization.
* @method tick
* @param {Number} delta The change in time in milliseconds since the last tick. Required unless all tweens have
* <code>useTicks</code> set to true.
* @param {Boolean} paused Indicates whether a global pause is in effect. Tweens with <code>ignoreGlobalPause</code>
* will ignore this, but all others will pause if this is true.
* @param {Boolean} paused Indicates whether a global pause is in effect. Tweens with {{#crossLink "Tween/ignoreGlobalPause:property"}}{{/crossLink}}
* will ignore this, but all others will pause if this is `true`.
* @static
*/
Tween.tick = function(delta, paused) {
@ -887,7 +1485,8 @@ var p = Tween.prototype = new createjs.EventDispatcher();
* Handle events that result from Tween being used as an event handler. This is included to allow Tween to handle
* tick events from <code>createjs.Ticker</code>. No other events are handled in Tween.
* @method handleEvent
* @param {Object} event An event object passed in by the EventDispatcher. Will usually be of type "tick".
* @param {Object} event An event object passed in by the {{#crossLink "EventDispatcher"}}{{/crossLink}}. Will
* usually be of type "tick".
* @private
* @static
* @since 0.4.2
@ -909,9 +1508,10 @@ var p = Tween.prototype = new createjs.EventDispatcher();
if (!target.tweenjs_count) { return; }
var tweens = Tween._tweens;
for (var i=tweens.length-1; i>=0; i--) {
if (tweens[i]._target == target) {
tweens[i]._paused = true;
tweens.splice(i,1);
var tween = tweens[i];
if (tween._target == target) {
tween._paused = true;
tweens.splice(i, 1);
}
}
target.tweenjs_count = 0;
@ -927,7 +1527,7 @@ var p = Tween.prototype = new createjs.EventDispatcher();
var tweens = Tween._tweens;
for (var i= 0, l=tweens.length; i<l; i++) {
var tween = tweens[i];
tween.paused = true;
tween._paused = true;
tween.target.tweenjs_count = 0;
}
tweens.length = 0;
@ -947,8 +1547,8 @@ var p = Tween.prototype = new createjs.EventDispatcher();
};
/**
* Installs a plugin, which can modify how certain properties are handled when tweened. See the CSSPlugin for an
* example of how to write TweenJS plugins.
* Installs a plugin, which can modify how certain properties are handled when tweened. See the {{#crossLink "CSSPlugin"}}{{/crossLink}}
* for an example of how to write TweenJS plugins.
* @method installPlugin
* @static
* @param {Object} plugin The plugin class to install
@ -974,7 +1574,7 @@ var p = Tween.prototype = new createjs.EventDispatcher();
* Registers or unregisters a tween with the ticking system.
* @method _register
* @param {Tween} tween The tween instance to register or unregister.
* @param {Boolean} value If true, the tween is registered. If false the tween is unregistered.
* @param {Boolean} value If true, the tween is registered. If false the tween is unregistered.
* @static
* @protected
*/
@ -1000,9 +1600,10 @@ var p = Tween.prototype = new createjs.EventDispatcher();
// public properties:
/**
* Causes this tween to continue playing when a global pause is active. For example, if TweenJS is using Ticker,
* then setting this to true (the default) will cause this tween to be paused when <code>Ticker.setPaused(true)</code> is called.
* See Tween.tick() for more info. Can be set via the props param.
* Causes this tween to continue playing when a global pause is active. For example, if TweenJS is using {{#crossLink "Ticker"}}{{/crossLink}},
* then setting this to true (the default) will cause this tween to be paused when <code>Ticker.setPaused(true)</code>
* is called. See the Tween {{#crossLink "Tween/tick"}}{{/crossLink}} method for more info. Can be set via the props
* parameter.
* @property ignoreGlobalPause
* @type Boolean
* @default false
@ -1360,7 +1961,8 @@ var p = Tween.prototype = new createjs.EventDispatcher();
/**
* Advances this tween by the specified amount of time in milliseconds (or ticks if <code>useTicks</code> is true).
* This is normally called automatically by the Tween engine (via <code>Tween.tick</code>), but is exposed for advanced uses.
* This is normally called automatically by the Tween engine (via <code>Tween.tick</code>), but is exposed for
* advanced uses.
* @method tick
* @param {Number} delta The time to advance in milliseconds (or ticks if <code>useTicks</code> is true).
*/
@ -1376,6 +1978,7 @@ var p = Tween.prototype = new createjs.EventDispatcher();
* @return {Tween} This tween instance (for chaining calls)
*/
p.setPaused = function(value) {
if (this._paused === !!value) { return this; }
this._paused = !!value;
Tween._register(this, !value);
return this;
@ -1630,6 +2233,7 @@ var Timeline = function(tweens, labels, props) {
this.initialize(tweens, labels, props);
};
var p = Timeline.prototype = new createjs.EventDispatcher();
Timeline.prototype.constructor = Timeline;
// public properties:
@ -1701,7 +2305,7 @@ var p = Timeline.prototype = new createjs.EventDispatcher();
* @protected
**/
p._labels = null;
/**
* @property _labelList
* @type Array[Object]
@ -1828,7 +2432,7 @@ var p = Timeline.prototype = new createjs.EventDispatcher();
p.setLabels = function(o) {
this._labels = o ? o : {};
};
/**
* Returns a sorted list of the labels defined on this timeline.
* @method getLabels
@ -1846,7 +2450,7 @@ var p = Timeline.prototype = new createjs.EventDispatcher();
}
return list;
};
/**
* Returns the name of the label on or immediately before the current position. For example, given a timeline with
* two labels, "first" on frame index 4, and "second" on frame 8, getCurrentLabel would return:<UL>
@ -1867,7 +2471,7 @@ var p = Timeline.prototype = new createjs.EventDispatcher();
}
return null;
};
/**
* Unpauses this timeline and jumps to the specified position or label.
* @method gotoAndPlay
@ -1953,7 +2557,7 @@ var p = Timeline.prototype = new createjs.EventDispatcher();
* @param {String|Number} positionOrLabel A numeric position value or label string.
**/
p.resolve = function(positionOrLabel) {
var pos = parseFloat(positionOrLabel);
var pos = Number(positionOrLabel);
if (isNaN(pos)) { pos = this._labels[positionOrLabel]; }
return pos;
};
@ -2755,6 +3359,6 @@ this.createjs = this.createjs || {};
* @type String
* @static
**/
s.buildDate = /*date*/"Thu, 12 Dec 2013 23:37:07 GMT"; // injected by build process
s.buildDate = /*date*/"Fri, 24 Oct 2014 16:09:53 GMT"; // injected by build process
})();