diff --git a/.gitignore b/.gitignore index 12e1b62..7395838 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .DS_Store -.project \ No newline at end of file +.project +*.sublime-* \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index f7143da..d185fd6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,10 +1,12 @@ module.exports = function(grunt) { + grunt.loadNpmTasks('grunt-concat-sourcemap'); grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-connect'); grunt.loadNpmTasks('grunt-contrib-qunit'); grunt.loadNpmTasks('grunt-contrib-yuidoc'); + grunt.loadNpmTasks('grunt-contrib-watch'); var root = 'src/pixi/', debug = 'bin/pixi.dev.js', @@ -31,10 +33,14 @@ module.exports = function(grunt) { '<%= dirs.src %>/utils/Detector.js', '<%= dirs.src %>/utils/Polyk.js', '<%= dirs.src %>/renderers/webgl/WebGLShaders.js', + '<%= dirs.src %>/renderers/webgl/PixiShader.js', + '<%= dirs.src %>/renderers/webgl/StripShader.js', + '<%= dirs.src %>/renderers/webgl/PrimitiveShader.js', '<%= dirs.src %>/renderers/webgl/WebGLGraphics.js', '<%= dirs.src %>/renderers/webgl/WebGLRenderer.js', '<%= dirs.src %>/renderers/webgl/WebGLBatch.js', '<%= dirs.src %>/renderers/webgl/WebGLRenderGroup.js', + '<%= dirs.src %>/renderers/webgl/WebGLFilterManager.js', '<%= dirs.src %>/renderers/canvas/CanvasRenderer.js', '<%= dirs.src %>/renderers/canvas/CanvasGraphics.js', '<%= dirs.src %>/primitives/Graphics.js', @@ -53,6 +59,22 @@ module.exports = function(grunt) { '<%= dirs.src %>/loaders/ImageLoader.js', '<%= dirs.src %>/loaders/BitmapFontLoader.js', '<%= dirs.src %>/loaders/SpineLoader.js', + '<%= dirs.src %>/filters/AbstractFilter.js', + '<%= dirs.src %>/filters/ColorMatrixFilter.js', + '<%= dirs.src %>/filters/GrayFilter.js', + '<%= dirs.src %>/filters/DisplacementFilter.js', + '<%= dirs.src %>/filters/PixelateFilter.js', + '<%= dirs.src %>/filters/BlurXFilter.js', + '<%= dirs.src %>/filters/BlurYFilter.js', + '<%= dirs.src %>/filters/BlurFilter.js', + '<%= dirs.src %>/filters/InvertFilter.js', + '<%= dirs.src %>/filters/SepiaFilter.js', + '<%= dirs.src %>/filters/TwistFilter.js', + '<%= dirs.src %>/filters/ColorStepFilter.js', + '<%= dirs.src %>/filters/DotScreenFilter.js', + '<%= dirs.src %>/filters/CrossHatchFilter.js', + '<%= dirs.src %>/filters/RGBSplitFilter.js', + '<%= dirs.src %>/Outro.js' ], banner = [ '/**', @@ -74,7 +96,6 @@ module.exports = function(grunt) { dirs: { build: 'bin', docs: 'docs', - examples: 'examples', src: 'src/pixi', test: 'test' }, @@ -93,6 +114,16 @@ module.exports = function(grunt) { dest: '<%= files.build %>' } }, + concat_sourcemap: { + dev: { + files: { + '<%= files.build %>': srcFiles + }, + options: { + sourceRoot: '../' + } + } + }, jshint: { beforeconcat: srcFiles, test: ['<%= files.testBlob %>'], @@ -110,24 +141,6 @@ module.exports = function(grunt) { dest: '<%= files.buildMin %>' } }, - distribute: { - examples: [ - 'examples/example 1 - Basics', - 'examples/example 2 - SpriteSheet', - 'examples/example 3 - MovieClip', - 'examples/example 4 - Balls', - 'examples/example 5 - Morph', - 'examples/example 6 - Interactivity', - 'examples/example 7 - Transparent Background', - 'examples/example 8 - Dragging', - 'examples/example 9 - Tiling Texture', - 'examples/example 10 - Text', - 'examples/example 11 - RenderTexture', - 'examples/example 12 - Spine', - 'examples/example 13 - Graphics', - 'examples/example 14 - Masking' - ] - }, connect: { qunit: { options: { @@ -162,29 +175,23 @@ module.exports = function(grunt) { outdir: '<%= dirs.docs %>' } } + }, + watch: { + dev: { + files: ['Gruntfile.js', 'src/**/*.js', 'examples/**/*.html'], + tasks: ['build-debug'], + + // We would need to inject + + + +
+
+
+ +

+ +
+
+ API Docs for: 1.3.0 +
+
+
+ + +
+
+ Show: + + + + + + + +
+ + +
+
+
+

AbstractFilter Class

+
+ + + + + + + + + + + Module: PIXI + + + + +
+ + + +
+

This is the base class for creating a pixi.js filter. Currently only webGL supports filters. +If you want to make a custom filter this should be your base class.

+ +
+ + +
+

Constructor

+
+

AbstractFilter

+ + +
+ (
    + +
  • + + fragmentSrc + +
  • + +
  • + + unifroms + +
  • + +
) +
+ + + + + + + + + + + + + + + + +
+ + + +

+ + Defined in + + + + + src/pixi/filters/AbstractFilter.js:6 + +

+ + + + + +
+ +
+ +
+ + +
+

Parameters:

+ +
    + +
  • + + fragmentSrc + Object + + + + +
    + +
    + + +
  • + +
  • + + unifroms + Object + + + + +
    + +
    + + +
  • + +
+
+ + + + + +
+ +
+ + +
+ + +
+
+

Item Index

+ + + + +
+

Properties

+ + +
+ + + + + +
+ + + + +
+

Properties

+ + +
+

passes

+ Array an array of filter objects + + + + + private + + + + + + +
+ + + +

+ + Defined in + + + + + src/pixi/filters/AbstractFilter.js:16 + +

+ + + + +
+ +
+

An array of passes - some filters contain a few steps this array simply stores the steps in a liniear fashion. +For example the blur filter has two passes blurX and blurY.

+ +
+ + + + + + +
+ + +
+

uniforms

+ Unknown + + + + + private + + + + + + +
+ + + +

+ + Defined in + + + + + src/pixi/filters/AbstractFilter.js:29 + +

+ + + + +
+ +
+ +
+ + + + + + +
+ + +
+ + + + + +
+
+ +
+
+
+
+
+
+ + + + + + + + + + diff --git a/docs/classes/AssetLoader.html b/docs/classes/AssetLoader.html index 71c3f58..49df281 100644 --- a/docs/classes/AssetLoader.html +++ b/docs/classes/AssetLoader.html @@ -3,11 +3,11 @@ AssetLoader - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
-

+

@@ -41,71 +41,95 @@ @@ -145,16 +169,21 @@

AssetLoader Class

- - -
- Extends EventTarget +
+ Uses +
+ + @@ -170,9 +199,12 @@
-

A Class that loads a bunch of images / sprite sheet / bitmap font files. Once the assets have been loaded they are added to the PIXI Texture cache and can be accessed easily through PIXI.Texture.fromImage() and PIXI.Sprite.fromImage() -When all items have been loaded this class will dispatch a "onLoaded" event -As each individual item is loaded this class will dispatch a "onProgress" event

+

A Class that loads a bunch of images / sprite sheet / bitmap font files. Once the +assets have been loaded they are added to the PIXI Texture cache and can be accessed +easily through PIXI.Texture.fromImage() and PIXI.Sprite.fromImage() +When all items have been loaded this class will dispatch a "onLoaded" event +As each individual item is loaded this class will dispatch a "onProgress" event

+
@@ -191,6 +223,12 @@ As each individual item is loaded this class will dispatch a "onProgress" event< +
  • + + crossorigin + +
  • + )
    @@ -220,7 +258,7 @@ As each individual item is loaded this class will dispatch a "onProgress" event< - src/pixi/loaders/AssetLoader.js:5 + src/pixi/loaders/AssetLoader.js:5

    @@ -243,13 +281,33 @@ As each individual item is loaded this class will dispatch a "onProgress" event<
  • assetURLs - Array + Array
    -

    an array of image/sprite sheet urls that you would like loaded supported. Supported image formats include "jpeg", "jpg", "png", "gif". Supported sprite sheet data formats only include "JSON" at this time. Supported bitmap font data formats include "xml" and "fnt".

    +

    an array of image/sprite sheet urls that you would like loaded + supported. Supported image formats include "jpeg", "jpg", "png", "gif". Supported + sprite sheet data formats only include "JSON" at this time. Supported bitmap font + data formats include "xml" and "fnt".

    + +
    + + +
  • + +
  • + + crossorigin + Boolean + + + + +
    +

    Whether requests should be treated as crossorigin

    +
    @@ -272,6 +330,8 @@ As each individual item is loaded this class will dispatch a "onProgress" event<
  • Index
  • +
  • Methods
  • +
  • Properties
  • @@ -286,18 +346,54 @@ As each individual item is loaded this class will dispatch a "onProgress" event<

    Item Index

    +
    +

    Methods

    + + +
    +

    Properties

    - @@ -480,6 +525,13 @@ http://www.bmglyph.com/ for mac.

      +
    • + _interactive + + + +
    • +
    • alpha @@ -499,6 +551,27 @@ http://www.bmglyph.com/ for mac.

      +
    • + +
    • + color + + + +
    • + +
    • + dynamic + + + +
    • + +
    • + filters + + +
    • @@ -513,6 +586,13 @@ http://www.bmglyph.com/ for mac.

      +
    • + +
    • + localTransform + + +
    • @@ -541,6 +621,13 @@ http://www.bmglyph.com/ for mac.

      +
    • + +
    • + renderable + + +
    • @@ -569,6 +656,20 @@ http://www.bmglyph.com/ for mac.

      +
    • + +
    • + worldAlpha + + + +
    • + +
    • + worldTransform + + +
    @@ -594,7 +695,7 @@ http://www.bmglyph.com/ for mac.

  • - DisplayObject + child
  • @@ -620,11 +721,11 @@ http://www.bmglyph.com/ for mac.

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:42 + src/pixi/display/DisplayObjectContainer.js:32

    @@ -636,6 +737,7 @@ http://www.bmglyph.com/ for mac.

    Adds a child to the container.

    +
    @@ -646,14 +748,15 @@ http://www.bmglyph.com/ for mac.

  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to add to the container

    +
    @@ -678,7 +781,7 @@ http://www.bmglyph.com/ for mac.

  • - DisplayObject + child
  • @@ -710,11 +813,11 @@ http://www.bmglyph.com/ for mac.

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:139 + src/pixi/display/DisplayObjectContainer.js:120

    @@ -726,6 +829,7 @@ http://www.bmglyph.com/ for mac.

    Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown

    +
    @@ -736,14 +840,15 @@ http://www.bmglyph.com/ for mac.

  • - DisplayObject + child DisplayObject
    - +

    The child to add

    +
    @@ -758,7 +863,8 @@ http://www.bmglyph.com/ for mac.

    - +

    The index to place the child in

    +
    @@ -809,11 +915,11 @@ http://www.bmglyph.com/ for mac.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:109 + src/pixi/display/DisplayObject.js:174

    @@ -825,6 +931,7 @@ http://www.bmglyph.com/ for mac.

    A callback that is used when the users clicks on the displayObject with their mouse

    +
    @@ -836,7 +943,7 @@ http://www.bmglyph.com/ for mac.

  • interactionData - InteractionData + InteractionData @@ -893,11 +1000,11 @@ http://www.bmglyph.com/ for mac.

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:274 + src/pixi/display/DisplayObjectContainer.js:256

    @@ -909,6 +1016,7 @@ http://www.bmglyph.com/ for mac.

    Returns the Child at the specified index

    +
    @@ -926,7 +1034,8 @@ http://www.bmglyph.com/ for mac.

    - +

    The index to get the child from

    +
    @@ -977,11 +1086,11 @@ http://www.bmglyph.com/ for mac.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:115 + src/pixi/display/DisplayObject.js:180

    @@ -993,6 +1102,7 @@ http://www.bmglyph.com/ for mac.

    A callback that is used when the user clicks the mouse down over the sprite

    +
    @@ -1004,7 +1114,7 @@ http://www.bmglyph.com/ for mac.

  • interactionData - InteractionData + InteractionData @@ -1061,11 +1171,11 @@ http://www.bmglyph.com/ for mac.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:141 + src/pixi/display/DisplayObject.js:206

    @@ -1077,6 +1187,7 @@ http://www.bmglyph.com/ for mac.

    A callback that is used when the users mouse leaves the displayObject

    +
    @@ -1088,7 +1199,7 @@ http://www.bmglyph.com/ for mac.

  • interactionData - InteractionData + InteractionData @@ -1145,11 +1256,11 @@ http://www.bmglyph.com/ for mac.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:135 + src/pixi/display/DisplayObject.js:200

    @@ -1161,6 +1272,7 @@ http://www.bmglyph.com/ for mac.

    A callback that is used when the users mouse rolls over the displayObject

    +
    @@ -1172,7 +1284,7 @@ http://www.bmglyph.com/ for mac.

  • interactionData - InteractionData + InteractionData @@ -1229,11 +1341,11 @@ http://www.bmglyph.com/ for mac.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:121 + src/pixi/display/DisplayObject.js:186

    @@ -1246,6 +1358,7 @@ http://www.bmglyph.com/ for mac.

    A callback that is used when the user releases the mouse that was over the displayObject for this callback to be fired the mouse must have been pressed down over the displayObject

    +
    @@ -1257,7 +1370,7 @@ for this callback to be fired the mouse must have been pressed down over the dis
  • interactionData - InteractionData + InteractionData @@ -1314,11 +1427,11 @@ for this callback to be fired the mouse must have been pressed down over the dis

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:128 + src/pixi/display/DisplayObject.js:193

    @@ -1331,6 +1444,7 @@ for this callback to be fired the mouse must have been pressed down over the dis

    A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject for this callback to be fired, The touch must have started over the displayObject

    +
    @@ -1342,7 +1456,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • interactionData - InteractionData + InteractionData @@ -1373,7 +1487,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • - DisplayObject + child
  • @@ -1399,11 +1513,11 @@ for this callback to be fired, The touch must have started over the displayObjec

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:291 + src/pixi/display/DisplayObjectContainer.js:274

    @@ -1415,6 +1529,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    Removes a child from the container.

    +
    @@ -1425,14 +1540,15 @@ for this callback to be fired, The touch must have started over the displayObjec
  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to remove

    +
    @@ -1448,7 +1564,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • -
    +

    setInteractive

    @@ -1468,6 +1584,8 @@ for this callback to be fired, The touch must have started over the displayObjec + deprecated + @@ -1483,16 +1601,18 @@ for this callback to be fired, The touch must have started over the displayObjec

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:193 + src/pixi/display/DisplayObject.js:247

    +

    Deprecated: Simply set the `interactive` property directly

    +
    @@ -1500,6 +1620,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default Instead of using this function you can now simply set the interactive property to true or false

    +
    @@ -1575,7 +1696,7 @@ Instead of using this function you can now simply set the interactive property t - src/pixi/text/BitmapText.js:44 + src/pixi/text/BitmapText.js:46

    @@ -1587,6 +1708,7 @@ Instead of using this function you can now simply set the interactive property t

    Set the style of the text

    +
    @@ -1605,6 +1727,7 @@ Instead of using this function you can now simply set the interactive property t

    The style parameters

    +
    @@ -1617,7 +1740,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously)

    +

    The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously)

    +
    @@ -1631,7 +1755,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    An alignment of the multiline text ("left", "center" or "right")

    +

    An alignment of the multiline text ("left", "center" or "right")

    +
    @@ -1693,7 +1818,7 @@ Instead of using this function you can now simply set the interactive property t - src/pixi/text/BitmapText.js:33 + src/pixi/text/BitmapText.js:34

    @@ -1705,6 +1830,7 @@ Instead of using this function you can now simply set the interactive property t

    Set the copy for the text object

    +
    @@ -1723,6 +1849,7 @@ Instead of using this function you can now simply set the interactive property t

    The copy that you would like the text to display

    +
    @@ -1738,7 +1865,7 @@ Instead of using this function you can now simply set the interactive property t
    -
    +

    swapChildren

    @@ -1747,13 +1874,13 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child
  • - DisplayObject2 + child2
  • @@ -1766,6 +1893,8 @@ Instead of using this function you can now simply set the interactive property t + private + @@ -1779,11 +1908,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:227 + src/pixi/display/DisplayObjectContainer.js:207

    @@ -1794,7 +1923,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    Swaps the depth of 2 displayObjects

    +

    [NYI] Swaps the depth of 2 displayObjects

    +
    @@ -1805,7 +1935,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child DisplayObject @@ -1820,7 +1950,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject2 + child2 DisplayObject @@ -1878,11 +2008,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:152 + src/pixi/display/DisplayObject.js:217

    @@ -1895,6 +2025,7 @@ Instead of using this function you can now simply set the interactive property t

    A callback that is used when the users taps on the sprite with their finger basically a touch version of click

    +
    @@ -1906,7 +2037,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -1963,11 +2094,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:165 + src/pixi/display/DisplayObject.js:230

    @@ -1979,6 +2110,7 @@ basically a touch version of click

    A callback that is used when the user releases a touch over the displayObject

    +
    @@ -1990,7 +2122,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -2047,11 +2179,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:171 + src/pixi/display/DisplayObject.js:236

    @@ -2064,6 +2196,7 @@ basically a touch version of click

    A callback that is used when the user releases the touch that was over the displayObject for this callback to be fired, The touch must have started over the sprite

    +
    @@ -2075,7 +2208,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -2132,11 +2265,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:159 + src/pixi/display/DisplayObject.js:224

    @@ -2147,7 +2280,8 @@ for this callback to be fired, The touch must have started over the sprite

  • -

    A callback that is used when the user touch's over the displayObject

    +

    A callback that is used when the user touch's over the displayObject

    +
    @@ -2159,7 +2293,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -2178,6 +2312,120 @@ for this callback to be fired, The touch must have started over the sprite

    +
  • + + +
    +

    updateText

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/text/BitmapText.js:67 + +

    + + + + + +
    + +
    +

    Renders text

    + +
    + + + + + + +
    + + +
    +

    updateTransform

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/text/BitmapText.js:142 + +

    + + + + + +
    + +
    +

    Updates the transfor of this object

    + +
    + + + + + +
    @@ -2189,6 +2437,50 @@ for this callback to be fired, The touch must have started over the sprite

    Properties

    +
    +

    _interactive

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:115 + +

    + + + + +
    + +
    +

    [read-only] Whether or not the object is interactive, do not toggle directly! use the interactive property

    + +
    + + + + + + +
    + +

    alpha

    Number @@ -2205,11 +2497,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:43 + src/pixi/display/DisplayObject.js:47

    @@ -2220,6 +2512,7 @@ for this callback to be fired, The touch must have started over the sprite

    The opacity of the object.

    +
    @@ -2246,11 +2539,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:98 + src/pixi/display/DisplayObject.js:72

    @@ -2261,6 +2554,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is used to indicate if the displayObject should display a mouse hand cursor on rollover

    +
    @@ -2273,7 +2567,7 @@ for this callback to be fired, The touch must have started over the sprite

    children

    - Array + Array @@ -2287,11 +2581,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:16 + src/pixi/display/DisplayObjectContainer.js:18

    @@ -2302,6 +2596,139 @@ for this callback to be fired, The touch must have started over the sprite

    [read-only] The of children of this container.

    + +
    + + + + + + +
    + + +
    +

    color

    + Array<> + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:145 + +

    + + + + +
    + +
    +

    [NYI] Unkown

    + +
    + + + + + + +
    + + +
    +

    dynamic

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:154 + +

    + + + + +
    + +
    +

    [NYI] Holds whether or not this object is dynamic, for rendering optimization

    + +
    + + + + + + +
    + + +
    +

    filters

    + Array An array of filters + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:318 + +

    + + + + +
    + +
    +

    Sets the filters for the displayObject. +* IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. +To remove filters simply set this property to 'null'

    +
    @@ -2314,7 +2741,7 @@ for this callback to be fired, The touch must have started over the sprite

    hitArea

    - Rectangle + Rectangle | Circle | Ellipse | Polygon @@ -2328,11 +2755,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:72 + src/pixi/display/DisplayObject.js:63

    @@ -2344,6 +2771,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is the defined area that will pick up mouse / touch events. It is null by default. Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)

    +
    @@ -2370,11 +2798,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:204 + src/pixi/display/DisplayObject.js:260

    @@ -2385,6 +2813,53 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Indicates if the sprite will have touch and mouse interactivity. It is false by default

    + +
    + + +

    Default: false

    + + + + + +
    + + +
    +

    localTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:135 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object locally

    +
    @@ -2397,7 +2872,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    mask

    - PIXI.Graphics + Graphics @@ -2411,11 +2886,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:222 + src/pixi/display/DisplayObject.js:280

    @@ -2428,6 +2903,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. To remove a mask, set this property to null.

    +
    @@ -2454,11 +2930,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:58 + src/pixi/display/DisplayObject.js:88

    @@ -2469,6 +2945,7 @@ To remove a mask, set this property to null.

    [read-only] The display object container that contains this display object.

    +
    @@ -2495,11 +2972,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:29 + src/pixi/display/DisplayObject.js:31

    @@ -2510,6 +2987,7 @@ To remove a mask, set this property to null.

    The pivot point of the displayObject that it rotates around

    +
    @@ -2536,11 +3014,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:15 + src/pixi/display/DisplayObject.js:15

    @@ -2551,6 +3029,49 @@ To remove a mask, set this property to null.

    The coordinate of the object relative to the local coordinates of the parent.

    + +
    + + + + + + +
    + + +
    +

    renderable

    + Boolean + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:80 + +

    + + + + +
    + +
    +

    Can this object be rendered

    +
    @@ -2577,11 +3098,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:36 + src/pixi/display/DisplayObject.js:39

    @@ -2592,6 +3113,7 @@ To remove a mask, set this property to null.

    The rotation of the object in radians.

    +
    @@ -2618,11 +3140,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:22 + src/pixi/display/DisplayObject.js:23

    @@ -2633,6 +3155,7 @@ To remove a mask, set this property to null.

    The scale factor of the object.

    +
    @@ -2659,11 +3182,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:65 + src/pixi/display/DisplayObject.js:97

    @@ -2674,6 +3197,7 @@ To remove a mask, set this property to null.

    [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.

    +
    @@ -2700,11 +3224,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:50 + src/pixi/display/DisplayObject.js:55

    @@ -2715,6 +3239,93 @@ To remove a mask, set this property to null.

    The visibility of the object.

    + +
    + + + + + + +
    + + +
    +

    worldAlpha

    + Number + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:106 + +

    + + + + +
    + +
    +

    [read-only] The multiplied alpha of the displayobject

    + +
    + + + + + + +
    + + +
    +

    worldTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:125 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object based on world (parent) factors

    +
    @@ -2740,13 +3351,13 @@ To remove a mask, set this property to null.

    - + - - - - - - + + + + + + diff --git a/docs/classes/BlurFilter.html b/docs/classes/BlurFilter.html new file mode 100644 index 0000000..d168b03 --- /dev/null +++ b/docs/classes/BlurFilter.html @@ -0,0 +1,426 @@ + + + + + BlurFilter - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    BlurFilter Class

    +
    + + + + + + + + + + + Module: PIXI + + + + +
    + + + +
    +

    The BlurFilter applies a Gaussian blur to an object. + The strength of the blur can be set for x- and y-axis separately (always relative to the stage).

    + +
    + + + +
    + + +
    +
    +

    Item Index

    + + + + +
    +

    Properties

    + + +
    + + + + + +
    + + + + +
    +

    Properties

    + + +
    +

    blur

    + Number the strength of the blur + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/filters/BlurFilter.js:24 + +

    + + + + +
    + +
    +

    Sets the strength of both the blurX and blurY properties simultaneously

    + +
    + + +

    Default: 2

    + + + + + +
    + + +
    +

    blurX

    + Number the strength of the blurX + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/filters/BlurFilter.js:40 + +

    + + + + +
    + +
    +

    Sets the strength of the blurX property simultaneously

    + +
    + + +

    Default: 2

    + + + + + +
    + + +
    +

    blurY

    + Number the strength of the blurY + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/filters/BlurFilter.js:56 + +

    + + + + +
    + +
    +

    Sets the strength of the blurX property simultaneously

    + +
    + + +

    Default: 2

    + + + + + +
    + + +
    + + + + + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/CanvasGraphics.html b/docs/classes/CanvasGraphics.html index 0e44412..252ac5e 100644 --- a/docs/classes/CanvasGraphics.html +++ b/docs/classes/CanvasGraphics.html @@ -3,11 +3,11 @@ CanvasGraphics - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -150,7 +174,7 @@ @@ -167,6 +191,7 @@

    A set of functions used by the webGL renderer to draw the primitive graphics data

    +
    @@ -176,6 +201,8 @@
  • Index
  • +
  • Methods
  • + @@ -186,6 +213,68 @@

    Item Index

    +
    +

    Methods

    + + +
    + @@ -195,6 +284,669 @@
    +
    +

    Methods

    + + +
    +

    buildCircle

    + + +
    + (
      + +
    • + + graphics + +
    • + +
    • + + webGLData + +
    • + +
    ) +
    + + + + + + + + private + + + + + + static + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLGraphics.js:204 + +

    + + + + + +
    + +
    +

    Builds a circle to draw

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + graphics + Graphics + + + + +
      + +
      + + +
    • + +
    • + + webGLData + Object + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    buildLine

    + + +
    + (
      + +
    • + + graphics + +
    • + +
    • + + webGLData + +
    • + +
    ) +
    + + + + + + + + private + + + + + + static + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLGraphics.js:272 + +

    + + + + + +
    + +
    +

    Builds a line to draw

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + graphics + Graphics + + + + +
      + +
      + + +
    • + +
    • + + webGLData + Object + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    buildPoly

    + + +
    + (
      + +
    • + + graphics + +
    • + +
    • + + webGLData + +
    • + +
    ) +
    + + + + + + + + private + + + + + + static + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLGraphics.js:463 + +

    + + + + + +
    + +
    +

    Builds a polygon to draw

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + graphics + Graphics + + + + +
      + +
      + + +
    • + +
    • + + webGLData + Object + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    buildRectangle

    + + +
    + (
      + +
    • + + graphics + +
    • + +
    • + + webGLData + +
    • + +
    ) +
    + + + + + + + + private + + + + + + static + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLGraphics.js:139 + +

    + + + + + +
    + +
    +

    Builds a rectangle to draw

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + graphics + Graphics + + + + +
      + +
      + + +
    • + +
    • + + webGLData + Object + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    renderGraphics

    + + +
    + (
      + +
    • + + graphics + +
    • + +
    • + + projection + +
    • + +
    ) +
    + + + + + + + + private + + + + + + static + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLGraphics.js:15 + +

    + + + + + +
    + +
    +

    Renders the graphics object

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + graphics + Graphics + + + + +
      + +
      + + +
    • + +
    • + + projection + Object + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    updateGraphics

    + + +
    + (
      + +
    • + + graphics + +
    • + +
    ) +
    + + + + + + + + private + + + + + + static + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLGraphics.js:87 + +

    + + + + + +
    + +
    +

    Updates the graphics object

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + graphics + Graphics + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    + @@ -210,13 +962,13 @@
    - + - - - - - - + + + + + + diff --git a/docs/classes/CanvasRenderer.html b/docs/classes/CanvasRenderer.html index bcc7dba..4baa9ad 100644 --- a/docs/classes/CanvasRenderer.html +++ b/docs/classes/CanvasRenderer.html @@ -3,11 +3,11 @@ CanvasRenderer - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -150,7 +174,7 @@ @@ -168,6 +192,7 @@

    the CanvasRenderer draws the stage and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. Dont forget to add the view to your DOM or you will not see anything :)

    +
    @@ -182,13 +207,13 @@ Dont forget to add the view to your DOM or you will not see anything :)

  • - width + width=0
  • - height + height=0
  • @@ -200,7 +225,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

  • - transparent + transparent=false
  • @@ -233,7 +258,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    - src/pixi/renderers/canvas/CanvasRenderer.js:6 + src/pixi/renderers/canvas/CanvasRenderer.js:6

    @@ -255,7 +280,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

  • - width + width=0 Number @@ -263,6 +288,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    the width of the canvas view

    +
    @@ -270,7 +296,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

  • - height + height=0 Number @@ -278,6 +304,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    the height of the canvas view

    +
    @@ -293,6 +320,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    the canvas to use as a view, optional

    +
    @@ -300,7 +328,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

  • - transparent + transparent=false Boolean @@ -308,6 +336,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    the transparency of the render view, default false

    +
    @@ -354,6 +383,41 @@ Dont forget to add the view to your DOM or you will not see anything :)

    +
  • + +
  • + renderDisplayObject + + + +
  • + +
  • + renderStrip + + + +
  • + +
  • + renderStripFlat + + + +
  • + +
  • + renderTilingSprite + + + +
  • + +
  • + resize + + +
  • @@ -450,7 +514,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    - src/pixi/renderers/canvas/CanvasRenderer.js:66 + src/pixi/renderers/canvas/CanvasRenderer.js:66

    @@ -462,6 +526,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    Renders the stage to its canvas view

    +
    @@ -480,6 +545,482 @@ Dont forget to add the view to your DOM or you will not see anything :)

    the Stage element to be rendered

    + +
    + + + + + +
    + + + + + +
    + + +
    +

    renderDisplayObject

    + + +
    + () +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/canvas/CanvasRenderer.js:129 + +

    + + + + + +
    + +
    +

    Renders a display object

    + +
    + + +
    +

    Parameters:

    + + +
    + + + + + +
    + + +
    +

    renderStrip

    + + +
    + () +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/canvas/CanvasRenderer.js:320 + +

    + + + + + +
    + +
    +

    Renders a strip

    + +
    + + +
    +

    Parameters:

    + + +
    + + + + + +
    + + +
    +

    renderStripFlat

    + + +
    + () +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/canvas/CanvasRenderer.js:250 + +

    + + + + + +
    + +
    +

    Renders a flat strip

    + +
    + + +
    +

    Parameters:

    + + +
    + + + + + +
    + + +
    +

    renderTilingSprite

    + + +
    + () +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/canvas/CanvasRenderer.js:287 + +

    + + + + + +
    + +
    +

    Renders a tiling sprite

    + +
    + + +
    +

    Parameters:

    + + +
    + + + + + +
    + + +
    +

    resize

    + + +
    + () +
    + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/canvas/CanvasRenderer.js:113 + +

    + + + + + +
    + +
    +

    resizes the canvas view to the specified width and height

    + +
    + + +
    +

    Parameters:

    + +
    - + - - - - - - + + + + + + diff --git a/docs/classes/Circle.html b/docs/classes/Circle.html index e67296d..5558388 100644 --- a/docs/classes/Circle.html +++ b/docs/classes/Circle.html @@ -3,11 +3,11 @@ Circle - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -150,7 +174,7 @@ @@ -166,7 +190,8 @@
    - +

    The Circle object can be used to specify a hit area for displayobjects

    +
    @@ -226,7 +251,7 @@ - src/pixi/core/Circle.js:5 + src/pixi/core/Circle.js:5

    @@ -256,6 +281,7 @@

    The X coord of the upper-left corner of the framing rectangle of this circle

    +
    @@ -271,6 +297,7 @@

    The Y coord of the upper-left corner of the framing rectangle of this circle

    +
    @@ -286,6 +313,7 @@

    The radius of the circle

    +
    @@ -395,7 +423,7 @@ - + Circle @@ -422,7 +450,7 @@ - src/pixi/core/Circle.js:36 + src/pixi/core/Circle.js:38

    @@ -433,7 +461,8 @@
    - +

    Creates a clone of this Circle instance

    +
    @@ -445,7 +474,10 @@
    - a copy of the polygon + Circle: + +

    a copy of the polygon

    +
    @@ -480,7 +512,7 @@ - + Boolean @@ -507,7 +539,7 @@ - src/pixi/core/Circle.js:45 + src/pixi/core/Circle.js:49

    @@ -518,7 +550,8 @@
    - +

    Checks if the x, and y coords passed to this function are contained within this circle

    +
    @@ -537,6 +570,7 @@

    The X coord of the point to test

    +
    @@ -552,6 +586,7 @@

    The Y coord of the point to test

    +
    @@ -568,7 +603,10 @@
    - if the x/y coords are within this polygon + Boolean: + +

    if the x/y coords are within this polygon

    +
    @@ -609,7 +647,7 @@ - src/pixi/core/Circle.js:28 + src/pixi/core/Circle.js:30

    @@ -655,7 +693,7 @@ - src/pixi/core/Circle.js:14 + src/pixi/core/Circle.js:16

    @@ -701,7 +739,7 @@ - src/pixi/core/Circle.js:21 + src/pixi/core/Circle.js:23

    @@ -739,13 +777,13 @@ - + - - - - - - + + + + + + diff --git a/docs/classes/ColorMatrixFilter.html b/docs/classes/ColorMatrixFilter.html new file mode 100644 index 0000000..babe305 --- /dev/null +++ b/docs/classes/ColorMatrixFilter.html @@ -0,0 +1,319 @@ + + + + + ColorMatrixFilter - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    ColorMatrixFilter Class

    +
    + + + + + + + + + + + Module: PIXI + + + + +
    + + + +
    +

    The ColorMatrixFilter class lets you apply a 4x4 matrix transformation on the RGBA + color and alpha values of every pixel on your displayObject to produce a result + with a new set of RGBA color and alpha values. Its pretty powerful!

    + +
    + + + +
    + + +
    +
    +

    Item Index

    + + + + +
    +

    Properties

    + + +
    + + + + + +
    + + + + +
    +

    Properties

    + + +
    +

    matrix

    + Array and array of 26 numbers + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/filters/ColorMatrixFilter.js:45 + +

    + + + + +
    + +
    +

    Sets the matrix of the color matrix filter

    + +
    + + +

    Default: [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]

    + + + + + +
    + + +
    + + + + + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/CustomRenderable.html b/docs/classes/CustomRenderable.html index 4866fb0..5b50c47 100644 --- a/docs/classes/CustomRenderable.html +++ b/docs/classes/CustomRenderable.html @@ -3,11 +3,11 @@ CustomRenderable - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -154,7 +178,7 @@ @@ -170,7 +194,8 @@
    -

    Need to finalize this a bit more but works! Its in but will be working on this feature properly next..:)

    +

    This object is one that will allow you to specify custom rendering functions based on render type

    +
    @@ -208,7 +233,7 @@ - src/pixi/extras/CustomRenderable.js:6 + src/pixi/extras/CustomRenderable.js:6

    @@ -261,6 +286,13 @@ + + +
  • + initWebGL + + +
  • @@ -298,11 +330,27 @@
  • -
  • +
  • + renderCanvas + + + +
  • + +
  • + renderWebGL + + + +
  • + +
  • setInteractive + deprecated +
  • @@ -343,6 +391,13 @@ @@ -476,11 +580,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:109 + src/pixi/display/DisplayObject.js:174

    @@ -492,6 +596,7 @@

    A callback that is used when the users clicks on the displayObject with their mouse

    +
    @@ -503,7 +608,7 @@
  • interactionData - InteractionData + InteractionData @@ -522,6 +627,95 @@ +
  • + + +
    +

    initWebGL

    + + +
    + (
      + +
    • + + renderer + +
    • + +
    ) +
    + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/extras/CustomRenderable.js:35 + +

    + + + + + +
    + +
    +

    If this object is being rendered by a WebGLRenderer it will call this callback to initialize

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + renderer + WebGLRenderer + + + + +
      +

      The renderer instance

      + +
      + + +
    • + +
    +
    + + + + +
    @@ -560,11 +754,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:115 + src/pixi/display/DisplayObject.js:180

    @@ -576,6 +770,7 @@

    A callback that is used when the user clicks the mouse down over the sprite

    +
    @@ -587,7 +782,7 @@
  • interactionData - InteractionData + InteractionData @@ -644,11 +839,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:141 + src/pixi/display/DisplayObject.js:206

    @@ -660,6 +855,7 @@

    A callback that is used when the users mouse leaves the displayObject

    +
    @@ -671,7 +867,7 @@
  • interactionData - InteractionData + InteractionData @@ -728,11 +924,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:135 + src/pixi/display/DisplayObject.js:200

    @@ -744,6 +940,7 @@

    A callback that is used when the users mouse rolls over the displayObject

    +
    @@ -755,7 +952,7 @@
  • interactionData - InteractionData + InteractionData @@ -812,11 +1009,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:121 + src/pixi/display/DisplayObject.js:186

    @@ -829,6 +1026,7 @@

    A callback that is used when the user releases the mouse that was over the displayObject for this callback to be fired the mouse must have been pressed down over the displayObject

    +
    @@ -840,7 +1038,7 @@ for this callback to be fired the mouse must have been pressed down over the dis
  • interactionData - InteractionData + InteractionData @@ -897,11 +1095,11 @@ for this callback to be fired the mouse must have been pressed down over the dis

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:128 + src/pixi/display/DisplayObject.js:193

    @@ -914,6 +1112,7 @@ for this callback to be fired the mouse must have been pressed down over the dis

    A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject for this callback to be fired, The touch must have started over the displayObject

    +
    @@ -925,7 +1124,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • interactionData - InteractionData + InteractionData @@ -947,8 +1146,8 @@ for this callback to be fired, The touch must have started over the displayObjec
  • -
    -

    setInteractive

    +
    +

    renderCanvas

    @@ -956,7 +1155,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • - interactive + renderer
  • @@ -981,12 +1180,15 @@ for this callback to be fired, The touch must have started over the displayObjec
    -

    Inherited from - DisplayObject: + +

    + + Defined in + - src/pixi/display/DisplayObject.js:193 + src/pixi/extras/CustomRenderable.js:24

    @@ -994,11 +1196,191 @@ for this callback to be fired, The touch must have started over the displayObjec +
    + +
    +

    If this object is being rendered by a CanvasRenderer it will call this callback

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + renderer + CanvasRenderer + + + + +
      +

      The renderer instance

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    renderWebGL

    + + +
    + (
      + +
    • + + renderer + +
    • + +
    ) +
    + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/extras/CustomRenderable.js:46 + +

    + + + + + +
    + +
    +

    If this object is being rendered by a WebGLRenderer it will call this callback

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + renderer + WebGLRenderer + + + + +
      +

      The renderer instance

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    setInteractive

    + + +
    + (
      + +
    • + + interactive + +
    • + +
    ) +
    + + + + + + deprecated + + + + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:247 + +

    + + + +

    Deprecated: Simply set the `interactive` property directly

    + + +

    [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default Instead of using this function you can now simply set the interactive property to true or false

    +
    @@ -1067,11 +1449,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:152 + src/pixi/display/DisplayObject.js:217

    @@ -1084,6 +1466,7 @@ Instead of using this function you can now simply set the interactive property t

    A callback that is used when the users taps on the sprite with their finger basically a touch version of click

    +
    @@ -1095,7 +1478,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -1152,11 +1535,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:165 + src/pixi/display/DisplayObject.js:230

    @@ -1168,6 +1551,7 @@ basically a touch version of click

    A callback that is used when the user releases a touch over the displayObject

    +
    @@ -1179,7 +1563,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -1236,11 +1620,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:171 + src/pixi/display/DisplayObject.js:236

    @@ -1253,6 +1637,7 @@ basically a touch version of click

    A callback that is used when the user releases the touch that was over the displayObject for this callback to be fired, The touch must have started over the sprite

    +
    @@ -1264,7 +1649,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -1321,11 +1706,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:159 + src/pixi/display/DisplayObject.js:224

    @@ -1336,7 +1721,8 @@ for this callback to be fired, The touch must have started over the sprite

  • -

    A callback that is used when the user touch's over the displayObject

    +

    A callback that is used when the user touch's over the displayObject

    +
    @@ -1348,7 +1734,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -1378,6 +1764,50 @@ for this callback to be fired, The touch must have started over the sprite

    Properties

    +
    +

    _interactive

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:115 + +

    + + + + +
    + +
    +

    [read-only] Whether or not the object is interactive, do not toggle directly! use the interactive property

    + +
    + + + + + + +
    + +

    alpha

    Number @@ -1394,11 +1824,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:43 + src/pixi/display/DisplayObject.js:47

    @@ -1409,6 +1839,7 @@ for this callback to be fired, The touch must have started over the sprite

    The opacity of the object.

    +
    @@ -1435,11 +1866,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:98 + src/pixi/display/DisplayObject.js:72

    @@ -1450,6 +1881,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is used to indicate if the displayObject should display a mouse hand cursor on rollover

    +
    @@ -1460,9 +1892,97 @@ for this callback to be fired, The touch must have started over the sprite

    -
    -

    hitArea

    - Rectangle +
    +

    color

    + Array<> + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:145 + +

    + + + + +
    + +
    +

    [NYI] Unkown

    + +
    + + + + + + +
    + + +
    +

    dynamic

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:154 + +

    + + + + +
    + +
    +

    [NYI] Holds whether or not this object is dynamic, for rendering optimization

    + +
    + + + + + + +
    + + +
    +

    filters

    + Array An array of filters @@ -1476,11 +1996,55 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:72 + src/pixi/display/DisplayObject.js:318 + +

    + + + + +
    + +
    +

    Sets the filters for the displayObject. +* IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. +To remove filters simply set this property to 'null'

    + +
    + + + + + + +
    + + +
    +

    hitArea

    + Rectangle | Circle | Ellipse | Polygon + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:63

    @@ -1492,6 +2056,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is the defined area that will pick up mouse / touch events. It is null by default. Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)

    +
    @@ -1518,11 +2083,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:204 + src/pixi/display/DisplayObject.js:260

    @@ -1533,6 +2098,53 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Indicates if the sprite will have touch and mouse interactivity. It is false by default

    + +
    + + +

    Default: false

    + + + + + +
    + + +
    +

    localTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:135 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object locally

    +
    @@ -1545,7 +2157,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    mask

    - PIXI.Graphics + Graphics @@ -1559,11 +2171,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:222 + src/pixi/display/DisplayObject.js:280

    @@ -1576,6 +2188,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. To remove a mask, set this property to null.

    +
    @@ -1602,11 +2215,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:58 + src/pixi/display/DisplayObject.js:88

    @@ -1617,6 +2230,7 @@ To remove a mask, set this property to null.

    [read-only] The display object container that contains this display object.

    +
    @@ -1643,11 +2257,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:29 + src/pixi/display/DisplayObject.js:31

    @@ -1658,6 +2272,7 @@ To remove a mask, set this property to null.

    The pivot point of the displayObject that it rotates around

    +
    @@ -1684,11 +2299,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:15 + src/pixi/display/DisplayObject.js:15

    @@ -1699,6 +2314,49 @@ To remove a mask, set this property to null.

    The coordinate of the object relative to the local coordinates of the parent.

    + +
    + + + + + + +
    + + +
    +

    renderable

    + Boolean + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:80 + +

    + + + + +
    + +
    +

    Can this object be rendered

    +
    @@ -1725,11 +2383,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:36 + src/pixi/display/DisplayObject.js:39

    @@ -1740,6 +2398,7 @@ To remove a mask, set this property to null.

    The rotation of the object in radians.

    +
    @@ -1766,11 +2425,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:22 + src/pixi/display/DisplayObject.js:23

    @@ -1781,6 +2440,7 @@ To remove a mask, set this property to null.

    The scale factor of the object.

    +
    @@ -1807,11 +2467,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:65 + src/pixi/display/DisplayObject.js:97

    @@ -1822,6 +2482,7 @@ To remove a mask, set this property to null.

    [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.

    +
    @@ -1848,11 +2509,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:50 + src/pixi/display/DisplayObject.js:55

    @@ -1863,6 +2524,93 @@ To remove a mask, set this property to null.

    The visibility of the object.

    + +
    + + + + + + +
    + + +
    +

    worldAlpha

    + Number + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:106 + +

    + + + + +
    + +
    +

    [read-only] The multiplied alpha of the displayobject

    + +
    + + + + + + +
    + + +
    +

    worldTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:125 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object based on world (parent) factors

    +
    @@ -1888,13 +2636,13 @@ To remove a mask, set this property to null.

  • - + - - - - - - + + + + + + diff --git a/docs/classes/DisplacementFilter.html b/docs/classes/DisplacementFilter.html new file mode 100644 index 0000000..753b93b --- /dev/null +++ b/docs/classes/DisplacementFilter.html @@ -0,0 +1,421 @@ + + + + + DisplacementFilter - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    DisplacementFilter Class

    +
    + + + + + + + + + + + Module: PIXI + + + + +
    + + + +
    +

    The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. + You can use this filter to apply all manor of crazy warping effects + Currently the r property of the texture is used offset the x and the g propery of the texture is used to offset the y.

    + +
    + + + +
    + + +
    +
    +

    Item Index

    + + + + +
    +

    Properties

    + + +
    + + + + + +
    + + + + +
    +

    Properties

    + + +
    +

    map

    + Texture + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/filters/DisplacementFilter.js:92 + +

    + + + + +
    + +
    +

    The texture used for the displacemtent map * must be power of 2 texture at the moment

    + +
    + + + + + + +
    + + +
    +

    offset

    + Point + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/filters/DisplacementFilter.js:122 + +

    + + + + +
    + +
    +

    The offset used to move the displacement map.

    + +
    + + + + + + +
    + + +
    +

    scale

    + Point + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/filters/DisplacementFilter.js:107 + +

    + + + + +
    + +
    +

    The multiplier used to scale the displacement result from the map calculation.

    + +
    + + + + + + +
    + + +
    + + + + + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/DisplayObject.html b/docs/classes/DisplayObject.html index 12cec79..adecad4 100644 --- a/docs/classes/DisplayObject.html +++ b/docs/classes/DisplayObject.html @@ -3,11 +3,11 @@ DisplayObject - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -150,7 +174,7 @@ @@ -166,7 +190,8 @@
    -

    this is the base class for all objects that are rendered on the screen.

    +

    The base class for all objects that are rendered on the screen.

    +
    @@ -204,7 +229,7 @@ - src/pixi/display/DisplayObject.js:5 + src/pixi/display/DisplayObject.js:5

    @@ -294,11 +319,13 @@ -
  • +
  • setInteractive + deprecated +
  • @@ -339,6 +366,13 @@ @@ -479,7 +562,7 @@ - src/pixi/display/DisplayObject.js:109 + src/pixi/display/DisplayObject.js:174

    @@ -491,6 +574,7 @@

    A callback that is used when the users clicks on the displayObject with their mouse

    +
    @@ -502,7 +586,7 @@
  • interactionData - InteractionData + InteractionData @@ -566,7 +650,7 @@ - src/pixi/display/DisplayObject.js:115 + src/pixi/display/DisplayObject.js:180

    @@ -578,6 +662,7 @@

    A callback that is used when the user clicks the mouse down over the sprite

    +
    @@ -589,7 +674,7 @@
  • interactionData - InteractionData + InteractionData @@ -653,7 +738,7 @@ - src/pixi/display/DisplayObject.js:141 + src/pixi/display/DisplayObject.js:206

    @@ -665,6 +750,7 @@

    A callback that is used when the users mouse leaves the displayObject

    +
    @@ -676,7 +762,7 @@
  • interactionData - InteractionData + InteractionData @@ -740,7 +826,7 @@ - src/pixi/display/DisplayObject.js:135 + src/pixi/display/DisplayObject.js:200

    @@ -752,6 +838,7 @@

    A callback that is used when the users mouse rolls over the displayObject

    +
    @@ -763,7 +850,7 @@
  • interactionData - InteractionData + InteractionData @@ -827,7 +914,7 @@ - src/pixi/display/DisplayObject.js:121 + src/pixi/display/DisplayObject.js:186

    @@ -840,6 +927,7 @@

    A callback that is used when the user releases the mouse that was over the displayObject for this callback to be fired the mouse must have been pressed down over the displayObject

    +
    @@ -851,7 +939,7 @@ for this callback to be fired the mouse must have been pressed down over the dis
  • interactionData - InteractionData + InteractionData @@ -915,7 +1003,7 @@ for this callback to be fired the mouse must have been pressed down over the dis - src/pixi/display/DisplayObject.js:128 + src/pixi/display/DisplayObject.js:193

    @@ -928,6 +1016,7 @@ for this callback to be fired the mouse must have been pressed down over the dis

    A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject for this callback to be fired, The touch must have started over the displayObject

    +
    @@ -939,7 +1028,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • interactionData - InteractionData + InteractionData @@ -961,7 +1050,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • -
    +

    setInteractive

    @@ -981,6 +1070,8 @@ for this callback to be fired, The touch must have started over the displayObjec + deprecated + @@ -1003,12 +1094,14 @@ for this callback to be fired, The touch must have started over the displayObjec - src/pixi/display/DisplayObject.js:193 + src/pixi/display/DisplayObject.js:247

    +

    Deprecated: Simply set the `interactive` property directly

    +
    @@ -1016,6 +1109,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default Instead of using this function you can now simply set the interactive property to true or false

    +
    @@ -1091,7 +1185,7 @@ Instead of using this function you can now simply set the interactive property t - src/pixi/display/DisplayObject.js:152 + src/pixi/display/DisplayObject.js:217

    @@ -1104,6 +1198,7 @@ Instead of using this function you can now simply set the interactive property t

    A callback that is used when the users taps on the sprite with their finger basically a touch version of click

    +
    @@ -1115,7 +1210,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -1179,7 +1274,7 @@ basically a touch version of click

    - src/pixi/display/DisplayObject.js:165 + src/pixi/display/DisplayObject.js:230

    @@ -1191,6 +1286,7 @@ basically a touch version of click

    A callback that is used when the user releases a touch over the displayObject

    +
    @@ -1202,7 +1298,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -1266,7 +1362,7 @@ basically a touch version of click

    - src/pixi/display/DisplayObject.js:171 + src/pixi/display/DisplayObject.js:236

    @@ -1279,6 +1375,7 @@ basically a touch version of click

    A callback that is used when the user releases the touch that was over the displayObject for this callback to be fired, The touch must have started over the sprite

    +
    @@ -1290,7 +1387,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -1354,7 +1451,7 @@ for this callback to be fired, The touch must have started over the sprite

    - src/pixi/display/DisplayObject.js:159 + src/pixi/display/DisplayObject.js:224

    @@ -1365,7 +1462,8 @@ for this callback to be fired, The touch must have started over the sprite

  • -

    A callback that is used when the user touch's over the displayObject

    +

    A callback that is used when the user touch's over the displayObject

    +
    @@ -1377,7 +1475,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -1407,6 +1505,53 @@ for this callback to be fired, The touch must have started over the sprite

    Properties

    +
    +

    _interactive

    + Boolean + + + + + private + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/display/DisplayObject.js:115 + +

    + + + + +
    + +
    +

    [read-only] Whether or not the object is interactive, do not toggle directly! use the interactive property

    + +
    + + + + + + +
    + +

    alpha

    Number @@ -1430,7 +1575,7 @@ for this callback to be fired, The touch must have started over the sprite

    - src/pixi/display/DisplayObject.js:43 + src/pixi/display/DisplayObject.js:47

    @@ -1441,6 +1586,7 @@ for this callback to be fired, The touch must have started over the sprite

    The opacity of the object.

    +
    @@ -1474,7 +1620,7 @@ for this callback to be fired, The touch must have started over the sprite

    - src/pixi/display/DisplayObject.js:98 + src/pixi/display/DisplayObject.js:72

    @@ -1485,6 +1631,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is used to indicate if the displayObject should display a mouse hand cursor on rollover

    +
    @@ -1495,9 +1642,103 @@ for this callback to be fired, The touch must have started over the sprite

    -
    -

    hitArea

    - Rectangle +
    +

    color

    + Array<> + + + + + private + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/display/DisplayObject.js:145 + +

    + + + + +
    + +
    +

    [NYI] Unkown

    + +
    + + + + + + +
    + + +
    +

    dynamic

    + Boolean + + + + + private + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/display/DisplayObject.js:154 + +

    + + + + +
    + +
    +

    [NYI] Holds whether or not this object is dynamic, for rendering optimization

    + +
    + + + + + + +
    + + +
    +

    filters

    + Array An array of filters @@ -1518,7 +1759,54 @@ for this callback to be fired, The touch must have started over the sprite

    - src/pixi/display/DisplayObject.js:72 + src/pixi/display/DisplayObject.js:318 + +

    + + + + +
    + +
    +

    Sets the filters for the displayObject. +* IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. +To remove filters simply set this property to 'null'

    + +
    + + + + + + +
    + + +
    +

    hitArea

    + Rectangle | Circle | Ellipse | Polygon + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/display/DisplayObject.js:63

    @@ -1530,6 +1818,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is the defined area that will pick up mouse / touch events. It is null by default. Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)

    +
    @@ -1563,7 +1852,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction - src/pixi/display/DisplayObject.js:204 + src/pixi/display/DisplayObject.js:260

    @@ -1574,6 +1863,56 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Indicates if the sprite will have touch and mouse interactivity. It is false by default

    + +
    + + +

    Default: false

    + + + + + +
    + + +
    +

    localTransform

    + Mat3 + + + + + private + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/display/DisplayObject.js:135 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object locally

    +
    @@ -1586,7 +1925,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    mask

    - PIXI.Graphics + Graphics @@ -1607,7 +1946,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction - src/pixi/display/DisplayObject.js:222 + src/pixi/display/DisplayObject.js:280

    @@ -1620,6 +1959,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. To remove a mask, set this property to null.

    +
    @@ -1653,7 +1993,7 @@ To remove a mask, set this property to null.

    - src/pixi/display/DisplayObject.js:58 + src/pixi/display/DisplayObject.js:88

    @@ -1664,6 +2004,7 @@ To remove a mask, set this property to null.

    [read-only] The display object container that contains this display object.

    +
    @@ -1697,7 +2038,7 @@ To remove a mask, set this property to null.

    - src/pixi/display/DisplayObject.js:29 + src/pixi/display/DisplayObject.js:31

    @@ -1708,6 +2049,7 @@ To remove a mask, set this property to null.

    The pivot point of the displayObject that it rotates around

    +
    @@ -1741,7 +2083,7 @@ To remove a mask, set this property to null.

    - src/pixi/display/DisplayObject.js:15 + src/pixi/display/DisplayObject.js:15

    @@ -1752,6 +2094,52 @@ To remove a mask, set this property to null.

    The coordinate of the object relative to the local coordinates of the parent.

    + +
    + + + + + + +
    + + +
    +

    renderable

    + Boolean + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/display/DisplayObject.js:80 + +

    + + + + +
    + +
    +

    Can this object be rendered

    +
    @@ -1785,7 +2173,7 @@ To remove a mask, set this property to null.

    - src/pixi/display/DisplayObject.js:36 + src/pixi/display/DisplayObject.js:39

    @@ -1796,6 +2184,7 @@ To remove a mask, set this property to null.

    The rotation of the object in radians.

    +
    @@ -1829,7 +2218,7 @@ To remove a mask, set this property to null.

    - src/pixi/display/DisplayObject.js:22 + src/pixi/display/DisplayObject.js:23

    @@ -1840,6 +2229,7 @@ To remove a mask, set this property to null.

    The scale factor of the object.

    +
    @@ -1873,7 +2263,7 @@ To remove a mask, set this property to null.

    - src/pixi/display/DisplayObject.js:65 + src/pixi/display/DisplayObject.js:97

    @@ -1884,6 +2274,7 @@ To remove a mask, set this property to null.

    [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.

    +
    @@ -1917,7 +2308,7 @@ To remove a mask, set this property to null.

    - src/pixi/display/DisplayObject.js:50 + src/pixi/display/DisplayObject.js:55

    @@ -1928,6 +2319,99 @@ To remove a mask, set this property to null.

    The visibility of the object.

    + +
    + + + + + + +
    + + +
    +

    worldAlpha

    + Number + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/display/DisplayObject.js:106 + +

    + + + + +
    + +
    +

    [read-only] The multiplied alpha of the displayobject

    + +
    + + + + + + +
    + + +
    +

    worldTransform

    + Mat3 + + + + + private + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/display/DisplayObject.js:125 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object based on world (parent) factors

    +
    @@ -1953,13 +2437,13 @@ To remove a mask, set this property to null.

  • - + - - - - - - + + + + + + diff --git a/docs/classes/DisplayObjectContainer.html b/docs/classes/DisplayObjectContainer.html index aff6af1..10e4c76 100644 --- a/docs/classes/DisplayObjectContainer.html +++ b/docs/classes/DisplayObjectContainer.html @@ -3,11 +3,11 @@ DisplayObjectContainer - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -154,7 +178,7 @@ @@ -170,7 +194,9 @@
    -

    A DisplayObjectContainer represents a collection of display objects. It is the base class of all display objects that act as a container for other objects.

    +

    A DisplayObjectContainer represents a collection of display objects. +It is the base class of all display objects that act as a container for other objects.

    +
    @@ -208,7 +234,7 @@ - src/pixi/display/DisplayObjectContainer.js:6 + src/pixi/display/DisplayObjectContainer.js:6

    @@ -326,14 +352,16 @@ -
  • +
  • setInteractive + deprecated +
  • -
  • +
  • swapChildren @@ -378,6 +406,13 @@ @@ -492,7 +576,7 @@
  • - DisplayObject + child
  • @@ -525,7 +609,7 @@ - src/pixi/display/DisplayObjectContainer.js:42 + src/pixi/display/DisplayObjectContainer.js:32

    @@ -537,6 +621,7 @@

    Adds a child to the container.

    +
    @@ -547,14 +632,15 @@
  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to add to the container

    +
    @@ -579,7 +665,7 @@
  • - DisplayObject + child
  • @@ -618,7 +704,7 @@ - src/pixi/display/DisplayObjectContainer.js:139 + src/pixi/display/DisplayObjectContainer.js:120

    @@ -630,6 +716,7 @@

    Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown

    +
    @@ -640,14 +727,15 @@
  • - DisplayObject + child DisplayObject
    - +

    The child to add

    +
    @@ -662,7 +750,8 @@
    - +

    The index to place the child in

    +
    @@ -713,11 +802,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:109 + src/pixi/display/DisplayObject.js:174

    @@ -729,6 +818,7 @@

    A callback that is used when the users clicks on the displayObject with their mouse

    +
    @@ -740,7 +830,7 @@
  • interactionData - InteractionData + InteractionData @@ -804,7 +894,7 @@ - src/pixi/display/DisplayObjectContainer.js:274 + src/pixi/display/DisplayObjectContainer.js:256

    @@ -816,6 +906,7 @@

    Returns the Child at the specified index

    +
    @@ -833,7 +924,8 @@
    - +

    The index to get the child from

    +
    @@ -884,11 +976,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:115 + src/pixi/display/DisplayObject.js:180

    @@ -900,6 +992,7 @@

    A callback that is used when the user clicks the mouse down over the sprite

    +
    @@ -911,7 +1004,7 @@
  • interactionData - InteractionData + InteractionData @@ -968,11 +1061,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:141 + src/pixi/display/DisplayObject.js:206

    @@ -984,6 +1077,7 @@

    A callback that is used when the users mouse leaves the displayObject

    +
    @@ -995,7 +1089,7 @@
  • interactionData - InteractionData + InteractionData @@ -1052,11 +1146,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:135 + src/pixi/display/DisplayObject.js:200

    @@ -1068,6 +1162,7 @@

    A callback that is used when the users mouse rolls over the displayObject

    +
    @@ -1079,7 +1174,7 @@
  • interactionData - InteractionData + InteractionData @@ -1136,11 +1231,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:121 + src/pixi/display/DisplayObject.js:186

    @@ -1153,6 +1248,7 @@

    A callback that is used when the user releases the mouse that was over the displayObject for this callback to be fired the mouse must have been pressed down over the displayObject

    +
    @@ -1164,7 +1260,7 @@ for this callback to be fired the mouse must have been pressed down over the dis
  • interactionData - InteractionData + InteractionData @@ -1221,11 +1317,11 @@ for this callback to be fired the mouse must have been pressed down over the dis

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:128 + src/pixi/display/DisplayObject.js:193

    @@ -1238,6 +1334,7 @@ for this callback to be fired the mouse must have been pressed down over the dis

    A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject for this callback to be fired, The touch must have started over the displayObject

    +
    @@ -1249,7 +1346,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • interactionData - InteractionData + InteractionData @@ -1280,7 +1377,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • - DisplayObject + child
  • @@ -1313,7 +1410,7 @@ for this callback to be fired, The touch must have started over the displayObjec - src/pixi/display/DisplayObjectContainer.js:291 + src/pixi/display/DisplayObjectContainer.js:274

    @@ -1325,6 +1422,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    Removes a child from the container.

    +
    @@ -1335,14 +1433,15 @@ for this callback to be fired, The touch must have started over the displayObjec
  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to remove

    +
    @@ -1358,7 +1457,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • -
    +

    setInteractive

    @@ -1378,6 +1477,8 @@ for this callback to be fired, The touch must have started over the displayObjec + deprecated + @@ -1393,16 +1494,18 @@ for this callback to be fired, The touch must have started over the displayObjec

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:193 + src/pixi/display/DisplayObject.js:247

    +

    Deprecated: Simply set the `interactive` property directly

    +
    @@ -1410,6 +1513,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default Instead of using this function you can now simply set the interactive property to true or false

    +
    @@ -1443,7 +1547,7 @@ Instead of using this function you can now simply set the interactive property t
    -
    +

    swapChildren

    @@ -1452,13 +1556,13 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child
  • - DisplayObject2 + child2
  • @@ -1471,6 +1575,8 @@ Instead of using this function you can now simply set the interactive property t + private + @@ -1491,7 +1597,7 @@ Instead of using this function you can now simply set the interactive property t - src/pixi/display/DisplayObjectContainer.js:227 + src/pixi/display/DisplayObjectContainer.js:207

    @@ -1502,7 +1608,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    Swaps the depth of 2 displayObjects

    +

    [NYI] Swaps the depth of 2 displayObjects

    +
    @@ -1513,7 +1620,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child DisplayObject @@ -1528,7 +1635,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject2 + child2 DisplayObject @@ -1586,11 +1693,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:152 + src/pixi/display/DisplayObject.js:217

    @@ -1603,6 +1710,7 @@ Instead of using this function you can now simply set the interactive property t

    A callback that is used when the users taps on the sprite with their finger basically a touch version of click

    +
    @@ -1614,7 +1722,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -1671,11 +1779,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:165 + src/pixi/display/DisplayObject.js:230

    @@ -1687,6 +1795,7 @@ basically a touch version of click

    A callback that is used when the user releases a touch over the displayObject

    +
    @@ -1698,7 +1807,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -1755,11 +1864,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:171 + src/pixi/display/DisplayObject.js:236

    @@ -1772,6 +1881,7 @@ basically a touch version of click

    A callback that is used when the user releases the touch that was over the displayObject for this callback to be fired, The touch must have started over the sprite

    +
    @@ -1783,7 +1893,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -1840,11 +1950,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:159 + src/pixi/display/DisplayObject.js:224

    @@ -1855,7 +1965,8 @@ for this callback to be fired, The touch must have started over the sprite

  • -

    A callback that is used when the user touch's over the displayObject

    +

    A callback that is used when the user touch's over the displayObject

    +
    @@ -1867,7 +1978,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -1897,6 +2008,50 @@ for this callback to be fired, The touch must have started over the sprite

    Properties

    +
    +

    _interactive

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:115 + +

    + + + + +
    + +
    +

    [read-only] Whether or not the object is interactive, do not toggle directly! use the interactive property

    + +
    + + + + + + +
    + +

    alpha

    Number @@ -1913,11 +2068,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:43 + src/pixi/display/DisplayObject.js:47

    @@ -1928,6 +2083,7 @@ for this callback to be fired, The touch must have started over the sprite

    The opacity of the object.

    +
    @@ -1954,11 +2110,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:98 + src/pixi/display/DisplayObject.js:72

    @@ -1969,6 +2125,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is used to indicate if the displayObject should display a mouse hand cursor on rollover

    +
    @@ -1981,7 +2138,7 @@ for this callback to be fired, The touch must have started over the sprite

    children

    - Array + Array @@ -2002,7 +2159,7 @@ for this callback to be fired, The touch must have started over the sprite

    - src/pixi/display/DisplayObjectContainer.js:16 + src/pixi/display/DisplayObjectContainer.js:18

    @@ -2013,6 +2170,7 @@ for this callback to be fired, The touch must have started over the sprite

    [read-only] The of children of this container.

    +
    @@ -2023,9 +2181,97 @@ for this callback to be fired, The touch must have started over the sprite

    -
    -

    hitArea

    - Rectangle +
    +

    color

    + Array<> + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:145 + +

    + + + + +
    + +
    +

    [NYI] Unkown

    + +
    + + + + + + +
    + + +
    +

    dynamic

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:154 + +

    + + + + +
    + +
    +

    [NYI] Holds whether or not this object is dynamic, for rendering optimization

    + +
    + + + + + + +
    + + +
    +

    filters

    + Array An array of filters @@ -2039,11 +2285,55 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:72 + src/pixi/display/DisplayObject.js:318 + +

    + + + + +
    + +
    +

    Sets the filters for the displayObject. +* IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. +To remove filters simply set this property to 'null'

    + +
    + + + + + + +
    + + +
    +

    hitArea

    + Rectangle | Circle | Ellipse | Polygon + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:63

    @@ -2055,6 +2345,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is the defined area that will pick up mouse / touch events. It is null by default. Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)

    +
    @@ -2081,11 +2372,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:204 + src/pixi/display/DisplayObject.js:260

    @@ -2096,6 +2387,53 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Indicates if the sprite will have touch and mouse interactivity. It is false by default

    + +
    + + +

    Default: false

    + + + + + +
    + + +
    +

    localTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:135 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object locally

    +
    @@ -2108,7 +2446,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    mask

    - PIXI.Graphics + Graphics @@ -2122,11 +2460,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:222 + src/pixi/display/DisplayObject.js:280

    @@ -2139,6 +2477,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. To remove a mask, set this property to null.

    +
    @@ -2165,11 +2504,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:58 + src/pixi/display/DisplayObject.js:88

    @@ -2180,6 +2519,7 @@ To remove a mask, set this property to null.

    [read-only] The display object container that contains this display object.

    +
    @@ -2206,11 +2546,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:29 + src/pixi/display/DisplayObject.js:31

    @@ -2221,6 +2561,7 @@ To remove a mask, set this property to null.

    The pivot point of the displayObject that it rotates around

    +
    @@ -2247,11 +2588,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:15 + src/pixi/display/DisplayObject.js:15

    @@ -2262,6 +2603,49 @@ To remove a mask, set this property to null.

    The coordinate of the object relative to the local coordinates of the parent.

    + +
    + + + + + + +
    + + +
    +

    renderable

    + Boolean + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:80 + +

    + + + + +
    + +
    +

    Can this object be rendered

    +
    @@ -2288,11 +2672,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:36 + src/pixi/display/DisplayObject.js:39

    @@ -2303,6 +2687,7 @@ To remove a mask, set this property to null.

    The rotation of the object in radians.

    +
    @@ -2329,11 +2714,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:22 + src/pixi/display/DisplayObject.js:23

    @@ -2344,6 +2729,7 @@ To remove a mask, set this property to null.

    The scale factor of the object.

    +
    @@ -2370,11 +2756,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:65 + src/pixi/display/DisplayObject.js:97

    @@ -2385,6 +2771,7 @@ To remove a mask, set this property to null.

    [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.

    +
    @@ -2411,11 +2798,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:50 + src/pixi/display/DisplayObject.js:55

    @@ -2426,6 +2813,93 @@ To remove a mask, set this property to null.

    The visibility of the object.

    + +
    + + + + + + +
    + + +
    +

    worldAlpha

    + Number + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:106 + +

    + + + + +
    + +
    +

    [read-only] The multiplied alpha of the displayobject

    + +
    + + + + + + +
    + + +
    +

    worldTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:125 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object based on world (parent) factors

    +
    @@ -2451,13 +2925,13 @@ To remove a mask, set this property to null.

    - + - - - - - - + + + + + + diff --git a/docs/classes/Ellipse.html b/docs/classes/Ellipse.html index c5b5e4e..7fbc4b1 100644 --- a/docs/classes/Ellipse.html +++ b/docs/classes/Ellipse.html @@ -3,11 +3,11 @@ Ellipse - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -150,7 +174,7 @@ @@ -166,7 +190,8 @@
    - +

    The Ellipse object can be used to specify a hit area for displayobjects

    +
    @@ -232,7 +257,7 @@ - src/pixi/core/Ellipse.js:5 + src/pixi/core/Ellipse.js:5

    @@ -261,7 +286,8 @@
    -

    The X coord of the upper-left corner of the framing rectangle of this circle

    +

    The X coord of the upper-left corner of the framing rectangle of this ellipse

    +
    @@ -276,7 +302,8 @@
    -

    The Y coord of the upper-left corner of the framing rectangle of this circle

    +

    The Y coord of the upper-left corner of the framing rectangle of this ellipse

    +
    @@ -291,7 +318,8 @@
    -

    The overall height of this ellipse

    +

    The overall width of this ellipse

    +
    @@ -306,7 +334,8 @@
    -

    The overall width of this ellipse

    +

    The overall height of this ellipse

    +
    @@ -423,7 +452,7 @@ - + Ellipse @@ -450,7 +479,7 @@ - src/pixi/core/Ellipse.js:44 + src/pixi/core/Ellipse.js:46

    @@ -461,7 +490,8 @@
    - +

    Creates a clone of this Ellipse instance

    +
    @@ -473,7 +503,10 @@
    - a copy of the polygon + Ellipse: + +

    a copy of the ellipse

    +
    @@ -508,7 +541,7 @@ - + Boolean @@ -535,7 +568,7 @@ - src/pixi/core/Ellipse.js:53 + src/pixi/core/Ellipse.js:57

    @@ -546,7 +579,8 @@
  • - +

    Checks if the x, and y coords passed to this function are contained within this ellipse

    +
    @@ -565,6 +599,7 @@

    The X coord of the point to test

    +
    @@ -580,6 +615,7 @@

    The Y coord of the point to test

    +
    @@ -596,7 +632,10 @@
    - if the x/y coords are within this polygon + Boolean: + +

    if the x/y coords are within this ellipse

    +
    @@ -637,7 +676,7 @@ - src/pixi/core/Ellipse.js:36 + src/pixi/core/Ellipse.js:38

    @@ -683,7 +722,7 @@ - src/pixi/core/Ellipse.js:29 + src/pixi/core/Ellipse.js:31

    @@ -729,7 +768,7 @@ - src/pixi/core/Ellipse.js:15 + src/pixi/core/Ellipse.js:17

    @@ -775,7 +814,7 @@ - src/pixi/core/Ellipse.js:22 + src/pixi/core/Ellipse.js:24

    @@ -813,13 +852,13 @@ - + - - - - - - + + + + + + diff --git a/docs/classes/EventTarget.html b/docs/classes/EventTarget.html new file mode 100644 index 0000000..a25d62d --- /dev/null +++ b/docs/classes/EventTarget.html @@ -0,0 +1,454 @@ + + + + + EventTarget - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    EventTarget Class

    +
    + + + + + + + + + + + Module: PIXI + + + + +
    + + + +
    +

    Adds event emitter functionality to a class

    + +
    + + + +
    + + +
    +
    +

    Item Index

    + + +
    +

    Methods

    + + +
    + + + + + + + +
    + + +
    +

    Methods

    + + +
    +

    autoDetectRenderer

    + + +
    + (
      + +
    • + + width + +
    • + +
    • + + height + +
    • + +
    • + + view + +
    • + +
    • + + transparent=false + +
    • + +
    • + + antialias=false + +
    • + +
    ) +
    + + + + + + + + + + + + static + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/utils/Detector.js:5 + +

    + + + + + +
    + +
    +

    This helper function will automatically detect which renderer you should be using. +WebGL is the preferred renderer as it is a lot fastest. If webGL is not supported by +the browser then this function will return a canvas renderer

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + width + Number + + + + +
      +

      the width of the renderers view

      + +
      + + +
    • + +
    • + + height + Number + + + + +
      +

      the height of the renderers view

      + +
      + + +
    • + +
    • + + view + Canvas + + + + +
      +

      the canvas to use as a view, optional

      + +
      + + +
    • + +
    • + + transparent=false + Boolean + + + + +
      +

      the transparency of the render view, default false

      + +
      + + +
    • + +
    • + + antialias=false + Boolean + + + + +
      +

      sets antialias (only applicable in webGL chrome at the moment)

      +

      antialias

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    + + + + + + + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/Graphics.html b/docs/classes/Graphics.html index 99e71fc..5fd3d7c 100644 --- a/docs/classes/Graphics.html +++ b/docs/classes/Graphics.html @@ -3,11 +3,11 @@ Graphics - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -154,7 +178,7 @@ @@ -170,9 +194,10 @@
    -

    The Graphics class contains a set of methods that you can use to create primitive shapes and lines. +

    The Graphics class contains a set of methods that you can use to create primitive shapes and lines. It is important to know that with the webGL renderer only simple polys can be filled at this stage -Complex polys will not be filled. Heres an example of a complex poly: http://www.goodboydigital.com/wp-content/uploads/2013/06/complexPolygon.png

    +Complex polys will not be filled. Heres an example of a complex poly: http://www.goodboydigital.com/wp-content/uploads/2013/06/complexPolygon.png

    +
    @@ -210,7 +235,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www - src/pixi/primitives/Graphics.js:6 + src/pixi/primitives/Graphics.js:6

    @@ -391,14 +416,16 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www -
  • +
  • setInteractive + deprecated +
  • -
  • +
  • swapChildren @@ -443,6 +470,13 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
      +
    • + _interactive + + + +
    • +
    • alpha @@ -462,6 +496,48 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www +
    • + +
    • + color + + + +
    • + +
    • + currentPath + + + +
    • + +
    • + dynamic + + + +
    • + +
    • + fillAlpha + + + +
    • + +
    • + filters + + + +
    • + +
    • + graphicsData + + +
    • @@ -476,6 +552,27 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www +
    • + +
    • + lineColor + + + +
    • + +
    • + lineWidth + + + +
    • + +
    • + localTransform + + +
    • @@ -504,6 +601,13 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www +
    • + +
    • + renderable + + +
    • @@ -532,6 +636,20 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www +
    • + +
    • + worldAlpha + + + +
    • + +
    • + worldTransform + + +
    @@ -557,7 +675,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
  • - DisplayObject + child
  • @@ -583,11 +701,11 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:42 + src/pixi/display/DisplayObjectContainer.js:32

    @@ -599,6 +717,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Adds a child to the container.

    +
    @@ -609,14 +728,15 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to add to the container

    +
    @@ -641,7 +761,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
  • - DisplayObject + child
  • @@ -673,11 +793,11 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:139 + src/pixi/display/DisplayObjectContainer.js:120

    @@ -689,6 +809,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown

    +
    @@ -699,14 +820,15 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
  • - DisplayObject + child DisplayObject
    - +

    The child to add

    +
    @@ -721,7 +843,8 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
    - +

    The index to place the child in

    +
    @@ -785,7 +908,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www - src/pixi/primitives/Graphics.js:85 + src/pixi/primitives/Graphics.js:123

    @@ -796,7 +919,9 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
  • -

    Specifies a simple one-color fill that subsequent calls to other Graphics methods (such as lineTo() or drawCircle()) use when drawing.

    +

    Specifies a simple one-color fill that subsequent calls to other Graphics methods +(such as lineTo() or drawCircle()) use when drawing.

    +
    @@ -815,6 +940,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    the color of the fill

    +
    @@ -830,6 +956,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    the alpha

    +
    @@ -877,7 +1004,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www - src/pixi/primitives/Graphics.js:167 + src/pixi/primitives/Graphics.js:211

    @@ -889,6 +1016,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings.

    +
    @@ -934,11 +1062,11 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:109 + src/pixi/display/DisplayObject.js:174

    @@ -950,6 +1078,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    A callback that is used when the users clicks on the displayObject with their mouse

    +
    @@ -961,7 +1090,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
  • interactionData - InteractionData + InteractionData @@ -1037,7 +1166,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www - src/pixi/primitives/Graphics.js:128 + src/pixi/primitives/Graphics.js:170

    @@ -1049,6 +1178,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Draws a circle.

    +
    @@ -1066,7 +1196,8 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
    - +

    The X coord of the center of the circle

    +
    @@ -1081,7 +1212,8 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
    - +

    The Y coord of the center of the circle

    +
    @@ -1096,7 +1228,8 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
    - +

    The radius of the circle

    +
    @@ -1172,7 +1305,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www - src/pixi/primitives/Graphics.js:147 + src/pixi/primitives/Graphics.js:190

    @@ -1184,6 +1317,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Draws an elipse.

    +
    @@ -1322,7 +1456,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www - src/pixi/primitives/Graphics.js:109 + src/pixi/primitives/Graphics.js:150

    @@ -1351,7 +1485,8 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
    - +

    The X coord of the top-left of the rectangle

    +
    @@ -1366,7 +1501,8 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
    - +

    The Y coord of the top-left of the rectangle

    +
    @@ -1381,7 +1517,8 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
    - +

    The width of the rectangle

    +
    @@ -1396,7 +1533,8 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
    - +

    The height of the rectangle

    +
    @@ -1444,7 +1582,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www - src/pixi/primitives/Graphics.js:98 + src/pixi/primitives/Graphics.js:138

    @@ -1456,6 +1594,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Applies a fill to the lines and shapes that were added since the last call to the beginFill() method.

    +
    @@ -1501,11 +1640,11 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:274 + src/pixi/display/DisplayObjectContainer.js:256

    @@ -1517,6 +1656,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Returns the Child at the specified index

    +
    @@ -1534,7 +1674,8 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
    - +

    The index to get the child from

    +
    @@ -1604,7 +1745,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www - src/pixi/primitives/Graphics.js:34 + src/pixi/primitives/Graphics.js:68

    @@ -1616,6 +1757,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Specifies a line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method.

    +
    @@ -1633,7 +1775,8 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
    - +

    width of the line to draw, will update the object's stored style

    +
    @@ -1648,7 +1791,8 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
    - +

    color of the line to draw, will update the object's stored style

    +
    @@ -1663,7 +1807,8 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
    - +

    alpha of the line to draw, will update the object's stored style

    +
    @@ -1727,7 +1872,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www - src/pixi/primitives/Graphics.js:73 + src/pixi/primitives/Graphics.js:109

    @@ -1738,7 +1883,9 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
  • -

    Draws a line using the current line style from the current drawing position to (x, y); the current drawing position is then set to (x, y).

    +

    Draws a line using the current line style from the current drawing position to (x, y); +the current drawing position is then set to (x, y).

    +
    @@ -1756,7 +1903,8 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
    - +

    the X coord to draw to

    +
    @@ -1771,7 +1919,8 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
    - +

    the Y coord to draw to

    +
    @@ -1822,11 +1971,11 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:115 + src/pixi/display/DisplayObject.js:180

    @@ -1838,6 +1987,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    A callback that is used when the user clicks the mouse down over the sprite

    +
    @@ -1849,7 +1999,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
  • interactionData - InteractionData + InteractionData @@ -1906,11 +2056,11 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:141 + src/pixi/display/DisplayObject.js:206

    @@ -1922,6 +2072,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    A callback that is used when the users mouse leaves the displayObject

    +
    @@ -1933,7 +2084,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
  • interactionData - InteractionData + InteractionData @@ -1990,11 +2141,11 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:135 + src/pixi/display/DisplayObject.js:200

    @@ -2006,6 +2157,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    A callback that is used when the users mouse rolls over the displayObject

    +
    @@ -2017,7 +2169,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www
  • interactionData - InteractionData + InteractionData @@ -2074,11 +2226,11 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:121 + src/pixi/display/DisplayObject.js:186

    @@ -2091,6 +2243,7 @@ Complex polys will not be filled. Heres an example of a complex poly: http://www

    A callback that is used when the user releases the mouse that was over the displayObject for this callback to be fired the mouse must have been pressed down over the displayObject

    +
    @@ -2102,7 +2255,7 @@ for this callback to be fired the mouse must have been pressed down over the dis
  • interactionData - InteractionData + InteractionData @@ -2159,11 +2312,11 @@ for this callback to be fired the mouse must have been pressed down over the dis

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:128 + src/pixi/display/DisplayObject.js:193

    @@ -2176,6 +2329,7 @@ for this callback to be fired the mouse must have been pressed down over the dis

    A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject for this callback to be fired, The touch must have started over the displayObject

    +
    @@ -2187,7 +2341,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • interactionData - InteractionData + InteractionData @@ -2257,7 +2411,7 @@ for this callback to be fired, The touch must have started over the displayObjec - src/pixi/primitives/Graphics.js:55 + src/pixi/primitives/Graphics.js:90

    @@ -2269,6 +2423,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    Moves the current drawing position to (x, y).

    +
    @@ -2286,7 +2441,8 @@ for this callback to be fired, The touch must have started over the displayObjec
    - +

    the X coord to move to

    +
    @@ -2301,7 +2457,8 @@ for this callback to be fired, The touch must have started over the displayObjec
    - +

    the Y coord to move to

    +
    @@ -2326,7 +2483,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • - DisplayObject + child
  • @@ -2352,11 +2509,11 @@ for this callback to be fired, The touch must have started over the displayObjec

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:291 + src/pixi/display/DisplayObjectContainer.js:274

    @@ -2368,6 +2525,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    Removes a child from the container.

    +
    @@ -2378,14 +2536,15 @@ for this callback to be fired, The touch must have started over the displayObjec
  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to remove

    +
    @@ -2401,7 +2560,7 @@ for this callback to be fired, The touch must have started over the displayObjec -
    +

    setInteractive

    @@ -2421,6 +2580,8 @@ for this callback to be fired, The touch must have started over the displayObjec + deprecated + @@ -2436,16 +2597,18 @@ for this callback to be fired, The touch must have started over the displayObjec

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:193 + src/pixi/display/DisplayObject.js:247

    +

    Deprecated: Simply set the `interactive` property directly

    +
    @@ -2453,6 +2616,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default Instead of using this function you can now simply set the interactive property to true or false

    +
    @@ -2486,7 +2650,7 @@ Instead of using this function you can now simply set the interactive property t
    -
    +

    swapChildren

    @@ -2495,13 +2659,13 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child
  • - DisplayObject2 + child2
  • @@ -2514,6 +2678,8 @@ Instead of using this function you can now simply set the interactive property t + private + @@ -2527,11 +2693,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:227 + src/pixi/display/DisplayObjectContainer.js:207

    @@ -2542,7 +2708,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    Swaps the depth of 2 displayObjects

    +

    [NYI] Swaps the depth of 2 displayObjects

    +
    @@ -2553,7 +2720,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child DisplayObject @@ -2568,7 +2735,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject2 + child2 DisplayObject @@ -2626,11 +2793,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:152 + src/pixi/display/DisplayObject.js:217

    @@ -2643,6 +2810,7 @@ Instead of using this function you can now simply set the interactive property t

    A callback that is used when the users taps on the sprite with their finger basically a touch version of click

    +
    @@ -2654,7 +2822,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -2711,11 +2879,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:165 + src/pixi/display/DisplayObject.js:230

    @@ -2727,6 +2895,7 @@ basically a touch version of click

    A callback that is used when the user releases a touch over the displayObject

    +
    @@ -2738,7 +2907,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -2795,11 +2964,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:171 + src/pixi/display/DisplayObject.js:236

    @@ -2812,6 +2981,7 @@ basically a touch version of click

    A callback that is used when the user releases the touch that was over the displayObject for this callback to be fired, The touch must have started over the sprite

    +
    @@ -2823,7 +2993,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -2880,11 +3050,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:159 + src/pixi/display/DisplayObject.js:224

    @@ -2895,7 +3065,8 @@ for this callback to be fired, The touch must have started over the sprite

    -

    A callback that is used when the user touch's over the displayObject

    +

    A callback that is used when the user touch's over the displayObject

    +
    @@ -2907,7 +3078,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -2937,6 +3108,50 @@ for this callback to be fired, The touch must have started over the sprite

    Properties

    +
    +

    _interactive

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:115 + +

    + + + + +
    + +
    +

    [read-only] Whether or not the object is interactive, do not toggle directly! use the interactive property

    + +
    + + + + + + +
    + +

    alpha

    Number @@ -2953,11 +3168,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:43 + src/pixi/display/DisplayObject.js:47

    @@ -2968,6 +3183,7 @@ for this callback to be fired, The touch must have started over the sprite

    The opacity of the object.

    +
    @@ -2994,11 +3210,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:98 + src/pixi/display/DisplayObject.js:72

    @@ -3009,6 +3225,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is used to indicate if the displayObject should display a mouse hand cursor on rollover

    +
    @@ -3021,7 +3238,7 @@ for this callback to be fired, The touch must have started over the sprite

    children

    - Array + Array @@ -3035,11 +3252,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:16 + src/pixi/display/DisplayObjectContainer.js:18

    @@ -3050,6 +3267,278 @@ for this callback to be fired, The touch must have started over the sprite

    [read-only] The of children of this container.

    + +
    + + + + + + +
    + + +
    +

    color

    + Array<> + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:145 + +

    + + + + +
    + +
    +

    [NYI] Unkown

    + +
    + + + + + + +
    + + +
    +

    currentPath

    + Object + + + + + private + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/primitives/Graphics.js:54 + +

    + + + + +
    + +
    +

    Current path

    + +
    + + + + + + +
    + + +
    +

    dynamic

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:154 + +

    + + + + +
    + +
    +

    [NYI] Holds whether or not this object is dynamic, for rendering optimization

    + +
    + + + + + + +
    + + +
    +

    fillAlpha

    + Number + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/primitives/Graphics.js:21 + +

    + + + + +
    + +
    +

    The alpha of the fill of this graphics object

    + +
    + + + + + + +
    + + +
    +

    filters

    + Array An array of filters + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:318 + +

    + + + + +
    + +
    +

    Sets the filters for the displayObject. +* IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. +To remove filters simply set this property to 'null'

    + +
    + + + + + + +
    + + +
    +

    graphicsData

    + Array + + + + + private + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/primitives/Graphics.js:45 + +

    + + + + +
    + +
    +

    Graphics data

    +
    @@ -3062,7 +3551,7 @@ for this callback to be fired, The touch must have started over the sprite

    hitArea

    - Rectangle + Rectangle | Circle | Ellipse | Polygon @@ -3076,11 +3565,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:72 + src/pixi/display/DisplayObject.js:63

    @@ -3092,6 +3581,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is the defined area that will pick up mouse / touch events. It is null by default. Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)

    +
    @@ -3118,11 +3608,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:204 + src/pixi/display/DisplayObject.js:260

    @@ -3133,6 +3623,143 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Indicates if the sprite will have touch and mouse interactivity. It is false by default

    + +
    + + +

    Default: false

    + + + + + +
    + + +
    +

    lineColor

    + String + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/primitives/Graphics.js:37 + +

    + + + + +
    + +
    +

    The color of any lines drawn

    + +
    + + + + + + +
    + + +
    +

    lineWidth

    + Number + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/primitives/Graphics.js:29 + +

    + + + + +
    + +
    +

    The width of any lines drawn

    + +
    + + + + + + +
    + + +
    +

    localTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:135 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object locally

    +
    @@ -3145,7 +3772,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    mask

    - PIXI.Graphics + Graphics @@ -3159,11 +3786,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:222 + src/pixi/display/DisplayObject.js:280

    @@ -3176,6 +3803,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. To remove a mask, set this property to null.

    +
    @@ -3202,11 +3830,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:58 + src/pixi/display/DisplayObject.js:88

    @@ -3217,6 +3845,7 @@ To remove a mask, set this property to null.

    [read-only] The display object container that contains this display object.

    +
    @@ -3243,11 +3872,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:29 + src/pixi/display/DisplayObject.js:31

    @@ -3258,6 +3887,7 @@ To remove a mask, set this property to null.

    The pivot point of the displayObject that it rotates around

    +
    @@ -3284,11 +3914,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:15 + src/pixi/display/DisplayObject.js:15

    @@ -3299,6 +3929,49 @@ To remove a mask, set this property to null.

    The coordinate of the object relative to the local coordinates of the parent.

    + +
    + + + + + + +
    + + +
    +

    renderable

    + Boolean + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:80 + +

    + + + + +
    + +
    +

    Can this object be rendered

    +
    @@ -3325,11 +3998,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:36 + src/pixi/display/DisplayObject.js:39

    @@ -3340,6 +4013,7 @@ To remove a mask, set this property to null.

    The rotation of the object in radians.

    +
    @@ -3366,11 +4040,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:22 + src/pixi/display/DisplayObject.js:23

    @@ -3381,6 +4055,7 @@ To remove a mask, set this property to null.

    The scale factor of the object.

    +
    @@ -3407,11 +4082,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:65 + src/pixi/display/DisplayObject.js:97

    @@ -3422,6 +4097,7 @@ To remove a mask, set this property to null.

    [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.

    +
    @@ -3448,11 +4124,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:50 + src/pixi/display/DisplayObject.js:55

    @@ -3463,6 +4139,93 @@ To remove a mask, set this property to null.

    The visibility of the object.

    + +
    + + + + + + +
    + + +
    +

    worldAlpha

    + Number + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:106 + +

    + + + + +
    + +
    +

    [read-only] The multiplied alpha of the displayobject

    + +
    + + + + + + +
    + + +
    +

    worldTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:125 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object based on world (parent) factors

    +
    @@ -3488,13 +4251,13 @@ To remove a mask, set this property to null.

    - + - - - - - - + + + + + + diff --git a/docs/classes/GreyFilter.html b/docs/classes/GreyFilter.html new file mode 100644 index 0000000..4f47931 --- /dev/null +++ b/docs/classes/GreyFilter.html @@ -0,0 +1,315 @@ + + + + + GreyFilter - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    GreyFilter Class

    +
    + + + + + + + + + + + Module: PIXI + + + + +
    + + + +
    +

    This turns your displayObjects to black and white.

    + +
    + + + +
    + + +
    +
    +

    Item Index

    + + + + +
    +

    Properties

    + +
      + +
    • + grey + + + +
    • + +
    +
    + + + + + +
    + + + + +
    +

    Properties

    + + +
    +

    grey

    + Unknown + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/filters/GreyFilter.js:40 + +

    + + + + +
    + +
    +

    The strength of the grey. 1 will make the object black and white, 0 will make the object its normal color

    + +
    + + + + + + +
    + + +
    + + + + + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/ImageLoader.html b/docs/classes/ImageLoader.html index 0400bba..d2ef76d 100644 --- a/docs/classes/ImageLoader.html +++ b/docs/classes/ImageLoader.html @@ -3,11 +3,11 @@ ImageLoader - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -145,16 +169,21 @@

    ImageLoader Class

    - - -
    - Extends EventTarget +
    + Uses +
    + + @@ -170,9 +199,10 @@
    -

    The image loader class is responsible for loading images file formats ("jpeg", "jpg", "png" and "gif") +

    The image loader class is responsible for loading images file formats ("jpeg", "jpg", "png" and "gif") Once the image has been loaded it is stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId() -When loaded this class will dispatch a 'loaded' event

    +When loaded this class will dispatch a 'loaded' event

    +
    @@ -226,7 +256,7 @@ When loaded this class will dispatch a 'loaded' event

    - src/pixi/loaders/ImageLoader.js:5 + src/pixi/loaders/ImageLoader.js:5

    @@ -256,6 +286,7 @@ When loaded this class will dispatch a 'loaded' event

    The url of the image

    +
    @@ -270,7 +301,8 @@ When loaded this class will dispatch a 'loaded' event

    - +

    Whether requests should be treated as crossorigin

    +
    @@ -293,6 +325,10 @@ When loaded this class will dispatch a 'loaded' event

  • Index
  • +
  • Methods
  • + + +
  • Properties
  • @@ -303,7 +339,51 @@ When loaded this class will dispatch a 'loaded' event

    Item Index

    +
    +

    Methods

    + +
    + + + +
    +

    Properties

    + + +
    @@ -312,7 +392,309 @@ When loaded this class will dispatch a 'loaded' event

    +
    +

    Methods

    + +
    +

    load

    + + + () + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/ImageLoader.js:39 + +

    + + + + + +
    + +
    +

    Loads image or takes it from cache

    + +
    + + + + + + +
    + + +
    +

    loadFramedSpriteSheet

    + + +
    + (
      + +
    • + + frameWidth + +
    • + +
    • + + frameHeight + +
    • + +
    • + + textureName + +
    • + +
    ) +
    + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/ImageLoader.js:71 + +

    + + + + + +
    + +
    +

    Loads image and split it to uniform sized frames

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + frameWidth + Number + + + + +
      +

      with of each frame

      + +
      + + +
    • + +
    • + + frameHeight + Number + + + + +
      +

      height of each frame

      + +
      + + +
    • + +
    • + + textureName + String + + + + +
      +

      if given, the frames will be cached in - format

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    onLoaded

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/ImageLoader.js:60 + +

    + + + + + +
    + +
    +

    Invoked when image file is loaded or it is already cached and ready to use

    + +
    + + + + + + +
    + + +
    + + + +
    +

    Properties

    + + +
    +

    texture

    + Texture + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/ImageLoader.js:20 + +

    + + + + +
    + +
    +

    The texture being loaded

    + +
    + + + + + + +
    + + +
    @@ -327,13 +709,13 @@ When loaded this class will dispatch a 'loaded' event

    - + - - - - - - + + + + + + diff --git a/docs/classes/InteractionManager.html b/docs/classes/InteractionManager.html deleted file mode 100644 index 54f508b..0000000 --- a/docs/classes/InteractionManager.html +++ /dev/null @@ -1,660 +0,0 @@ - - - - - InteractionManager - Pixi.JS - - - - - - - - -
    -
    -
    - -

    - -
    -
    - API Docs for: 1.3.0 -
    -
    -
    - - -
    -
    - Show: - - - - - - - -
    - - -
    -
    -
    -

    InteractionManager Class

    -
    - - - - - - - - - - - Module: PIXI - - - - -
    - - - -
    -

    The interaction manager deals with mouse and touch events. Any DisplayObject can be interactive -This manager also supports multitouch.

    -
    - - -
    -

    Constructor

    -
    -

    InteractionManager

    - - -
    - (
      - -
    • - - stage - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/pixi/InteractionManager.js:7 - -

    - - - - - -
    - -
    - -
    - - -
    -

    Parameters:

    - -
      - -
    • - - stage - Stage - - - - -
      - -
      - - -
    • - -
    -
    - - - - - -
    - -
    - - -
    - - -
    -
    -

    Item Index

    - - -
    -

    Methods

    - - -
    - - - -
    -

    Properties

    - - -
    - - - - - -
    - - -
    -

    Methods

    - - -
    -

    autoDetectRenderer

    - - -
    - (
      - -
    • - - width - -
    • - -
    • - - height - -
    • - -
    • - - view - -
    • - -
    • - - transparent - -
    • - -
    ) -
    - - - - - - - - - - - - static - - - - - - -
    - - - -

    - - Defined in - - - - - src/pixi/utils/Detector.js:5 - -

    - - - - - -
    - -
    -

    This helper function will automatically detect which renderer you should be using. -WebGL is the preferred renderer as it is a lot fastest. If webGL is not supported by the browser then this function will return a canvas renderer

    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - width - Number - - - - -
      -

      the width of the renderers view

      -
      - - -
    • - -
    • - - height - Number - - - - -
      -

      the height of the renderers view

      -
      - - -
    • - -
    • - - view - Canvas - - - - -
      -

      the canvas to use as a view, optional

      -
      - - -
    • - -
    • - - transparent - Boolean - - - - -
      -

      the transparency of the render view, default false

      -
      - - -
    • - -
    -
    - - - - - -
    - - -
    - - - -
    -

    Properties

    - - -
    -

    mouse

    - InteractionData - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/pixi/InteractionManager.js:30 - -

    - - - - -
    - -
    -

    the mouse data

    -
    - - - - - - -
    - - -
    -

    stage

    - Stage - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/pixi/InteractionManager.js:17 - -

    - - - - -
    - -
    -

    a refference to the stage

    -
    - - - - - - -
    - - -
    -

    touchs

    - Object - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/pixi/InteractionManager.js:37 - -

    - - - - -
    - -
    -

    an object that stores current touches (InteractionData) by id reference

    -
    - - - - - - -
    - - -
    - - - - - -
    -
    - -
    -
    -
    -
    -
    -
    - - - - - - - - - - diff --git a/docs/classes/InvertFilter.html b/docs/classes/InvertFilter.html new file mode 100644 index 0000000..d2184c7 --- /dev/null +++ b/docs/classes/InvertFilter.html @@ -0,0 +1,315 @@ + + + + + InvertFilter - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    InvertFilter Class

    +
    + + + + + + + + + + + Module: PIXI + + + + +
    + + + +
    +

    This inverts your displayObjects colors.

    + +
    + + + +
    + + +
    +
    +

    Item Index

    + + + + +
    +

    Properties

    + + +
    + + + + + +
    + + + + +
    +

    Properties

    + + +
    +

    invert

    + Unknown + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/filters/InvertFilter.js:41 + +

    + + + + +
    + +
    +

    The strength of the invert. 1 will fully invert the colors, 0 will make the object its normal color

    + +
    + + + + + + +
    + + +
    + + + + + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/JsonLoader.html b/docs/classes/JsonLoader.html index a7e8161..c5c510b 100644 --- a/docs/classes/JsonLoader.html +++ b/docs/classes/JsonLoader.html @@ -3,11 +3,11 @@ JsonLoader - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -145,16 +169,21 @@

    JsonLoader Class

    - - -
    - Extends EventTarget +
    + Uses +
    + + @@ -171,8 +200,9 @@

    The json file loader is used to load in JSON data and parsing it -When loaded this class will dispatch a "loaded" event -If load failed this class will dispatch a "error" event

    +When loaded this class will dispatch a "loaded" event +If load failed this class will dispatch a "error" event

    +
    @@ -226,7 +256,7 @@ If load failed this class will dispatch a "error" event

    - src/pixi/loaders/JsonLoader.js:5 + src/pixi/loaders/JsonLoader.js:5

    @@ -255,7 +285,8 @@ If load failed this class will dispatch a "error" event

    -

    the url of the JSON file

    +

    The url of the JSON file

    +
    @@ -270,7 +301,8 @@ If load failed this class will dispatch a "error" event

    - +

    Whether requests should be treated as crossorigin

    +
    @@ -293,6 +325,10 @@ If load failed this class will dispatch a "error" event

  • Index
  • +
  • Methods
  • + + +
  • Properties
  • @@ -303,7 +339,79 @@ If load failed this class will dispatch a "error" event

    Item Index

    +
    +

    Methods

    + +
    + + + +
    +

    Properties

    + + +
    @@ -312,7 +420,425 @@ If load failed this class will dispatch a "error" event

    +
    +

    Methods

    + +
    +

    load

    + + + () + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/JsonLoader.js:58 + +

    + + + + + +
    + +
    +

    Loads the JSON data

    + +
    + + + + + + +
    + + +
    +

    onError

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/JsonLoader.js:154 + +

    + + + + + +
    + +
    +

    Invoke when error occured

    + +
    + + + + + + +
    + + +
    +

    onJSONLoaded

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/JsonLoader.js:75 + +

    + + + + + +
    + +
    +

    Invoke when JSON file is loaded

    + +
    + + + + + + +
    + + +
    +

    onLoaded

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/JsonLoader.js:140 + +

    + + + + + +
    + +
    +

    Invoke when json file loaded

    + +
    + + + + + + +
    + + +
    + + + +
    +

    Properties

    + + +
    +

    baseUrl

    + String + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/JsonLoader.js:35 + +

    + + + + +
    + +
    +

    [read-only] The base url of the bitmap font data

    + +
    + + + + + + +
    + + +
    +

    crossorigin

    + Boolean + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/JsonLoader.js:27 + +

    + + + + +
    + +
    +

    Whether the requests should be treated as cross origin

    + +
    + + + + + + +
    + + +
    +

    loaded

    + Boolean + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/JsonLoader.js:44 + +

    + + + + +
    + +
    +

    [read-only] Whether the data has loaded yet

    + +
    + + + + + + +
    + + +
    +

    url

    + String + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/JsonLoader.js:19 + +

    + + + + +
    + +
    +

    The url of the bitmap font data

    + +
    + + + + + + +
    + + +
    @@ -327,13 +853,13 @@ If load failed this class will dispatch a "error" event

    - + - - - - - - + + + + + + diff --git a/docs/classes/MovieClip.html b/docs/classes/MovieClip.html index ecfa688..90a28a9 100644 --- a/docs/classes/MovieClip.html +++ b/docs/classes/MovieClip.html @@ -3,11 +3,11 @@ MovieClip - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -154,7 +178,7 @@ @@ -171,6 +195,7 @@

    A MovieClip is a simple way to display an animation depicted by a list of textures.

    +
    @@ -218,7 +243,7 @@ - src/pixi/display/MovieClip.js:5 + src/pixi/display/MovieClip.js:5

    @@ -241,13 +266,14 @@
  • textures - Array + Array

    an array of {Texture} objects that make up the animation

    +
    @@ -364,6 +390,13 @@ +
  • + +
  • + onTextureUpdate + + +
  • @@ -380,11 +413,13 @@
  • -
  • +
  • setInteractive + deprecated +
  • @@ -401,7 +436,7 @@
  • -
  • +
  • swapChildren @@ -446,6 +481,27 @@ @@ -637,7 +749,7 @@
  • - DisplayObject + child
  • @@ -663,11 +775,11 @@

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:42 + src/pixi/display/DisplayObjectContainer.js:32

    @@ -679,6 +791,7 @@

    Adds a child to the container.

    +
    @@ -689,14 +802,15 @@
  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to add to the container

    +
    @@ -721,7 +835,7 @@
  • - DisplayObject + child
  • @@ -753,11 +867,11 @@

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:139 + src/pixi/display/DisplayObjectContainer.js:120

    @@ -769,6 +883,7 @@

    Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown

    +
    @@ -779,14 +894,15 @@
  • - DisplayObject + child DisplayObject
    - +

    The child to add

    +
    @@ -801,7 +917,8 @@
    - +

    The index to place the child in

    +
    @@ -852,11 +969,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:109 + src/pixi/display/DisplayObject.js:174

    @@ -868,6 +985,7 @@

    A callback that is used when the users clicks on the displayObject with their mouse

    +
    @@ -879,7 +997,7 @@
  • interactionData - InteractionData + InteractionData @@ -936,11 +1054,11 @@

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:274 + src/pixi/display/DisplayObjectContainer.js:256

    @@ -952,6 +1070,7 @@

    Returns the Child at the specified index

    +
    @@ -969,7 +1088,8 @@
    - +

    The index to get the child from

    +
    @@ -1027,7 +1147,7 @@ - src/pixi/display/MovieClip.js:94 + src/pixi/display/MovieClip.js:126

    @@ -1039,6 +1159,7 @@

    Goes to a specific frame and begins playing the MovieClip

    +
    @@ -1057,6 +1178,7 @@

    frame index to start at

    +
    @@ -1114,7 +1236,7 @@ - src/pixi/display/MovieClip.js:81 + src/pixi/display/MovieClip.js:112

    @@ -1126,6 +1248,7 @@

    Stops the MovieClip and goes to a specific frame

    +
    @@ -1144,6 +1267,7 @@

    frame index to stop at

    +
    @@ -1194,11 +1318,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:115 + src/pixi/display/DisplayObject.js:180

    @@ -1210,6 +1334,7 @@

    A callback that is used when the user clicks the mouse down over the sprite

    +
    @@ -1221,7 +1346,7 @@
  • interactionData - InteractionData + InteractionData @@ -1278,11 +1403,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:141 + src/pixi/display/DisplayObject.js:206

    @@ -1294,6 +1419,7 @@

    A callback that is used when the users mouse leaves the displayObject

    +
    @@ -1305,7 +1431,7 @@
  • interactionData - InteractionData + InteractionData @@ -1362,11 +1488,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:135 + src/pixi/display/DisplayObject.js:200

    @@ -1378,6 +1504,7 @@

    A callback that is used when the users mouse rolls over the displayObject

    +
    @@ -1389,7 +1516,7 @@
  • interactionData - InteractionData + InteractionData @@ -1446,11 +1573,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:121 + src/pixi/display/DisplayObject.js:186

    @@ -1463,6 +1590,7 @@

    A callback that is used when the user releases the mouse that was over the displayObject for this callback to be fired the mouse must have been pressed down over the displayObject

    +
    @@ -1474,7 +1602,7 @@ for this callback to be fired the mouse must have been pressed down over the dis
  • interactionData - InteractionData + InteractionData @@ -1531,11 +1659,11 @@ for this callback to be fired the mouse must have been pressed down over the dis

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:128 + src/pixi/display/DisplayObject.js:193

    @@ -1548,6 +1676,7 @@ for this callback to be fired the mouse must have been pressed down over the dis

    A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject for this callback to be fired, The touch must have started over the displayObject

    +
    @@ -1559,7 +1688,94 @@ for this callback to be fired, The touch must have started over the displayObjec
  • interactionData - InteractionData + InteractionData + + + + +
    + +
    + + +
  • + + +
    + + + + + +
    + + +
    +

    onTextureUpdate

    + + +
    + () +
    + + + + + + + + private + + + + + + + + + + +
    + + +

    Inherited from + Sprite: + + + + src/pixi/display/Sprite.js:145 + +

    + + + + + +
    + +
    +

    When the texture is updated, this event will fire to update the scale and frame

    + +
    + + +
    +

    Parameters:

    + +
    -
    +

    setInteractive

    @@ -1739,6 +1958,8 @@ for this callback to be fired, The touch must have started over the displayObjec + deprecated + @@ -1754,16 +1975,18 @@ for this callback to be fired, The touch must have started over the displayObjec

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:193 + src/pixi/display/DisplayObject.js:247

    +

    Deprecated: Simply set the `interactive` property directly

    +
    @@ -1771,6 +1994,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default Instead of using this function you can now simply set the interactive property to true or false

    +
    @@ -1839,11 +2063,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - Sprite: + Sprite: - src/pixi/display/Sprite.js:103 + src/pixi/display/Sprite.js:118

    @@ -1854,7 +2078,8 @@ Instead of using this function you can now simply set the interactive property t
    - +

    Sets the texture of the sprite

    +
    @@ -1873,6 +2098,7 @@ Instead of using this function you can now simply set the interactive property t

    The PIXI texture that is displayed by the sprite

    +
    @@ -1920,7 +2146,7 @@ Instead of using this function you can now simply set the interactive property t - src/pixi/display/MovieClip.js:63 + src/pixi/display/MovieClip.js:92

    @@ -1932,6 +2158,7 @@ Instead of using this function you can now simply set the interactive property t

    Stops the MovieClip

    +
    @@ -1942,7 +2169,7 @@ Instead of using this function you can now simply set the interactive property t
    -
    +

    swapChildren

    @@ -1951,13 +2178,13 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child
  • - DisplayObject2 + child2
  • @@ -1970,6 +2197,8 @@ Instead of using this function you can now simply set the interactive property t + private + @@ -1983,11 +2212,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:227 + src/pixi/display/DisplayObjectContainer.js:207

    @@ -1998,7 +2227,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    Swaps the depth of 2 displayObjects

    +

    [NYI] Swaps the depth of 2 displayObjects

    +
    @@ -2009,7 +2239,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child DisplayObject @@ -2024,7 +2254,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject2 + child2 DisplayObject @@ -2082,11 +2312,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:152 + src/pixi/display/DisplayObject.js:217

    @@ -2099,6 +2329,7 @@ Instead of using this function you can now simply set the interactive property t

    A callback that is used when the users taps on the sprite with their finger basically a touch version of click

    +
    @@ -2110,7 +2341,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -2167,11 +2398,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:165 + src/pixi/display/DisplayObject.js:230

    @@ -2183,6 +2414,7 @@ basically a touch version of click

    A callback that is used when the user releases a touch over the displayObject

    +
    @@ -2194,7 +2426,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -2251,11 +2483,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:171 + src/pixi/display/DisplayObject.js:236

    @@ -2268,6 +2500,7 @@ basically a touch version of click

    A callback that is used when the user releases the touch that was over the displayObject for this callback to be fired, The touch must have started over the sprite

    +
    @@ -2279,7 +2512,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -2336,11 +2569,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:159 + src/pixi/display/DisplayObject.js:224

    @@ -2351,7 +2584,8 @@ for this callback to be fired, The touch must have started over the sprite

  • -

    A callback that is used when the user touch's over the displayObject

    +

    A callback that is used when the user touch's over the displayObject

    +
    @@ -2363,7 +2597,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -2393,6 +2627,138 @@ for this callback to be fired, The touch must have started over the sprite

    Properties

    +
    +

    _height

    + Number + + + + + private + + + + + + +
    + + +

    Inherited from + Sprite: + + + + src/pixi/display/Sprite.js:60 + +

    + + + + +
    + +
    +

    The height of the sprite (this is initially set by the texture)

    + +
    + + + + + + +
    + + +
    +

    _interactive

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:115 + +

    + + + + +
    + +
    +

    [read-only] Whether or not the object is interactive, do not toggle directly! use the interactive property

    + +
    + + + + + + +
    + + +
    +

    _width

    + Number + + + + + private + + + + + + +
    + + +

    Inherited from + Sprite: + + + + src/pixi/display/Sprite.js:51 + +

    + + + + +
    + +
    +

    The width of the sprite (this is initially set by the texture)

    + +
    + + + + + + +
    + +

    alpha

    Number @@ -2409,11 +2775,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:43 + src/pixi/display/DisplayObject.js:47

    @@ -2424,6 +2790,7 @@ for this callback to be fired, The touch must have started over the sprite

    The opacity of the object.

    +
    @@ -2450,11 +2817,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - Sprite: + Sprite: - src/pixi/display/Sprite.js:21 + src/pixi/display/Sprite.js:23

    @@ -2468,6 +2835,7 @@ for this callback to be fired, The touch must have started over the sprite

    The default is 0,0 this means the textures origin is the top left Setting than anchor to 0.5,0.5 means the textures origin is centered Setting the anchor to 1,1 would mean the textures origin points will be the bottom right

    +
    @@ -2501,7 +2869,7 @@ Setting the anchor to 1,1 would mean the textures origin points will be the bott - src/pixi/display/MovieClip.js:30 + src/pixi/display/MovieClip.js:25

    @@ -2512,9 +2880,12 @@ Setting the anchor to 1,1 would mean the textures origin points will be the bott

    The speed that the MovieClip will play at. Higher is faster, lower is slower

    +
    +

    Default: 1

    + @@ -2524,7 +2895,7 @@ Setting the anchor to 1,1 would mean the textures origin points will be the bott

    blendMode

    - Uint + Number @@ -2538,11 +2909,11 @@ Setting the anchor to 1,1 would mean the textures origin points will be the bott

    Inherited from - Sprite: + Sprite: - src/pixi/display/Sprite.js:38 + src/pixi/display/Sprite.js:42

    @@ -2554,6 +2925,7 @@ Setting the anchor to 1,1 would mean the textures origin points will be the bott

    The blend mode of sprite. currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    +
    @@ -2580,11 +2952,11 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:98 + src/pixi/display/DisplayObject.js:72

    @@ -2595,6 +2967,7 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    This is used to indicate if the displayObject should display a mouse hand cursor on rollover

    +
    @@ -2607,7 +2980,7 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    children

    - Array + Array @@ -2621,11 +2994,11 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:16 + src/pixi/display/DisplayObjectContainer.js:18

    @@ -2636,6 +3009,51 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    [read-only] The of children of this container.

    + +
    + + + + + + +
    + + +
    +

    color

    + Array<> + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:145 + +

    + + + + +
    + +
    +

    [NYI] Unkown

    +
    @@ -2669,7 +3087,7 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    - src/pixi/display/MovieClip.js:23 + src/pixi/display/MovieClip.js:51

    @@ -2679,7 +3097,98 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    -

    [read only] The index MovieClips current frame (this may not have to be a whole number)

    +

    [read-only] The index MovieClips current frame (this may not have to be a whole number)

    + +
    + + +

    Default: 0

    + + + + + +
    + + +
    +

    dynamic

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:154 + +

    + + + + +
    + +
    +

    [NYI] Holds whether or not this object is dynamic, for rendering optimization

    + +
    + + + + + + +
    + + +
    +

    filters

    + Array An array of filters + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:318 + +

    + + + + +
    + +
    +

    Sets the filters for the displayObject. +* IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. +To remove filters simply set this property to 'null'

    +
    @@ -2692,7 +3201,7 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    height

    - #Number + Number @@ -2706,11 +3215,11 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    Inherited from - Sprite: + Sprite: - src/pixi/display/Sprite.js:53 + src/pixi/display/Sprite.js:102

    @@ -2720,7 +3229,8 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    -

    The height of the sprite (this is initially set by the texture)

    +

    The height of the sprite, setting this will actually modify the scale to acheive the value set

    +
    @@ -2733,7 +3243,7 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    hitArea

    - Rectangle + Rectangle | Circle | Ellipse | Polygon @@ -2747,11 +3257,11 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:72 + src/pixi/display/DisplayObject.js:63

    @@ -2763,6 +3273,7 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    This is the defined area that will pick up mouse / touch events. It is null by default. Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)

    +
    @@ -2789,11 +3300,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:204 + src/pixi/display/DisplayObject.js:260

    @@ -2804,6 +3315,53 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Indicates if the sprite will have touch and mouse interactivity. It is false by default

    + +
    + + +

    Default: false

    + + + + + +
    + + +
    +

    localTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:135 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object locally

    +
    @@ -2837,7 +3395,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction - src/pixi/display/MovieClip.js:37 + src/pixi/display/MovieClip.js:34

    @@ -2848,9 +3406,12 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Whether or not the movie clip repeats after playing.

    +
    +

    Default: true

    + @@ -2860,7 +3421,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    mask

    - PIXI.Graphics + Graphics @@ -2874,11 +3435,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:222 + src/pixi/display/DisplayObject.js:280

    @@ -2891,6 +3452,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. To remove a mask, set this property to null.

    +
    @@ -2924,7 +3486,7 @@ To remove a mask, set this property to null.

    - src/pixi/display/MovieClip.js:44 + src/pixi/display/MovieClip.js:43

    @@ -2935,6 +3497,7 @@ To remove a mask, set this property to null.

    Function to call when a MovieClip finishes playing

    +
    @@ -2961,11 +3524,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:58 + src/pixi/display/DisplayObject.js:88

    @@ -2976,6 +3539,7 @@ To remove a mask, set this property to null.

    [read-only] The display object container that contains this display object.

    +
    @@ -3002,11 +3566,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:29 + src/pixi/display/DisplayObject.js:31

    @@ -3017,6 +3581,7 @@ To remove a mask, set this property to null.

    The pivot point of the displayObject that it rotates around

    +
    @@ -3050,7 +3615,7 @@ To remove a mask, set this property to null.

    - src/pixi/display/MovieClip.js:51 + src/pixi/display/MovieClip.js:61

    @@ -3060,7 +3625,8 @@ To remove a mask, set this property to null.

    -

    [read only] indicates if the MovieClip is currently playing

    +

    [read-only] Indicates if the MovieClip is currently playing

    +
    @@ -3087,11 +3653,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:15 + src/pixi/display/DisplayObject.js:15

    @@ -3102,6 +3668,49 @@ To remove a mask, set this property to null.

    The coordinate of the object relative to the local coordinates of the parent.

    + +
    + + + + + + +
    + + +
    +

    renderable

    + Boolean + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:80 + +

    + + + + +
    + +
    +

    Can this object be rendered

    +
    @@ -3128,11 +3737,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:36 + src/pixi/display/DisplayObject.js:39

    @@ -3143,6 +3752,7 @@ To remove a mask, set this property to null.

    The rotation of the object in radians.

    +
    @@ -3169,11 +3779,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:22 + src/pixi/display/DisplayObject.js:23

    @@ -3184,6 +3794,7 @@ To remove a mask, set this property to null.

    The scale factor of the object.

    +
    @@ -3210,11 +3821,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:65 + src/pixi/display/DisplayObject.js:97

    @@ -3225,6 +3836,7 @@ To remove a mask, set this property to null.

    [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.

    +
    @@ -3251,11 +3863,11 @@ To remove a mask, set this property to null.

    Inherited from - Sprite: + Sprite: - src/pixi/display/Sprite.js:31 + src/pixi/display/Sprite.js:34

    @@ -3266,6 +3878,7 @@ To remove a mask, set this property to null.

    The texture that the sprite is using

    +
    @@ -3299,7 +3912,7 @@ To remove a mask, set this property to null.

    - src/pixi/display/MovieClip.js:16 + src/pixi/display/MovieClip.js:17

    @@ -3310,6 +3923,7 @@ To remove a mask, set this property to null.

    The array of textures that make up the animation

    +
    @@ -3317,6 +3931,54 @@ To remove a mask, set this property to null.

    +
    + + +
    +

    totalFrames

    + Number + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/display/MovieClip.js:75 + +

    + + + + +
    + +
    +

    [read-only] totalFrames is the total number of frames in the MovieClip. This is the same as number of textures +assigned to the MovieClip.

    + +
    + + +

    Default: 0

    + + + + +
    @@ -3336,11 +3998,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:50 + src/pixi/display/DisplayObject.js:55

    @@ -3351,6 +4013,7 @@ To remove a mask, set this property to null.

    The visibility of the object.

    +
    @@ -3363,7 +4026,7 @@ To remove a mask, set this property to null.

    width

    - #Number + Number @@ -3377,11 +4040,11 @@ To remove a mask, set this property to null.

    Inherited from - Sprite: + Sprite: - src/pixi/display/Sprite.js:46 + src/pixi/display/Sprite.js:86

    @@ -3391,7 +4054,94 @@ To remove a mask, set this property to null.

    -

    The width of the sprite (this is initially set by the texture)

    +

    The width of the sprite, setting this will actually modify the scale to acheive the value set

    + +
    + + + + + + + + + +
    +

    worldAlpha

    + Number + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:106 + +

    + + + + +
    + +
    +

    [read-only] The multiplied alpha of the displayobject

    + +
    + + + + + + +
    + + +
    +

    worldTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:125 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object based on world (parent) factors

    +
    @@ -3417,13 +4167,13 @@ To remove a mask, set this property to null.

    - + - - - - - - + + + + + + diff --git a/docs/classes/PixelateFilter.html b/docs/classes/PixelateFilter.html new file mode 100644 index 0000000..ba0d21d --- /dev/null +++ b/docs/classes/PixelateFilter.html @@ -0,0 +1,315 @@ + + + + + PixelateFilter - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    PixelateFilter Class

    +
    + + + + + + + + + + + Module: PIXI + + + + +
    + + + +
    +

    This filter applies a pixlate effect making display objects appear "blocky"

    + +
    + + + +
    + + +
    +
    +

    Item Index

    + + + + +
    +

    Properties

    + +
      + +
    • + size + + + +
    • + +
    +
    + + + + + +
    + + + + +
    +

    Properties

    + + +
    +

    size

    + Point + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/filters/PixelateFilter.js:50 + +

    + + + + +
    + +
    +

    This a point that describes the size of the blocs. x is the width of the block and y is the the height

    + +
    + + + + + + +
    + + +
    + + + + + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/Point.html b/docs/classes/Point.html index 9cc03ce..21f7d7a 100644 --- a/docs/classes/Point.html +++ b/docs/classes/Point.html @@ -3,11 +3,11 @@ Point - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -150,7 +174,7 @@ @@ -167,6 +191,7 @@

    The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.

    +
    @@ -220,7 +245,7 @@ - src/pixi/core/Point.js:5 + src/pixi/core/Point.js:5

    @@ -250,6 +275,7 @@

    position of the point

    +
    @@ -265,6 +291,7 @@

    position of the point

    +
    @@ -360,7 +387,7 @@ - + Point @@ -387,7 +414,7 @@ - src/pixi/core/Point.js:29 + src/pixi/core/Point.js:30

    @@ -398,7 +425,8 @@
    - +

    Creates a clone of this point

    +
    @@ -410,7 +438,10 @@
    - a copy of the point + Point: + +

    a copy of the point

    +
    @@ -451,7 +482,7 @@ - src/pixi/core/Point.js:14 + src/pixi/core/Point.js:15

    @@ -497,7 +528,7 @@ - src/pixi/core/Point.js:21 + src/pixi/core/Point.js:22

    @@ -535,13 +566,13 @@ - + - - - - - - + + + + + + diff --git a/docs/classes/PolyK.AjaxRequest.html b/docs/classes/PolyK.AjaxRequest.html new file mode 100644 index 0000000..508d79f --- /dev/null +++ b/docs/classes/PolyK.AjaxRequest.html @@ -0,0 +1,601 @@ + + + + + PolyK.AjaxRequest - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    PolyK.AjaxRequest Class

    +
    + + + + + +
    + Defined in: src/pixi/utils/Utils.js:81 +
    + + + + + Module: PIXI + + + + +
    + + + +
    +

    A wrapper for ajax requests to be handled cross browser

    + +
    + + +
    +

    Constructor

    +
    +

    PolyK.AjaxRequest

    + + + () + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/utils/Utils.js:81 + +

    + + + + + +
    + +
    + +
    + + + + + + +
    + +
    + + +
    + + +
    +
    +

    Item Index

    + + +
    +

    Methods

    + + +
    + + + + + + + +
    + + +
    +

    Methods

    + + +
    +

    bind

    + + + () + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/utils/Utils.js:53 + +

    + + + + + +
    + +
    +

    A polyfill for Function.prototype.bind

    + +
    + + + + + + +
    + + +
    +

    cancelAnimationFrame

    + + + () + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/utils/Utils.js:13 + +

    + + + + + +
    + +
    +

    A polyfill for cancelAnimationFrame

    + +
    + + + + + + +
    + + +
    +

    HEXtoRGB

    + + +
    + (
      + +
    • + + hex + +
    • + +
    ) +
    + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/utils/Utils.js:43 + +

    + + + + + +
    + +
    +

    Converts a hex color number to an [R, G, B] array

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + hex + Number + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    requestAnimationFrame

    + + + () + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/utils/Utils.js:8 + +

    + + + + + +
    + +
    +

    A polyfill for requestAnimationFrame

    + +
    + + + + + + +
    + + +
    + + + + + + + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/InteractionData.html b/docs/classes/PolyK.InteractionData.html similarity index 62% rename from docs/classes/InteractionData.html rename to docs/classes/PolyK.InteractionData.html index 56f1b0d..2555156 100644 --- a/docs/classes/InteractionData.html +++ b/docs/classes/PolyK.InteractionData.html @@ -2,12 +2,12 @@ - InteractionData - Pixi.JS - - - - - + PolyK.InteractionData - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,7 +166,7 @@
    -

    InteractionData Class

    +

    PolyK.InteractionData Class

    @@ -150,7 +174,7 @@ @@ -166,14 +190,15 @@
    - +

    Holds all information related to an Interaction event

    +

    Constructor

    -
    -

    InteractionData

    +
    +

    PolyK.InteractionData

    () @@ -204,7 +229,7 @@ - src/pixi/InteractionManager.js:493 + src/pixi/InteractionManager.js:646

    @@ -350,7 +375,7 @@ - src/pixi/InteractionManager.js:524 + src/pixi/InteractionManager.js:682

    @@ -362,6 +387,7 @@

    This will return the local coords of the specified displayObject for this InteractionData

    +
    @@ -380,6 +406,7 @@

    The DisplayObject that you would like the local coords off

    +
    @@ -398,7 +425,8 @@ Point: - A point containing the coords of the InteractionData position relative to the DisplayObject +

    A point containing the coords of the InteractionData position relative to the DisplayObject

    +
    @@ -439,7 +467,7 @@ - src/pixi/InteractionManager.js:499 + src/pixi/InteractionManager.js:654

    @@ -450,6 +478,7 @@

    This point stores the global coords of where the touch/mouse event happened

    +
    @@ -483,7 +512,7 @@ - src/pixi/InteractionManager.js:516 + src/pixi/InteractionManager.js:673

    @@ -494,6 +523,7 @@

    When passed to an event handler, this will be the original DOM Event that was captured

    +
    @@ -527,7 +557,7 @@ - src/pixi/InteractionManager.js:509 + src/pixi/InteractionManager.js:665

    @@ -538,6 +568,7 @@

    The target Sprite that was interacted with

    +
    @@ -563,13 +594,13 @@
    - + - - - - - - + + + + + + diff --git a/docs/classes/PolyK.InteractionManager.html b/docs/classes/PolyK.InteractionManager.html new file mode 100644 index 0000000..d24b54e --- /dev/null +++ b/docs/classes/PolyK.InteractionManager.html @@ -0,0 +1,1616 @@ + + + + + PolyK.InteractionManager - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    PolyK.InteractionManager Class

    +
    + + + + + + + + + + + Module: PIXI + + + + +
    + + + +
    +

    The interaction manager deals with mouse and touch events. Any DisplayObject can be interactive +This manager also supports multitouch.

    + +
    + + +
    +

    Constructor

    +
    +

    PolyK.InteractionManager

    + + +
    + (
      + +
    • + + stage + +
    • + +
    ) +
    + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:5 + +

    + + + + + +
    + +
    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + stage + Stage + + + + +
      +

      The stage to handle interactions

      + +
      + + +
    • + +
    +
    + + + + + +
    + +
    + + +
    + + +
    +
    +

    Item Index

    + + +
    +

    Methods

    + + +
    + + + +
    +

    Properties

    + + +
    + + + + + +
    + + +
    +

    Methods

    + + +
    +

    collectInteractiveSprite

    + + +
    + (
      + +
    • + + displayObject + +
    • + +
    • + + iParent + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:70 + +

    + + + + + +
    + +
    +

    Collects an interactive sprite recursively to have their interactions managed

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + displayObject + DisplayObject + + + + +
      +

      the displayObject to collect

      + +
      + + +
    • + +
    • + + iParent + DisplayObject + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    hitTest

    + + +
    + (
      + +
    • + + item + +
    • + +
    • + + interactionData + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:422 + +

    + + + + + +
    + +
    +

    Tests if the current mouse coords hit a sprite

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + item + DisplayObject + + + + +
      +

      The displayObject to test for a hit

      + +
      + + +
    • + +
    • + + interactionData + InteractionData + + + + +
      +

      The interactiondata object to update in the case of a hit

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    onMouseDown

    + + +
    + (
      + +
    • + + event + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:305 + +

    + + + + + +
    + +
    +

    Is called when the mouse button is pressed down on the renderer element

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + event + Event + + + + +
      +

      The DOM event of a mouse button being pressed down

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    onMouseMove

    + + +
    + (
      + +
    • + + event + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:273 + +

    + + + + + +
    + +
    +

    Is called when the mouse moves accross the renderer element

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + event + Event + + + + +
      +

      The DOM event of the mouse moving

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    onMouseUp

    + + +
    + (
      + +
    • + + event + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:370 + +

    + + + + + +
    + +
    +

    Is called when the mouse button is released on the renderer element

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + event + Event + + + + +
      +

      The DOM event of a mouse button being released

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    onTouchEnd

    + + +
    + (
      + +
    • + + event + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:575 + +

    + + + + + +
    + +
    +

    Is called when a touch is ended on the renderer element

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + event + Event + + + + +
      +

      The DOM event of a touch ending on the renderer view

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    onTouchMove

    + + +
    + (
      + +
    • + + event + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:495 + +

    + + + + + +
    + +
    +

    Is called when a touch is moved accross the renderer element

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + event + Event + + + + +
      +

      The DOM event of a touch moving accross the renderer view

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    onTouchStart

    + + +
    + (
      + +
    • + + event + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:526 + +

    + + + + + +
    + +
    +

    Is called when a touch is started on the renderer element

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + event + Event + + + + +
      +

      The DOM event of a touch starting on the renderer view

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    setTarget

    + + +
    + (
      + +
    • + + target + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:114 + +

    + + + + + +
    + +
    +

    Sets the target for event delegation

    + +
    + + +
    +

    Parameters:

    + + +
    + + + + + +
    + + +
    +

    setTargetDomElement

    + + +
    + (
      + +
    • + + domElement + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:135 + +

    + + + + + +
    + +
    +

    Sets the dom element which will receive mouse/touch events. This is useful for when you have other DOM +elements ontop of the renderers Canvas element. With this you'll be able to delegate another dom element +to receive those events

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + domElement + DOMElement + + + + +
      +

      the dom element which will receive mouse and touch events

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    update

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:185 + +

    + + + + + +
    + +
    +

    updates the state of interactive objects

    + +
    + + + + + + +
    + + +
    + + + +
    +

    Properties

    + + +
    +

    mouse

    + InteractionData + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:23 + +

    + + + + +
    + +
    +

    the mouse data

    + +
    + + + + + + +
    + + +
    +

    stage

    + Stage + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:15 + +

    + + + + +
    + +
    +

    a refference to the stage

    + +
    + + + + + + +
    + + +
    +

    touchs

    + Object + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/InteractionManager.js:31 + +

    + + + + +
    + +
    +

    an object that stores current touches (InteractionData) by id reference

    + +
    + + + + + + +
    + + +
    + + + + + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/PolyK._PointInTriangle.html b/docs/classes/PolyK._PointInTriangle.html new file mode 100644 index 0000000..3ea0a55 --- /dev/null +++ b/docs/classes/PolyK._PointInTriangle.html @@ -0,0 +1,325 @@ + + + + + PolyK._PointInTriangle - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    PolyK._PointInTriangle Class

    +
    + + + + + +
    + Defined in: src/pixi/utils/Polyk.js:109 +
    + + + + + Module: PIXI + + + + +
    + + + +
    +

    Checks if a point is within a triangle

    + +
    + + + +
    + + +
    +
    +

    Item Index

    + + +
    +

    Methods

    + + +
    + + + + + + + +
    + + +
    +

    Methods

    + + +
    +

    Triangulate

    + + + () + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/utils/Polyk.js:36 + +

    + + + + + +
    + +
    +

    Triangulates shapes for webGL graphic fills

    + +
    + + + + + + +
    + + +
    + + + + + + + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/PolyK._convex.html b/docs/classes/PolyK._convex.html new file mode 100644 index 0000000..4a91a69 --- /dev/null +++ b/docs/classes/PolyK._convex.html @@ -0,0 +1,247 @@ + + + + + PolyK._convex - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    PolyK._convex Class

    +
    + + + + + +
    + Defined in: src/pixi/utils/Polyk.js:139 +
    + + + + + Module: PIXI + + + + +
    + + + +
    +

    Checks if a shape is convex

    + +
    + + + +
    + + +
    +
    +

    Item Index

    + + + + + + + + +
    + + + + + + + + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/Polygon.html b/docs/classes/Polygon.html index 587eb48..6dcfee8 100644 --- a/docs/classes/Polygon.html +++ b/docs/classes/Polygon.html @@ -3,11 +3,11 @@ Polygon - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
  • points - Array | Array + Array | Array | Point... | Number... + multiple +
    -

    This cna be an array of Points or a flat array of numbers - that will be interpreted as [x,y, x,y, ...]

    +

    This can be an array of Points that form the polygon, + a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arguments passed can be + all the points of the polygon e.g. new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...), or the + arguments passed can be flat x,y values e.g. new PIXI.Polygon(x,y, x,y, x,y, ...) where x and y are + Numbers.

    +
    @@ -323,7 +353,7 @@ - + Polygon @@ -350,7 +380,7 @@ - src/pixi/core/Polygon.js:28 + src/pixi/core/Polygon.js:35

    @@ -361,7 +391,8 @@
    - +

    Creates a clone of this polygon

    +
    @@ -373,7 +404,10 @@
    - a copy of the polygon + Polygon: + +

    a copy of the polygon

    +
    @@ -408,7 +442,7 @@ - + Boolean @@ -435,7 +469,7 @@ - src/pixi/core/Polygon.js:42 + src/pixi/core/Polygon.js:51

    @@ -446,7 +480,8 @@
    - +

    Checks if the x, and y coords passed to this function are contained within this polygon

    +
    @@ -465,6 +500,7 @@

    The X coord of the point to test

    +
    @@ -480,6 +516,7 @@

    The Y coord of the point to test

    +
    @@ -496,7 +533,10 @@
    - if the x/y coords are within this polygon + Boolean: + +

    if the x/y coords are within this polygon

    +
    @@ -523,13 +563,13 @@ - + - - - - - - + + + + + + diff --git a/docs/classes/Rectangle.html b/docs/classes/Rectangle.html index bbf3d67..142297c 100644 --- a/docs/classes/Rectangle.html +++ b/docs/classes/Rectangle.html @@ -3,11 +3,11 @@ Rectangle - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -150,7 +174,7 @@ @@ -167,6 +191,7 @@

    the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height.

    +
    @@ -232,7 +257,7 @@ - src/pixi/core/Rectangle.js:5 + src/pixi/core/Rectangle.js:5

    @@ -261,7 +286,8 @@
    -

    position of the rectangle

    +

    The X coord of the upper-left corner of the rectangle

    +
    @@ -276,7 +302,8 @@
    -

    position of the rectangle

    +

    The Y coord of the upper-left corner of the rectangle

    +
    @@ -291,7 +318,8 @@
    -

    of the rectangle

    +

    The overall width of this rectangle

    +
    @@ -306,7 +334,8 @@
    -

    of the rectangle

    +

    The overall height of this rectangle

    +
    @@ -423,7 +452,7 @@ - + Rectangle @@ -450,7 +479,7 @@ - src/pixi/core/Rectangle.js:45 + src/pixi/core/Rectangle.js:46

    @@ -461,7 +490,8 @@
    - +

    Creates a clone of this Rectangle

    +
    @@ -473,7 +503,10 @@
    - a copy of the rectangle + Rectangle: + +

    a copy of the rectangle

    +
    @@ -508,7 +541,7 @@ - + Boolean @@ -535,7 +568,7 @@ - src/pixi/core/Rectangle.js:54 + src/pixi/core/Rectangle.js:57

    @@ -546,7 +579,8 @@
    - +

    Checks if the x, and y coords passed to this function are contained within this Rectangle

    +
    @@ -565,6 +599,7 @@

    The X coord of the point to test

    +
    @@ -580,6 +615,7 @@

    The Y coord of the point to test

    +
    @@ -596,7 +632,10 @@
    - if the x/y coords are within this polygon + Boolean: + +

    if the x/y coords are within this Rectangle

    +
    @@ -637,7 +676,7 @@ - src/pixi/core/Rectangle.js:37 + src/pixi/core/Rectangle.js:38

    @@ -683,7 +722,7 @@ - src/pixi/core/Rectangle.js:30 + src/pixi/core/Rectangle.js:31

    @@ -729,7 +768,7 @@ - src/pixi/core/Rectangle.js:16 + src/pixi/core/Rectangle.js:17

    @@ -775,7 +814,7 @@ - src/pixi/core/Rectangle.js:23 + src/pixi/core/Rectangle.js:24

    @@ -813,13 +852,13 @@ - + - - - - - - + + + + + + diff --git a/docs/classes/RenderTexture.html b/docs/classes/RenderTexture.html index e274141..3e617dc 100644 --- a/docs/classes/RenderTexture.html +++ b/docs/classes/RenderTexture.html @@ -3,11 +3,11 @@ RenderTexture - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -154,7 +178,7 @@ @@ -171,27 +195,21 @@

    A RenderTexture is a special texture that allows any pixi displayObject to be rendered to it.

    -

    Hint: All DisplayObjects (exmpl. Sprites) that renders on RenderTexture should be preloaded. Otherwise black rectangles will be drawn instead.

    -

    RenderTexture takes snapshot of DisplayObject passed to render method. If DisplayObject is passed to render method, position and rotation of it will be ignored. For example:

    -
    var renderTexture = new PIXI.RenderTexture(800, 600);
    -var sprite = PIXI.Sprite.fromImage("spinObj_01.png");
    +var sprite = PIXI.Sprite.fromImage("spinObj_01.png");
     sprite.position.x = 800/2;
     sprite.position.y = 600/2;
     sprite.anchor.x = 0.5;
     sprite.anchor.y = 0.5;
    -renderTexture.render(sprite);
    -
    - +renderTexture.render(sprite);

    Sprite in this case will be rendered to 0,0 position. To render this sprite at center DisplayObjectContainer should be used:

    -
    var doc = new PIXI.DisplayObjectContainer();
     doc.addChild(sprite);
    -renderTexture.render(doc);  // Renders to center of renderTexture
    -
    +renderTexture.render(doc); // Renders to center of renderTexture +
    @@ -245,7 +263,7 @@ renderTexture.render(doc); // Renders to center of renderTexture - src/pixi/textures/RenderTexture.js:5 + src/pixi/textures/RenderTexture.js:5

    @@ -274,7 +292,8 @@ renderTexture.render(doc); // Renders to center of renderTexture
    - +

    The width of the render texture

    +
    @@ -289,7 +308,8 @@ renderTexture.render(doc); // Renders to center of renderTexture
    - +

    The height of the render texture

    +
    @@ -332,14 +352,42 @@ renderTexture.render(doc); // Renders to center of renderTexture @@ -390,8 +445,8 @@ renderTexture.render(doc); // Renders to center of renderTexture

    Methods

    -
    -

    fromFrame

    +
    +

    destroy

    @@ -399,7 +454,7 @@ renderTexture.render(doc); // Renders to center of renderTexture
  • - frameId + destroyBase
  • @@ -408,10 +463,6 @@ renderTexture.render(doc); // Renders to center of renderTexture - - - - @@ -429,11 +480,11 @@ renderTexture.render(doc); // Renders to center of renderTexture

    Inherited from - Texture: + Texture: - src/pixi/textures/Texture.js:127 + src/pixi/textures/Texture.js:93

    @@ -444,8 +495,8 @@ renderTexture.render(doc); // Renders to center of renderTexture
    -

    Helper function that returns a texture based on a frame id - If the frame id is not in the texture cache an error will be thrown

    +

    Destroys this texture

    +
    @@ -456,14 +507,15 @@ renderTexture.render(doc); // Renders to center of renderTexture
  • - frameId - String + destroyBase + Boolean
    -

    The frame id of the texture

    +

    Whether to destroy the base texture as well

    +
    @@ -474,24 +526,214 @@ renderTexture.render(doc); // Renders to center of renderTexture -
    -

    Returns:

    -
    + +
    + - - Texture +
    +

    initCanvas

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + -
    -
    +

    + + Defined in + + + + + src/pixi/textures/RenderTexture.js:125 + +

    + + + + + +
    + +
    +

    Initializes the canvas data for this texture

    + +
    + + + -
    -

    render

    +
    +

    initWebGL

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/textures/RenderTexture.js:57 + +

    + + + + + +
    + +
    +

    Initializes the webgl data for this texture

    + +
    + + + + + + +
    + + +
    +

    onBaseTextureLoaded

    + + +
    + (
      + +
    • + + event + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + +

    Inherited from + Texture: + + + + src/pixi/textures/Texture.js:73 + +

    + + + + + +
    + +
    +

    Called when the base texture is loaded

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + event + Object + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    renderCanvas

    @@ -518,6 +760,8 @@ renderTexture.render(doc); // Renders to center of renderTexture + private + @@ -538,7 +782,7 @@ renderTexture.render(doc); // Renders to center of renderTexture - src/pixi/textures/RenderTexture.js:112 + src/pixi/textures/RenderTexture.js:214

    @@ -550,6 +794,7 @@ renderTexture.render(doc); // Renders to center of renderTexture

    This function will draw the display object to the texture.

    +
    @@ -567,7 +812,8 @@ renderTexture.render(doc); // Renders to center of renderTexture
    - +

    The display object to render this texture on

    +
    @@ -583,6 +829,120 @@ renderTexture.render(doc); // Renders to center of renderTexture

    If true the texture will be cleared before the displayObject is drawn

    + +
    + + +
  • + + + + + + + + + + + +
    +

    renderWebGL

    + + +
    + () +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/textures/RenderTexture.js:141 + +

    + + + + + +
    + +
    +

    This function will draw the display object to the texture.

    + +
    + + +
    +

    Parameters:

    + +
    - + - - - - - - + + + + + + diff --git a/docs/classes/SepiaFilter.html b/docs/classes/SepiaFilter.html new file mode 100644 index 0000000..7911051 --- /dev/null +++ b/docs/classes/SepiaFilter.html @@ -0,0 +1,315 @@ + + + + + SepiaFilter - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    SepiaFilter Class

    +
    + + + + + + + + + + + Module: PIXI + + + + +
    + + + +
    +

    This applies a sepia effect to your displayObjects.

    + +
    + + + +
    + + +
    +
    +

    Item Index

    + + + + +
    +

    Properties

    + +
      + +
    • + sepia + + + +
    • + +
    +
    + + + + + +
    + + + + +
    +

    Properties

    + + +
    +

    sepia

    + Unknown + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/filters/SepiaFilter.js:44 + +

    + + + + +
    + +
    +

    The strength of the sepia. 1 will apply the full sepia effect, 0 will make the object its normal color

    + +
    + + + + + + +
    + + +
    + + + + + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/Spine.html b/docs/classes/Spine.html index 07fba75..2152e64 100644 --- a/docs/classes/Spine.html +++ b/docs/classes/Spine.html @@ -3,11 +3,11 @@ Spine - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -145,6 +169,15 @@

    Spine Class

    +
    + Uses + +
    +
    @@ -154,7 +187,7 @@ @@ -171,11 +204,12 @@

    The Spine loader is used to load in JSON spine data -To generate the data you need to use http://esotericsoftware.com/ and export the "JSON" format -Due to a clash of names You will need to change the extension of the spine file from *.json to *.anim for it to load -See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source -You will need to generate a sprite sheet to accompany the spine data -When loaded this class will dispatch a "loaded" event

    +To generate the data you need to use http://esotericsoftware.com/ and export the "JSON" format +Due to a clash of names You will need to change the extension of the spine file from .json to .anim for it to load +See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source +You will need to generate a sprite sheet to accompany the spine data +When loaded this class will dispatch a "loaded" event

    +
    @@ -223,7 +257,7 @@ When loaded this class will dispatch a "loaded" event

    - src/pixi/loaders/SpineLoader.js:10 + src/pixi/loaders/SpineLoader.js:10

    @@ -252,7 +286,8 @@ When loaded this class will dispatch a "loaded" event

    -

    the url of the spine anim file to be used

    +

    The url of the spine anim file to be used

    +
    @@ -320,6 +355,13 @@ When loaded this class will dispatch a "loaded" event

    + + +
  • + load + + +
  • @@ -355,6 +397,20 @@ When loaded this class will dispatch a "loaded" event

    +
  • + +
  • + onJSONLoaded + + + +
  • + +
  • + onLoaded + + +
  • @@ -364,14 +420,16 @@ When loaded this class will dispatch a "loaded" event

  • -
  • +
  • setInteractive + deprecated +
  • -
  • +
  • swapChildren @@ -416,6 +474,13 @@ When loaded this class will dispatch a "loaded" event

      +
    • + _interactive + + + +
    • +
    • alpha @@ -435,6 +500,34 @@ When loaded this class will dispatch a "loaded" event

      +
    • + +
    • + color + + + +
    • + +
    • + crossorigin + + + +
    • + +
    • + dynamic + + + +
    • + +
    • + filters + + +
    • @@ -449,6 +542,20 @@ When loaded this class will dispatch a "loaded" event

      +
    • + +
    • + loaded + + + +
    • + +
    • + localTransform + + +
    • @@ -477,6 +584,13 @@ When loaded this class will dispatch a "loaded" event

      +
    • + +
    • + renderable + + +
    • @@ -498,6 +612,13 @@ When loaded this class will dispatch a "loaded" event

      +
    • + +
    • + url + + +
    • @@ -505,6 +626,20 @@ When loaded this class will dispatch a "loaded" event

      +
    • + +
    • + worldAlpha + + + +
    • + +
    • + worldTransform + + +
    @@ -530,7 +665,7 @@ When loaded this class will dispatch a "loaded" event

  • - DisplayObject + child
  • @@ -556,11 +691,11 @@ When loaded this class will dispatch a "loaded" event

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:42 + src/pixi/display/DisplayObjectContainer.js:32

    @@ -572,6 +707,7 @@ When loaded this class will dispatch a "loaded" event

    Adds a child to the container.

    +
    @@ -582,14 +718,15 @@ When loaded this class will dispatch a "loaded" event

  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to add to the container

    +
    @@ -614,7 +751,7 @@ When loaded this class will dispatch a "loaded" event

  • - DisplayObject + child
  • @@ -646,11 +783,11 @@ When loaded this class will dispatch a "loaded" event

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:139 + src/pixi/display/DisplayObjectContainer.js:120

    @@ -662,6 +799,7 @@ When loaded this class will dispatch a "loaded" event

    Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown

    +
    @@ -672,14 +810,15 @@ When loaded this class will dispatch a "loaded" event

  • - DisplayObject + child DisplayObject
    - +

    The child to add

    +
    @@ -694,7 +833,8 @@ When loaded this class will dispatch a "loaded" event

    - +

    The index to place the child in

    +
    @@ -745,11 +885,11 @@ When loaded this class will dispatch a "loaded" event

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:109 + src/pixi/display/DisplayObject.js:174

    @@ -761,6 +901,7 @@ When loaded this class will dispatch a "loaded" event

    A callback that is used when the users clicks on the displayObject with their mouse

    +
    @@ -772,7 +913,7 @@ When loaded this class will dispatch a "loaded" event

  • interactionData - InteractionData + InteractionData @@ -829,11 +970,11 @@ When loaded this class will dispatch a "loaded" event

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:274 + src/pixi/display/DisplayObjectContainer.js:256

    @@ -845,6 +986,7 @@ When loaded this class will dispatch a "loaded" event

    Returns the Child at the specified index

    +
    @@ -862,7 +1004,8 @@ When loaded this class will dispatch a "loaded" event

    - +

    The index to get the child from

    +
    @@ -875,6 +1018,61 @@ When loaded this class will dispatch a "loaded" event

    +
  • + + +
    +

    load

    + + + () + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/SpineLoader.js:56 + +

    + + + + + +
    + +
    +

    Loads the JSON data

    + +
    + + + + + +
    @@ -913,11 +1111,11 @@ When loaded this class will dispatch a "loaded" event

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:115 + src/pixi/display/DisplayObject.js:180

    @@ -929,6 +1127,7 @@ When loaded this class will dispatch a "loaded" event

    A callback that is used when the user clicks the mouse down over the sprite

    +
    @@ -940,7 +1139,7 @@ When loaded this class will dispatch a "loaded" event

  • interactionData - InteractionData + InteractionData @@ -997,11 +1196,11 @@ When loaded this class will dispatch a "loaded" event

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:141 + src/pixi/display/DisplayObject.js:206

    @@ -1013,6 +1212,7 @@ When loaded this class will dispatch a "loaded" event

    A callback that is used when the users mouse leaves the displayObject

    +
    @@ -1024,7 +1224,7 @@ When loaded this class will dispatch a "loaded" event

  • interactionData - InteractionData + InteractionData @@ -1081,11 +1281,11 @@ When loaded this class will dispatch a "loaded" event

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:135 + src/pixi/display/DisplayObject.js:200

    @@ -1097,6 +1297,7 @@ When loaded this class will dispatch a "loaded" event

    A callback that is used when the users mouse rolls over the displayObject

    +
    @@ -1108,7 +1309,7 @@ When loaded this class will dispatch a "loaded" event

  • interactionData - InteractionData + InteractionData @@ -1165,11 +1366,11 @@ When loaded this class will dispatch a "loaded" event

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:121 + src/pixi/display/DisplayObject.js:186

    @@ -1182,6 +1383,7 @@ When loaded this class will dispatch a "loaded" event

    A callback that is used when the user releases the mouse that was over the displayObject for this callback to be fired the mouse must have been pressed down over the displayObject

    +
    @@ -1193,7 +1395,7 @@ for this callback to be fired the mouse must have been pressed down over the dis
  • interactionData - InteractionData + InteractionData @@ -1250,11 +1452,11 @@ for this callback to be fired the mouse must have been pressed down over the dis

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:128 + src/pixi/display/DisplayObject.js:193

    @@ -1267,6 +1469,7 @@ for this callback to be fired the mouse must have been pressed down over the dis

    A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject for this callback to be fired, The touch must have started over the displayObject

    +
    @@ -1278,7 +1481,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • interactionData - InteractionData + InteractionData @@ -1297,6 +1500,120 @@ for this callback to be fired, The touch must have started over the displayObjec +
  • + + +
    +

    onJSONLoaded

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/SpineLoader.js:72 + +

    + + + + + +
    + +
    +

    Invoke when JSON file is loaded

    + +
    + + + + + + +
    + + +
    +

    onLoaded

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/SpineLoader.js:87 + +

    + + + + + +
    + +
    +

    Invoke when JSON file is loaded

    + +
    + + + + + +
    @@ -1309,7 +1626,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • - DisplayObject + child
  • @@ -1335,11 +1652,11 @@ for this callback to be fired, The touch must have started over the displayObjec

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:291 + src/pixi/display/DisplayObjectContainer.js:274

    @@ -1351,6 +1668,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    Removes a child from the container.

    +
    @@ -1361,14 +1679,15 @@ for this callback to be fired, The touch must have started over the displayObjec
  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to remove

    +
    @@ -1384,7 +1703,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • -
    +

    setInteractive

    @@ -1404,6 +1723,8 @@ for this callback to be fired, The touch must have started over the displayObjec + deprecated + @@ -1419,16 +1740,18 @@ for this callback to be fired, The touch must have started over the displayObjec

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:193 + src/pixi/display/DisplayObject.js:247

    +

    Deprecated: Simply set the `interactive` property directly

    +
    @@ -1436,6 +1759,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default Instead of using this function you can now simply set the interactive property to true or false

    +
    @@ -1469,7 +1793,7 @@ Instead of using this function you can now simply set the interactive property t
    -
    +

    swapChildren

    @@ -1478,13 +1802,13 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child
  • - DisplayObject2 + child2
  • @@ -1497,6 +1821,8 @@ Instead of using this function you can now simply set the interactive property t + private + @@ -1510,11 +1836,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:227 + src/pixi/display/DisplayObjectContainer.js:207

    @@ -1525,7 +1851,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    Swaps the depth of 2 displayObjects

    +

    [NYI] Swaps the depth of 2 displayObjects

    +
    @@ -1536,7 +1863,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child DisplayObject @@ -1551,7 +1878,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject2 + child2 DisplayObject @@ -1609,11 +1936,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:152 + src/pixi/display/DisplayObject.js:217

    @@ -1626,6 +1953,7 @@ Instead of using this function you can now simply set the interactive property t

    A callback that is used when the users taps on the sprite with their finger basically a touch version of click

    +
    @@ -1637,7 +1965,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -1694,11 +2022,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:165 + src/pixi/display/DisplayObject.js:230

    @@ -1710,6 +2038,7 @@ basically a touch version of click

    A callback that is used when the user releases a touch over the displayObject

    +
    @@ -1721,7 +2050,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -1778,11 +2107,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:171 + src/pixi/display/DisplayObject.js:236

    @@ -1795,6 +2124,7 @@ basically a touch version of click

    A callback that is used when the user releases the touch that was over the displayObject for this callback to be fired, The touch must have started over the sprite

    +
    @@ -1806,7 +2136,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -1863,11 +2193,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:159 + src/pixi/display/DisplayObject.js:224

    @@ -1878,7 +2208,8 @@ for this callback to be fired, The touch must have started over the sprite

  • -

    A callback that is used when the user touch's over the displayObject

    +

    A callback that is used when the user touch's over the displayObject

    +
    @@ -1890,7 +2221,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -1920,6 +2251,50 @@ for this callback to be fired, The touch must have started over the sprite

    Properties

    +
    +

    _interactive

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:115 + +

    + + + + +
    + +
    +

    [read-only] Whether or not the object is interactive, do not toggle directly! use the interactive property

    + +
    + + + + + + +
    + +

    alpha

    Number @@ -1936,11 +2311,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:43 + src/pixi/display/DisplayObject.js:47

    @@ -1951,6 +2326,7 @@ for this callback to be fired, The touch must have started over the sprite

    The opacity of the object.

    +
    @@ -1977,11 +2353,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:98 + src/pixi/display/DisplayObject.js:72

    @@ -1992,6 +2368,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is used to indicate if the displayObject should display a mouse hand cursor on rollover

    +
    @@ -2004,7 +2381,7 @@ for this callback to be fired, The touch must have started over the sprite

    children

    - Array + Array @@ -2018,11 +2395,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:16 + src/pixi/display/DisplayObjectContainer.js:18

    @@ -2033,6 +2410,184 @@ for this callback to be fired, The touch must have started over the sprite

    [read-only] The of children of this container.

    + +
    + + + + + + +
    + + +
    +

    color

    + Array<> + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:145 + +

    + + + + +
    + +
    +

    [NYI] Unkown

    + +
    + + + + + + +
    + + +
    +

    crossorigin

    + Boolean + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/SpineLoader.js:36 + +

    + + + + +
    + +
    +

    Whether the requests should be treated as cross origin

    + +
    + + + + + + +
    + + +
    +

    dynamic

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:154 + +

    + + + + +
    + +
    +

    [NYI] Holds whether or not this object is dynamic, for rendering optimization

    + +
    + + + + + + +
    + + +
    +

    filters

    + Array An array of filters + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:318 + +

    + + + + +
    + +
    +

    Sets the filters for the displayObject. +* IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. +To remove filters simply set this property to 'null'

    +
    @@ -2045,7 +2600,7 @@ for this callback to be fired, The touch must have started over the sprite

    hitArea

    - Rectangle + Rectangle | Circle | Ellipse | Polygon @@ -2059,11 +2614,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:72 + src/pixi/display/DisplayObject.js:63

    @@ -2075,6 +2630,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is the defined area that will pick up mouse / touch events. It is null by default. Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)

    +
    @@ -2101,11 +2657,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:204 + src/pixi/display/DisplayObject.js:260

    @@ -2116,6 +2672,98 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Indicates if the sprite will have touch and mouse interactivity. It is false by default

    + +
    + + +

    Default: false

    + + + + + +
    + + +
    +

    loaded

    + Boolean + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/SpineLoader.js:44 + +

    + + + + +
    + +
    +

    [read-only] Whether the data has loaded yet

    + +
    + + + + + + +
    + + +
    +

    localTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:135 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object locally

    +
    @@ -2128,7 +2776,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    mask

    - PIXI.Graphics + Graphics @@ -2142,11 +2790,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:222 + src/pixi/display/DisplayObject.js:280

    @@ -2159,6 +2807,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. To remove a mask, set this property to null.

    +
    @@ -2185,11 +2834,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:58 + src/pixi/display/DisplayObject.js:88

    @@ -2200,6 +2849,7 @@ To remove a mask, set this property to null.

    [read-only] The display object container that contains this display object.

    +
    @@ -2226,11 +2876,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:29 + src/pixi/display/DisplayObject.js:31

    @@ -2241,6 +2891,7 @@ To remove a mask, set this property to null.

    The pivot point of the displayObject that it rotates around

    +
    @@ -2267,11 +2918,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:15 + src/pixi/display/DisplayObject.js:15

    @@ -2282,6 +2933,49 @@ To remove a mask, set this property to null.

    The coordinate of the object relative to the local coordinates of the parent.

    + +
    + + + + + + +
    + + +
    +

    renderable

    + Boolean + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:80 + +

    + + + + +
    + +
    +

    Can this object be rendered

    +
    @@ -2308,11 +3002,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:36 + src/pixi/display/DisplayObject.js:39

    @@ -2323,6 +3017,7 @@ To remove a mask, set this property to null.

    The rotation of the object in radians.

    +
    @@ -2349,11 +3044,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:22 + src/pixi/display/DisplayObject.js:23

    @@ -2364,6 +3059,7 @@ To remove a mask, set this property to null.

    The scale factor of the object.

    +
    @@ -2390,11 +3086,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:65 + src/pixi/display/DisplayObject.js:97

    @@ -2405,6 +3101,52 @@ To remove a mask, set this property to null.

    [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.

    + +
    + + + + + + +
    + + +
    +

    url

    + String + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/SpineLoader.js:28 + +

    + + + + +
    + +
    +

    The url of the bitmap font data

    +
    @@ -2431,11 +3173,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:50 + src/pixi/display/DisplayObject.js:55

    @@ -2446,6 +3188,93 @@ To remove a mask, set this property to null.

    The visibility of the object.

    + +
    + + + + + + +
    + + +
    +

    worldAlpha

    + Number + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:106 + +

    + + + + +
    + +
    +

    [read-only] The multiplied alpha of the displayobject

    + +
    + + + + + + +
    + + +
    +

    worldTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:125 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object based on world (parent) factors

    +
    @@ -2471,13 +3300,13 @@ To remove a mask, set this property to null.

    - + - - - - - - + + + + + + diff --git a/docs/classes/Sprite.html b/docs/classes/Sprite.html index aea92ff..2916b16 100644 --- a/docs/classes/Sprite.html +++ b/docs/classes/Sprite.html @@ -3,11 +3,11 @@ Sprite - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
  • + +
  • + onTextureUpdate + + +
  • @@ -377,11 +410,13 @@
  • -
  • +
  • setInteractive + deprecated +
  • @@ -391,7 +426,7 @@
  • -
  • +
  • swapChildren @@ -436,6 +471,27 @@ @@ -585,7 +690,7 @@
  • - DisplayObject + child
  • @@ -611,11 +716,11 @@

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:42 + src/pixi/display/DisplayObjectContainer.js:32

    @@ -627,6 +732,7 @@

    Adds a child to the container.

    +
    @@ -637,14 +743,15 @@
  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to add to the container

    +
    @@ -669,7 +776,7 @@
  • - DisplayObject + child
  • @@ -701,11 +808,11 @@

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:139 + src/pixi/display/DisplayObjectContainer.js:120

    @@ -717,6 +824,7 @@

    Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown

    +
    @@ -727,14 +835,15 @@
  • - DisplayObject + child DisplayObject
    - +

    The child to add

    +
    @@ -749,7 +858,8 @@
    - +

    The index to place the child in

    +
    @@ -800,11 +910,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:109 + src/pixi/display/DisplayObject.js:174

    @@ -816,6 +926,7 @@

    A callback that is used when the users clicks on the displayObject with their mouse

    +
    @@ -827,7 +938,7 @@
  • interactionData - InteractionData + InteractionData @@ -897,7 +1008,7 @@ - src/pixi/display/Sprite.js:135 + src/pixi/display/Sprite.js:165

    @@ -910,6 +1021,7 @@

    Helper function that creates a sprite that will contain a texture from the TextureCache based on the frameId The frame ids are created when a Texture packer file has been loaded

    +
    @@ -928,6 +1040,7 @@

    The frame Id of the texture in the cache

    +
    @@ -946,7 +1059,8 @@ Sprite: - A new Sprite using a texture from the texture cache matching the frameId +

    A new Sprite using a texture from the texture cache matching the frameId

    +
  • @@ -965,7 +1079,7 @@
  • - The + imageId
  • @@ -1004,7 +1118,7 @@ - src/pixi/display/Sprite.js:151 + src/pixi/display/Sprite.js:182

    @@ -1017,6 +1131,7 @@

    Helper function that creates a sprite that will contain a texture based on an image url If the image is not in the texture cache it will be loaded

    +
    @@ -1027,14 +1142,15 @@
  • - The - Object + imageId + String
    -

    image url of the texture

    +

    The image url of the texture

    +
    @@ -1053,7 +1169,8 @@ Sprite: - A new Sprite using a texture from the texture cache matching the image id +

    A new Sprite using a texture from the texture cache matching the image id

    + @@ -1098,11 +1215,11 @@

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:274 + src/pixi/display/DisplayObjectContainer.js:256

    @@ -1114,6 +1231,7 @@

    Returns the Child at the specified index

    +
    @@ -1131,7 +1249,8 @@
    - +

    The index to get the child from

    +
    @@ -1182,11 +1301,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:115 + src/pixi/display/DisplayObject.js:180

    @@ -1198,6 +1317,7 @@

    A callback that is used when the user clicks the mouse down over the sprite

    +
    @@ -1209,7 +1329,7 @@
  • interactionData - InteractionData + InteractionData @@ -1266,11 +1386,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:141 + src/pixi/display/DisplayObject.js:206

    @@ -1282,6 +1402,7 @@

    A callback that is used when the users mouse leaves the displayObject

    +
    @@ -1293,7 +1414,7 @@
  • interactionData - InteractionData + InteractionData @@ -1350,11 +1471,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:135 + src/pixi/display/DisplayObject.js:200

    @@ -1366,6 +1487,7 @@

    A callback that is used when the users mouse rolls over the displayObject

    +
    @@ -1377,7 +1499,7 @@
  • interactionData - InteractionData + InteractionData @@ -1434,11 +1556,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:121 + src/pixi/display/DisplayObject.js:186

    @@ -1451,6 +1573,7 @@

    A callback that is used when the user releases the mouse that was over the displayObject for this callback to be fired the mouse must have been pressed down over the displayObject

    +
    @@ -1462,7 +1585,7 @@ for this callback to be fired the mouse must have been pressed down over the dis
  • interactionData - InteractionData + InteractionData @@ -1519,11 +1642,11 @@ for this callback to be fired the mouse must have been pressed down over the dis

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:128 + src/pixi/display/DisplayObject.js:193

    @@ -1536,6 +1659,7 @@ for this callback to be fired the mouse must have been pressed down over the dis

    A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject for this callback to be fired, The touch must have started over the displayObject

    +
    @@ -1547,7 +1671,97 @@ for this callback to be fired, The touch must have started over the displayObjec
  • interactionData - InteractionData + InteractionData + + + + +
    + +
    + + +
  • + + + + + + + + + + + +
    +

    onTextureUpdate

    + + +
    + () +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/display/Sprite.js:145 + +

    + + + + + +
    + +
    +

    When the texture is updated, this event will fire to update the scale and frame

    + +
    + + +
    +

    Parameters:

    + +
    -
    +

    setInteractive

    @@ -1673,6 +1889,8 @@ for this callback to be fired, The touch must have started over the displayObjec + deprecated + @@ -1688,16 +1906,18 @@ for this callback to be fired, The touch must have started over the displayObjec

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:193 + src/pixi/display/DisplayObject.js:247

    +

    Deprecated: Simply set the `interactive` property directly

    +
    @@ -1705,6 +1925,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default Instead of using this function you can now simply set the interactive property to true or false

    +
    @@ -1780,7 +2001,7 @@ Instead of using this function you can now simply set the interactive property t - src/pixi/display/Sprite.js:103 + src/pixi/display/Sprite.js:118

    @@ -1791,7 +2012,8 @@ Instead of using this function you can now simply set the interactive property t
    - +

    Sets the texture of the sprite

    +
    @@ -1810,6 +2032,7 @@ Instead of using this function you can now simply set the interactive property t

    The PIXI texture that is displayed by the sprite

    +
    @@ -1825,7 +2048,7 @@ Instead of using this function you can now simply set the interactive property t
    -
    +

    swapChildren

    @@ -1834,13 +2057,13 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child
  • - DisplayObject2 + child2
  • @@ -1853,6 +2076,8 @@ Instead of using this function you can now simply set the interactive property t + private + @@ -1866,11 +2091,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:227 + src/pixi/display/DisplayObjectContainer.js:207

    @@ -1881,7 +2106,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    Swaps the depth of 2 displayObjects

    +

    [NYI] Swaps the depth of 2 displayObjects

    +
    @@ -1892,7 +2118,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child DisplayObject @@ -1907,7 +2133,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject2 + child2 DisplayObject @@ -1965,11 +2191,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:152 + src/pixi/display/DisplayObject.js:217

    @@ -1982,6 +2208,7 @@ Instead of using this function you can now simply set the interactive property t

    A callback that is used when the users taps on the sprite with their finger basically a touch version of click

    +
    @@ -1993,7 +2220,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -2050,11 +2277,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:165 + src/pixi/display/DisplayObject.js:230

    @@ -2066,6 +2293,7 @@ basically a touch version of click

    A callback that is used when the user releases a touch over the displayObject

    +
    @@ -2077,7 +2305,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -2134,11 +2362,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:171 + src/pixi/display/DisplayObject.js:236

    @@ -2151,6 +2379,7 @@ basically a touch version of click

    A callback that is used when the user releases the touch that was over the displayObject for this callback to be fired, The touch must have started over the sprite

    +
    @@ -2162,7 +2391,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -2219,11 +2448,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:159 + src/pixi/display/DisplayObject.js:224

    @@ -2234,7 +2463,8 @@ for this callback to be fired, The touch must have started over the sprite

  • -

    A callback that is used when the user touch's over the displayObject

    +

    A callback that is used when the user touch's over the displayObject

    +
    @@ -2246,7 +2476,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -2276,6 +2506,144 @@ for this callback to be fired, The touch must have started over the sprite

    Properties

    +
    +

    _height

    + Number + + + + + private + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/display/Sprite.js:60 + +

    + + + + +
    + +
    +

    The height of the sprite (this is initially set by the texture)

    + +
    + + + + + + +
    + + +
    +

    _interactive

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:115 + +

    + + + + +
    + +
    +

    [read-only] Whether or not the object is interactive, do not toggle directly! use the interactive property

    + +
    + + + + + + +
    + + +
    +

    _width

    + Number + + + + + private + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/display/Sprite.js:51 + +

    + + + + +
    + +
    +

    The width of the sprite (this is initially set by the texture)

    + +
    + + + + + + +
    + +

    alpha

    Number @@ -2292,11 +2660,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:43 + src/pixi/display/DisplayObject.js:47

    @@ -2307,6 +2675,7 @@ for this callback to be fired, The touch must have started over the sprite

    The opacity of the object.

    +
    @@ -2340,7 +2709,7 @@ for this callback to be fired, The touch must have started over the sprite

    - src/pixi/display/Sprite.js:21 + src/pixi/display/Sprite.js:23

    @@ -2354,6 +2723,7 @@ for this callback to be fired, The touch must have started over the sprite

    The default is 0,0 this means the textures origin is the top left Setting than anchor to 0.5,0.5 means the textures origin is centered Setting the anchor to 1,1 would mean the textures origin points will be the bottom right

    +
    @@ -2366,7 +2736,7 @@ Setting the anchor to 1,1 would mean the textures origin points will be the bott

    blendMode

    - Uint + Number @@ -2387,7 +2757,7 @@ Setting the anchor to 1,1 would mean the textures origin points will be the bott - src/pixi/display/Sprite.js:38 + src/pixi/display/Sprite.js:42

    @@ -2399,6 +2769,7 @@ Setting the anchor to 1,1 would mean the textures origin points will be the bott

    The blend mode of sprite. currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    +
    @@ -2425,11 +2796,11 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:98 + src/pixi/display/DisplayObject.js:72

    @@ -2440,6 +2811,7 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    This is used to indicate if the displayObject should display a mouse hand cursor on rollover

    +
    @@ -2452,7 +2824,7 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    children

    - Array + Array @@ -2466,11 +2838,11 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:16 + src/pixi/display/DisplayObjectContainer.js:18

    @@ -2481,6 +2853,139 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    [read-only] The of children of this container.

    + +
    + + + + + + +
    + + +
    +

    color

    + Array<> + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:145 + +

    + + + + +
    + +
    +

    [NYI] Unkown

    + +
    + + + + + + +
    + + +
    +

    dynamic

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:154 + +

    + + + + +
    + +
    +

    [NYI] Holds whether or not this object is dynamic, for rendering optimization

    + +
    + + + + + + +
    + + +
    +

    filters

    + Array An array of filters + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:318 + +

    + + + + +
    + +
    +

    Sets the filters for the displayObject. +* IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. +To remove filters simply set this property to 'null'

    +
    @@ -2493,7 +2998,7 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    height

    - #Number + Number @@ -2514,7 +3019,7 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    - src/pixi/display/Sprite.js:53 + src/pixi/display/Sprite.js:102

    @@ -2524,7 +3029,8 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    -

    The height of the sprite (this is initially set by the texture)

    +

    The height of the sprite, setting this will actually modify the scale to acheive the value set

    +
    @@ -2537,7 +3043,7 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    hitArea

    - Rectangle + Rectangle | Circle | Ellipse | Polygon @@ -2551,11 +3057,11 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:72 + src/pixi/display/DisplayObject.js:63

    @@ -2567,6 +3073,7 @@ currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN

    This is the defined area that will pick up mouse / touch events. It is null by default. Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)

    +
    @@ -2593,11 +3100,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:204 + src/pixi/display/DisplayObject.js:260

    @@ -2608,6 +3115,53 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Indicates if the sprite will have touch and mouse interactivity. It is false by default

    + +
    + + +

    Default: false

    + + + + + +
    + + +
    +

    localTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:135 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object locally

    +
    @@ -2620,7 +3174,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    mask

    - PIXI.Graphics + Graphics @@ -2634,11 +3188,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:222 + src/pixi/display/DisplayObject.js:280

    @@ -2651,6 +3205,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. To remove a mask, set this property to null.

    +
    @@ -2677,11 +3232,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:58 + src/pixi/display/DisplayObject.js:88

    @@ -2692,6 +3247,7 @@ To remove a mask, set this property to null.

    [read-only] The display object container that contains this display object.

    +
    @@ -2718,11 +3274,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:29 + src/pixi/display/DisplayObject.js:31

    @@ -2733,6 +3289,7 @@ To remove a mask, set this property to null.

    The pivot point of the displayObject that it rotates around

    +
    @@ -2759,11 +3316,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:15 + src/pixi/display/DisplayObject.js:15

    @@ -2774,6 +3331,49 @@ To remove a mask, set this property to null.

    The coordinate of the object relative to the local coordinates of the parent.

    + +
    + + + + + + +
    + + +
    +

    renderable

    + Boolean + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:80 + +

    + + + + +
    + +
    +

    Can this object be rendered

    +
    @@ -2800,11 +3400,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:36 + src/pixi/display/DisplayObject.js:39

    @@ -2815,6 +3415,7 @@ To remove a mask, set this property to null.

    The rotation of the object in radians.

    +
    @@ -2841,11 +3442,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:22 + src/pixi/display/DisplayObject.js:23

    @@ -2856,6 +3457,7 @@ To remove a mask, set this property to null.

    The scale factor of the object.

    +
    @@ -2882,11 +3484,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:65 + src/pixi/display/DisplayObject.js:97

    @@ -2897,6 +3499,7 @@ To remove a mask, set this property to null.

    [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.

    +
    @@ -2930,7 +3533,7 @@ To remove a mask, set this property to null.

    - src/pixi/display/Sprite.js:31 + src/pixi/display/Sprite.js:34

    @@ -2941,6 +3544,7 @@ To remove a mask, set this property to null.

    The texture that the sprite is using

    +
    @@ -2967,11 +3571,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:50 + src/pixi/display/DisplayObject.js:55

    @@ -2982,6 +3586,7 @@ To remove a mask, set this property to null.

    The visibility of the object.

    +
    @@ -2994,7 +3599,7 @@ To remove a mask, set this property to null.

    width

    - #Number + Number @@ -3015,7 +3620,7 @@ To remove a mask, set this property to null.

    - src/pixi/display/Sprite.js:46 + src/pixi/display/Sprite.js:86

    @@ -3025,7 +3630,94 @@ To remove a mask, set this property to null.

    -

    The width of the sprite (this is initially set by the texture)

    +

    The width of the sprite, setting this will actually modify the scale to acheive the value set

    + +
    + + + + + + +
    + + +
    +

    worldAlpha

    + Number + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:106 + +

    + + + + +
    + +
    +

    [read-only] The multiplied alpha of the displayobject

    + +
    + + + + + + +
    + + +
    +

    worldTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:125 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object based on world (parent) factors

    +
    @@ -3051,13 +3743,13 @@ To remove a mask, set this property to null.

    - + - - - - - - + + + + + + diff --git a/docs/classes/SpriteSheetLoader.html b/docs/classes/SpriteSheetLoader.html index f1091f0..824e84c 100644 --- a/docs/classes/SpriteSheetLoader.html +++ b/docs/classes/SpriteSheetLoader.html @@ -3,11 +3,11 @@ SpriteSheetLoader - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -145,16 +169,21 @@

    SpriteSheetLoader Class

    - - -
    - Extends EventTarget +
    + Uses +
    + + @@ -171,12 +200,13 @@

    The sprite sheet loader is used to load in JSON sprite sheet data -To generate the data you can use http://www.codeandweb.com/texturepacker and publish the "JSON" format +To generate the data you can use http://www.codeandweb.com/texturepacker and publish the "JSON" format There is a free version so thats nice, although the paid version is great value for money. -It is highly recommended to use Sprite sheets (also know as texture atlas") as it means sprite"s can be batched and drawn together for highly increased rendering speed. +It is highly recommended to use Sprite sheets (also know as texture atlas") as it means sprite"s can be batched and drawn together for highly increased rendering speed. Once the data has been loaded the frames are stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId() This loader will also load the image file that the Spritesheet points to as well as the data. -When loaded this class will dispatch a "loaded" event

    +When loaded this class will dispatch a "loaded" event

    +
    @@ -230,7 +260,7 @@ When loaded this class will dispatch a "loaded" event

    - src/pixi/loaders/SpriteSheetLoader.js:5 + src/pixi/loaders/SpriteSheetLoader.js:5

    @@ -259,7 +289,8 @@ When loaded this class will dispatch a "loaded" event

    -

    the url of the sprite sheet JSON file

    +

    The url of the sprite sheet JSON file

    +
    @@ -274,7 +305,8 @@ When loaded this class will dispatch a "loaded" event

    - +

    Whether requests should be treated as crossorigin

    +
    @@ -297,6 +329,10 @@ When loaded this class will dispatch a "loaded" event

  • Index
  • +
  • Methods
  • + + +
  • Properties
  • @@ -307,7 +343,79 @@ When loaded this class will dispatch a "loaded" event

    Item Index

    +
    +

    Methods

    + +
    + + + +
    +

    Properties

    + + +
    @@ -316,7 +424,413 @@ When loaded this class will dispatch a "loaded" event

    +
    +

    Methods

    + +
    +

    load

    + + + () + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/SpriteSheetLoader.js:74 + +

    + + + + + +
    + +
    +

    This will begin loading the JSON file

    + +
    + + + + + + +
    + + +
    +

    onJSONLoaded

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/SpriteSheetLoader.js:89 + +

    + + + + + +
    + +
    +

    Invoke when JSON file is loaded

    + +
    + + + + + + +
    + + +
    +

    onLoaded

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/SpriteSheetLoader.js:126 + +

    + + + + + +
    + +
    +

    Invoke when all files are loaded (json and texture)

    + +
    + + + + + + +
    + + +
    + + + +
    +

    Properties

    + + +
    +

    baseUrl

    + String + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/SpriteSheetLoader.js:45 + +

    + + + + +
    + +
    +

    [read-only] The base url of the bitmap font data

    + +
    + + + + + + +
    + + +
    +

    crossorigin

    + Boolean + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/SpriteSheetLoader.js:37 + +

    + + + + +
    + +
    +

    Whether the requests should be treated as cross origin

    + +
    + + + + + + +
    + + +
    +

    frames

    + Object + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/SpriteSheetLoader.js:62 + +

    + + + + +
    + +
    +

    The frames of the sprite sheet

    + +
    + + + + + + +
    + + +
    +

    texture

    + Texture + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/SpriteSheetLoader.js:54 + +

    + + + + +
    + +
    +

    The texture being loaded

    + +
    + + + + + + +
    + + +
    +

    url

    + String + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/loaders/SpriteSheetLoader.js:29 + +

    + + + + +
    + +
    +

    The url of the bitmap font data

    + +
    + + + + + + +
    + + +
    @@ -331,13 +845,13 @@ When loaded this class will dispatch a "loaded" event

    - + - - - - - - + + + + + + diff --git a/docs/classes/Stage.html b/docs/classes/Stage.html index e145e0c..84ad082 100644 --- a/docs/classes/Stage.html +++ b/docs/classes/Stage.html @@ -3,11 +3,11 @@ Stage - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -154,7 +178,7 @@ @@ -171,6 +195,7 @@

    A Stage represents the root of the display tree. Everything connected to the stage is rendered

    +
    @@ -189,12 +214,6 @@ -
  • - - interactive - -
  • - )
    @@ -224,7 +243,7 @@ - src/pixi/display/Stage.js:5 + src/pixi/display/Stage.js:5

    @@ -253,22 +272,9 @@
    -

    the background color of the stage

    -
    +

    the background color of the stage, easiest way to pass this in is in hex format + like: 0xFFFFFF for white

    - - - -
  • - - interactive - Boolean - - - - -
    -

    enable / disable interaction (default is false)

    @@ -394,14 +400,23 @@
  • -
  • - setInteractive +
  • + setInteractionDelegate
  • -
  • +
  • + setInteractive + + + + deprecated + +
  • + +
  • swapChildren @@ -434,13 +449,6 @@ -
  • - -
  • - updateTransform - - -
  • @@ -453,6 +461,13 @@ @@ -567,7 +645,7 @@
  • - DisplayObject + child
  • @@ -593,11 +671,11 @@

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:42 + src/pixi/display/DisplayObjectContainer.js:32

    @@ -609,6 +687,7 @@

    Adds a child to the container.

    +
    @@ -619,14 +698,15 @@
  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to add to the container

    +
    @@ -651,7 +731,7 @@
  • - DisplayObject + child
  • @@ -683,11 +763,11 @@

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:139 + src/pixi/display/DisplayObjectContainer.js:120

    @@ -699,6 +779,7 @@

    Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown

    +
    @@ -709,14 +790,15 @@
  • - DisplayObject + child DisplayObject
    - +

    The child to add

    +
    @@ -731,7 +813,8 @@
    - +

    The index to place the child in

    +
    @@ -782,11 +865,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:109 + src/pixi/display/DisplayObject.js:174

    @@ -798,6 +881,7 @@

    A callback that is used when the users clicks on the displayObject with their mouse

    +
    @@ -809,7 +893,7 @@
  • interactionData - InteractionData + InteractionData @@ -866,11 +950,11 @@

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:274 + src/pixi/display/DisplayObjectContainer.js:256

    @@ -882,6 +966,7 @@

    Returns the Child at the specified index

    +
    @@ -899,7 +984,8 @@
    - +

    The index to get the child from

    +
    @@ -951,7 +1037,7 @@ - src/pixi/display/Stage.js:78 + src/pixi/display/Stage.js:125

    @@ -963,6 +1049,7 @@

    This will return the point containing global coords of the mouse.

    +
    @@ -976,7 +1063,8 @@ Point: - The point containing the coords of the global InteractionData position. +

    The point containing the coords of the global InteractionData position.

    +
  • @@ -1021,11 +1109,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:115 + src/pixi/display/DisplayObject.js:180

    @@ -1037,6 +1125,7 @@

    A callback that is used when the user clicks the mouse down over the sprite

    +
    @@ -1048,7 +1137,7 @@
  • interactionData - InteractionData + InteractionData @@ -1105,11 +1194,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:141 + src/pixi/display/DisplayObject.js:206

    @@ -1121,6 +1210,7 @@

    A callback that is used when the users mouse leaves the displayObject

    +
    @@ -1132,7 +1222,7 @@
  • interactionData - InteractionData + InteractionData @@ -1189,11 +1279,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:135 + src/pixi/display/DisplayObject.js:200

    @@ -1205,6 +1295,7 @@

    A callback that is used when the users mouse rolls over the displayObject

    +
    @@ -1216,7 +1307,7 @@
  • interactionData - InteractionData + InteractionData @@ -1273,11 +1364,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:121 + src/pixi/display/DisplayObject.js:186

    @@ -1290,6 +1381,7 @@

    A callback that is used when the user releases the mouse that was over the displayObject for this callback to be fired the mouse must have been pressed down over the displayObject

    +
    @@ -1301,7 +1393,7 @@ for this callback to be fired the mouse must have been pressed down over the dis
  • interactionData - InteractionData + InteractionData @@ -1358,11 +1450,11 @@ for this callback to be fired the mouse must have been pressed down over the dis

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:128 + src/pixi/display/DisplayObject.js:193

    @@ -1375,6 +1467,7 @@ for this callback to be fired the mouse must have been pressed down over the dis

    A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject for this callback to be fired, The touch must have started over the displayObject

    +
    @@ -1386,7 +1479,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • interactionData - InteractionData + InteractionData @@ -1417,7 +1510,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • - DisplayObject + child
  • @@ -1443,11 +1536,11 @@ for this callback to be fired, The touch must have started over the displayObjec

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:291 + src/pixi/display/DisplayObjectContainer.js:274

    @@ -1459,6 +1552,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    Removes a child from the container.

    +
    @@ -1469,14 +1563,15 @@ for this callback to be fired, The touch must have started over the displayObjec
  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to remove

    +
    @@ -1534,7 +1629,7 @@ for this callback to be fired, The touch must have started over the displayObjec - src/pixi/display/Stage.js:65 + src/pixi/display/Stage.js:109

    @@ -1545,7 +1640,8 @@ for this callback to be fired, The touch must have started over the displayObjec
    - +

    Sets the background color for the stage

    +
    @@ -1563,7 +1659,9 @@ for this callback to be fired, The touch must have started over the displayObjec
    - +

    the color of the background, easiest way to pass this in is in hex format + like: 0xFFFFFF for white

    +
    @@ -1579,8 +1677,8 @@ for this callback to be fired, The touch must have started over the displayObjec -
    -

    setInteractive

    +
    +

    setInteractionDelegate

    @@ -1588,7 +1686,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • - interactive + domElement
  • @@ -1613,12 +1711,15 @@ for this callback to be fired, The touch must have started over the displayObjec
    -

    Inherited from - DisplayObject: + +

    + + Defined in + - src/pixi/display/DisplayObject.js:193 + src/pixi/display/Stage.js:70

    @@ -1626,11 +1727,103 @@ for this callback to be fired, The touch must have started over the displayObjec +
    + +
    +

    Sets another DOM element which can receive mouse/touch interactions instead of the default Canvas element. +This is useful for when you have other DOM elements ontop of the Canvas element.

    + +
    + + +
    +

    Parameters:

    + + +
    + + + + + + + + +
    +

    setInteractive

    + + +
    + () +
    + + + + + + deprecated + + + + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:247 + +

    + + + +

    Deprecated: Simply set the `interactive` property directly

    + + +

    [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default Instead of using this function you can now simply set the interactive property to true or false

    +
    @@ -1664,7 +1857,7 @@ Instead of using this function you can now simply set the interactive property t
    -
    +

    swapChildren

    @@ -1673,13 +1866,13 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child
  • - DisplayObject2 + child2
  • @@ -1692,6 +1885,8 @@ Instead of using this function you can now simply set the interactive property t + private + @@ -1705,11 +1900,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:227 + src/pixi/display/DisplayObjectContainer.js:207

    @@ -1720,7 +1915,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    Swaps the depth of 2 displayObjects

    +

    [NYI] Swaps the depth of 2 displayObjects

    +
    @@ -1731,7 +1927,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child DisplayObject @@ -1746,7 +1942,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject2 + child2 DisplayObject @@ -1804,11 +2000,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:152 + src/pixi/display/DisplayObject.js:217

    @@ -1821,6 +2017,7 @@ Instead of using this function you can now simply set the interactive property t

    A callback that is used when the users taps on the sprite with their finger basically a touch version of click

    +
    @@ -1832,7 +2029,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -1889,11 +2086,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:165 + src/pixi/display/DisplayObject.js:230

    @@ -1905,6 +2102,7 @@ basically a touch version of click

    A callback that is used when the user releases a touch over the displayObject

    +
    @@ -1916,7 +2114,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -1973,11 +2171,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:171 + src/pixi/display/DisplayObject.js:236

    @@ -1990,6 +2188,7 @@ basically a touch version of click

    A callback that is used when the user releases the touch that was over the displayObject for this callback to be fired, The touch must have started over the sprite

    +
    @@ -2001,7 +2200,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -2058,11 +2257,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:159 + src/pixi/display/DisplayObject.js:224

    @@ -2073,7 +2272,8 @@ for this callback to be fired, The touch must have started over the sprite

  • -

    A callback that is used when the user touch's over the displayObject

    +

    A callback that is used when the user touch's over the displayObject

    +
    @@ -2085,7 +2285,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -2107,21 +2307,22 @@ for this callback to be fired, The touch must have started over the sprite

    -
    -

    updateTransform

    +
    + - - () - + +
    +

    Properties

    + + +
    +

    _interactive

    + Boolean - - - - - + private @@ -2131,26 +2332,23 @@ for this callback to be fired, The touch must have started over the sprite

    - +

    [read-only] Whether or not the object is interactive, do not toggle directly! use the interactive property

    +
    @@ -2161,14 +2359,6 @@ for this callback to be fired, The touch must have started over the sprite

    -
    - - - -
    -

    Properties

    - -

    alpha

    Number @@ -2185,11 +2375,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:43 + src/pixi/display/DisplayObject.js:47

    @@ -2200,6 +2390,7 @@ for this callback to be fired, The touch must have started over the sprite

    The opacity of the object.

    +
    @@ -2226,11 +2417,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:98 + src/pixi/display/DisplayObject.js:72

    @@ -2241,6 +2432,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is used to indicate if the displayObject should display a mouse hand cursor on rollover

    +
    @@ -2253,7 +2445,7 @@ for this callback to be fired, The touch must have started over the sprite

    children

    - Array + Array @@ -2267,11 +2459,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:16 + src/pixi/display/DisplayObjectContainer.js:18

    @@ -2282,6 +2474,186 @@ for this callback to be fired, The touch must have started over the sprite

    [read-only] The of children of this container.

    + +
    + + + + + + +
    + + +
    +

    color

    + Array<> + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:145 + +

    + + + + +
    + +
    +

    [NYI] Unkown

    + +
    + + + + + + +
    + + +
    +

    dirty

    + Boolean + + + + + private + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/display/Stage.js:44 + +

    + + + + +
    + +
    +

    Whether the stage is dirty and needs to have interactions updated

    + +
    + + + + + + +
    + + +
    +

    dynamic

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:154 + +

    + + + + +
    + +
    +

    [NYI] Holds whether or not this object is dynamic, for rendering optimization

    + +
    + + + + + + +
    + + +
    +

    filters

    + Array An array of filters + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:318 + +

    + + + + +
    + +
    +

    Sets the filters for the displayObject. +* IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. +To remove filters simply set this property to 'null'

    +
    @@ -2294,7 +2666,7 @@ for this callback to be fired, The touch must have started over the sprite

    hitArea

    - Rectangle + Rectangle | Circle | Ellipse | Polygon @@ -2308,11 +2680,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:72 + src/pixi/display/DisplayObject.js:63

    @@ -2324,6 +2696,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is the defined area that will pick up mouse / touch events. It is null by default. Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)

    +
    @@ -2334,7 +2707,52 @@ Setting it is a neat way of optimising the hitTest function that the interaction
    -
    +
    +

    interactive

    + InteractionManager + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/display/Stage.js:36 + +

    + + + + +
    + +
    +

    The interaction manage for this stage, manages all interactive activity on the stage

    + +
    + + + + + + +
    + + +

    interactive

    Boolean @@ -2348,13 +2766,16 @@ Setting it is a neat way of optimising the hitTest function that the interaction
    +

    Inherited from + + DisplayObject + -

    Inherited from - DisplayObject: + but overwritten in - src/pixi/display/DisplayObject.js:204 + src/pixi/display/Stage.js:28

    @@ -2364,7 +2785,52 @@ Setting it is a neat way of optimising the hitTest function that the interaction
    -

    Indicates if the sprite will have touch and mouse interactivity. It is false by default

    +

    Whether or not the stage is interactive

    + +
    + + + + + + +
    + + +
    +

    localTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:135 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object locally

    +
    @@ -2377,7 +2843,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    mask

    - PIXI.Graphics + Graphics @@ -2391,11 +2857,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:222 + src/pixi/display/DisplayObject.js:280

    @@ -2408,6 +2874,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. To remove a mask, set this property to null.

    +
    @@ -2434,11 +2901,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:58 + src/pixi/display/DisplayObject.js:88

    @@ -2449,6 +2916,7 @@ To remove a mask, set this property to null.

    [read-only] The display object container that contains this display object.

    +
    @@ -2475,11 +2943,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:29 + src/pixi/display/DisplayObject.js:31

    @@ -2490,6 +2958,7 @@ To remove a mask, set this property to null.

    The pivot point of the displayObject that it rotates around

    +
    @@ -2516,11 +2985,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:15 + src/pixi/display/DisplayObject.js:15

    @@ -2531,6 +3000,49 @@ To remove a mask, set this property to null.

    The coordinate of the object relative to the local coordinates of the parent.

    + +
    + + + + + + +
    + + +
    +

    renderable

    + Boolean + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:80 + +

    + + + + +
    + +
    +

    Can this object be rendered

    +
    @@ -2557,11 +3069,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:36 + src/pixi/display/DisplayObject.js:39

    @@ -2572,6 +3084,7 @@ To remove a mask, set this property to null.

    The rotation of the object in radians.

    +
    @@ -2598,11 +3111,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:22 + src/pixi/display/DisplayObject.js:23

    @@ -2613,6 +3126,7 @@ To remove a mask, set this property to null.

    The scale factor of the object.

    +
    @@ -2639,11 +3153,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:65 + src/pixi/display/DisplayObject.js:97

    @@ -2654,6 +3168,7 @@ To remove a mask, set this property to null.

    [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.

    +
    @@ -2680,11 +3195,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:50 + src/pixi/display/DisplayObject.js:55

    @@ -2695,6 +3210,96 @@ To remove a mask, set this property to null.

    The visibility of the object.

    + +
    + + + + + + +
    + + +
    +

    worldAlpha

    + Number + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:106 + +

    + + + + +
    + +
    +

    [read-only] The multiplied alpha of the displayobject

    + +
    + + + + + + +
    + + +
    +

    worldTransform

    + Mat3 + + + + + private + + + + + + +
    + +

    Inherited from + + DisplayObject + + + but overwritten in + + + + src/pixi/display/Stage.js:18 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object based on world (parent) factors

    +
    @@ -2720,13 +3325,13 @@ To remove a mask, set this property to null.

    - + - - - - - - + + + + + + diff --git a/docs/classes/Text.html b/docs/classes/Text.html index db91c58..e9d556b 100644 --- a/docs/classes/Text.html +++ b/docs/classes/Text.html @@ -3,11 +3,11 @@ Text - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -154,7 +178,7 @@
    - Defined in: src/pixi/text/Text.js:5 + Defined in: src/pixi/text/Text.js:5
    @@ -170,7 +194,8 @@
    -

    A Text Object will create a line(s) of text to split a line you can use "\n"

    +

    A Text Object will create a line(s) of text to split a line you can use "\n"

    +
    @@ -224,7 +249,7 @@ - src/pixi/text/Text.js:5 + src/pixi/text/Text.js:5

    @@ -254,6 +279,7 @@

    The copy that you would like the text to display

    +
    @@ -270,6 +296,7 @@

    The style parameters

    +
    @@ -283,7 +310,8 @@
    -

    default "bold 20pt Arial" The style and size of the font

    +

    default "bold 20pt Arial" The style and size of the font

    +
    @@ -297,7 +325,8 @@
    -

    A canvas fillstyle that will be used on the text eg "red", "#00FF00"

    +

    A canvas fillstyle that will be used on the text eg "red", "#00FF00"

    +
    @@ -311,7 +340,8 @@
    -

    An alignment of the multiline text ("left", "center" or "right")

    +

    An alignment of the multiline text ("left", "center" or "right")

    +
    @@ -325,7 +355,8 @@
    -

    A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00"

    +

    A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00"

    +
    @@ -340,6 +371,7 @@

    A number that represents the thickness of the stroke. Default is 0 (no stroke)

    +
    @@ -354,6 +386,7 @@

    Indicates if word wrap should be used

    +
    @@ -368,6 +401,7 @@

    The width at which text will wrap

    +
    @@ -432,6 +466,13 @@ +
  • + +
  • + destroy + + +
  • @@ -474,6 +515,13 @@ +
  • + +
  • + onTextureUpdate + + +
  • @@ -483,11 +531,13 @@
  • -
  • +
  • setInteractive + deprecated +
  • @@ -504,7 +554,7 @@
  • -
  • +
  • swapChildren @@ -537,6 +587,34 @@ +
  • + +
  • + updateText + + + +
  • + +
  • + updateTexture + + + +
  • + +
  • + updateTransform + + + +
  • + +
  • + wordWrap + + +
  • @@ -549,6 +627,27 @@ @@ -698,7 +846,7 @@
  • - DisplayObject + child
  • @@ -724,11 +872,11 @@

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:42 + src/pixi/display/DisplayObjectContainer.js:32

    @@ -740,6 +888,7 @@

    Adds a child to the container.

    +
    @@ -750,14 +899,15 @@
  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to add to the container

    +
    @@ -782,7 +932,7 @@
  • - DisplayObject + child
  • @@ -814,11 +964,11 @@

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:139 + src/pixi/display/DisplayObjectContainer.js:120

    @@ -830,6 +980,7 @@

    Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown

    +
    @@ -840,14 +991,15 @@
  • - DisplayObject + child DisplayObject
    - +

    The child to add

    +
    @@ -862,7 +1014,8 @@
    - +

    The index to place the child in

    +
    @@ -913,11 +1066,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:109 + src/pixi/display/DisplayObject.js:174

    @@ -929,6 +1082,7 @@

    A callback that is used when the users clicks on the displayObject with their mouse

    +
    @@ -940,7 +1094,95 @@
  • interactionData - InteractionData + InteractionData + + + + +
    + +
    + + +
  • + + + + + + + + + + + +
    +

    destroy

    + + +
    + () +
    + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/text/Text.js:270 + +

    + + + + + +
    + +
    +

    Destroys this text object

    + +
    + + +
    +

    Parameters:

    + + +
    + + + + + +
    + + +
    +

    onTextureUpdate

    + + +
    + () +
    + + + + + + + + private + + + + + + + + + + +
    + + +

    Inherited from + Sprite: + + + + src/pixi/display/Sprite.js:145 + +

    + + + + + +
    + +
    +

    When the texture is updated, this event will fire to update the scale and frame

    + +
    + + +
    +

    Parameters:

    + +
    -
    +

    setInteractive

    @@ -1572,6 +1910,8 @@ for this callback to be fired, The touch must have started over the displayObjec + deprecated + @@ -1587,16 +1927,18 @@ for this callback to be fired, The touch must have started over the displayObjec

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:193 + src/pixi/display/DisplayObject.js:247

    +

    Deprecated: Simply set the `interactive` property directly

    +
    @@ -1604,6 +1946,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default Instead of using this function you can now simply set the interactive property to true or false

    +
    @@ -1685,7 +2028,7 @@ Instead of using this function you can now simply set the interactive property t - src/pixi/text/Text.js:37 + src/pixi/text/Text.js:38

    @@ -1697,6 +2040,7 @@ Instead of using this function you can now simply set the interactive property t

    Set the style of the text

    +
    @@ -1716,6 +2060,7 @@ Instead of using this function you can now simply set the interactive property t

    The style parameters

    +
    @@ -1729,7 +2074,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    A canvas fillstyle that will be used on the text eg "red", "#00FF00"

    +

    A canvas fillstyle that will be used on the text eg "red", "#00FF00"

    +
    @@ -1743,7 +2089,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    An alignment of the multiline text ("left", "center" or "right")

    +

    An alignment of the multiline text ("left", "center" or "right")

    +
    @@ -1757,7 +2104,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00"

    +

    A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00"

    +
    @@ -1772,6 +2120,7 @@ Instead of using this function you can now simply set the interactive property t

    A number that represents the thickness of the stroke. Default is 0 (no stroke)

    +
    @@ -1786,6 +2135,7 @@ Instead of using this function you can now simply set the interactive property t

    Indicates if word wrap should be used

    +
    @@ -1800,6 +2150,7 @@ Instead of using this function you can now simply set the interactive property t

    The width at which text will wrap

    +
    @@ -1818,7 +2169,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    20pt Arial"] The style and size of the font

    +

    20pt Arial"] The style and size of the font

    +
    @@ -1869,11 +2221,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - Sprite: + Sprite: - src/pixi/display/Sprite.js:103 + src/pixi/display/Sprite.js:118

    @@ -1884,7 +2236,8 @@ Instead of using this function you can now simply set the interactive property t
    - +

    Sets the texture of the sprite

    +
    @@ -1903,6 +2256,7 @@ Instead of using this function you can now simply set the interactive property t

    The PIXI texture that is displayed by the sprite

    +
    @@ -1918,7 +2272,7 @@ Instead of using this function you can now simply set the interactive property t
    -
    +

    swapChildren

    @@ -1927,13 +2281,13 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child
  • - DisplayObject2 + child2
  • @@ -1946,6 +2300,8 @@ Instead of using this function you can now simply set the interactive property t + private + @@ -1959,11 +2315,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:227 + src/pixi/display/DisplayObjectContainer.js:207

    @@ -1974,7 +2330,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    Swaps the depth of 2 displayObjects

    +

    [NYI] Swaps the depth of 2 displayObjects

    +
    @@ -1985,7 +2342,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + child DisplayObject @@ -2000,7 +2357,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject2 + child2 DisplayObject @@ -2058,11 +2415,11 @@ Instead of using this function you can now simply set the interactive property t

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:152 + src/pixi/display/DisplayObject.js:217

    @@ -2075,6 +2432,7 @@ Instead of using this function you can now simply set the interactive property t

    A callback that is used when the users taps on the sprite with their finger basically a touch version of click

    +
    @@ -2086,7 +2444,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -2143,11 +2501,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:165 + src/pixi/display/DisplayObject.js:230

    @@ -2159,6 +2517,7 @@ basically a touch version of click

    A callback that is used when the user releases a touch over the displayObject

    +
    @@ -2170,7 +2529,7 @@ basically a touch version of click

  • interactionData - InteractionData + InteractionData @@ -2227,11 +2586,11 @@ basically a touch version of click

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:171 + src/pixi/display/DisplayObject.js:236

    @@ -2244,6 +2603,7 @@ basically a touch version of click

    A callback that is used when the user releases the touch that was over the displayObject for this callback to be fired, The touch must have started over the sprite

    +
    @@ -2255,7 +2615,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -2312,11 +2672,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:159 + src/pixi/display/DisplayObject.js:224

    @@ -2327,7 +2687,8 @@ for this callback to be fired, The touch must have started over the sprite

  • -

    A callback that is used when the user touch's over the displayObject

    +

    A callback that is used when the user touch's over the displayObject

    +
    @@ -2339,7 +2700,268 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData + + + + +
    + +
    + + +
  • + + + + + + + + + + + +
    +

    updateText

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/text/Text.js:77 + +

    + + + + + +
    + +
    +

    Renders text

    + +
    + + + + + + +
    + + +
    +

    updateTexture

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/text/Text.js:148 + +

    + + + + + +
    + +
    +

    Updates texture size based on canvas size

    + +
    + + + + + + +
    + + +
    +

    updateTransform

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/text/Text.js:167 + +

    + + + + + +
    + +
    +

    Updates the transfor of this object

    + +
    + + + + + + +
    + + +
    +

    wordWrap

    + + +
    + () +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/text/Text.js:216 + +

    + + + + + +
    + +
    +

    A Text Object will apply wordwrap

    + +
    + + +
    +

    Parameters:

    + + )
    @@ -764,7 +925,7 @@ - src/pixi/textures/Texture.js:105 + src/pixi/textures/Texture.js:127

    @@ -776,7 +937,8 @@

    Helper function that returns a texture based on an image url - If the image is not in the texture cache it will be created and loaded

    +If the image is not in the texture cache it will be created and loaded

    +
    @@ -795,6 +957,23 @@

    The image url of the texture

    + +
    + + + + +
  • + + crossorigin + Boolean + + + + +
    +

    Whether requests should be treated as crossorigin

    +
    @@ -811,13 +990,104 @@
    - Texture +

    Texture

    +
  • + + + +
    +

    onBaseTextureLoaded

    + + +
    + () +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/textures/Texture.js:73 + +

    + + + + + +
    + +
    +

    Called when the base texture is loaded

    + +
    + + +
    +

    Parameters:

    + + +
    + + + + +
    @@ -869,7 +1139,7 @@ - src/pixi/textures/Texture.js:171 + src/pixi/textures/Texture.js:195

    @@ -881,6 +1151,7 @@

    Remove a texture from the textureCache.

    +
    @@ -899,6 +1170,7 @@

    the id of the texture to be removed

    +
    @@ -917,7 +1189,8 @@ Texture: - the texture that was removed +

    the texture that was removed

    + @@ -969,7 +1242,7 @@ - src/pixi/textures/Texture.js:83 + src/pixi/textures/Texture.js:104

    @@ -981,6 +1254,7 @@

    Specifies the rectangle region of the baseTexture

    +
    @@ -998,7 +1272,8 @@
    - +

    The frame of the texture to set it to

    +
    @@ -1045,7 +1320,7 @@ - src/pixi/textures/Texture.js:31 + src/pixi/textures/Texture.js:31

    @@ -1056,6 +1331,7 @@

    The base texture of this texture

    +
    @@ -1068,7 +1344,7 @@

    frame

    - #Rectangle + Rectangle @@ -1089,7 +1365,7 @@ - src/pixi/textures/Texture.js:40 + src/pixi/textures/Texture.js:39

    @@ -1100,6 +1376,52 @@

    The frame specifies the region of the base texture that this texture uses

    + +
    + + + + + + +
    + + +
    +

    trim

    + Point + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/textures/Texture.js:47 + +

    + + + + +
    + +
    +

    The trim point

    +
    @@ -1125,13 +1447,13 @@
    - + - - - - - - + + + + + + diff --git a/docs/classes/TilingSprite.html b/docs/classes/TilingSprite.html index 663486b..9ed2238 100644 --- a/docs/classes/TilingSprite.html +++ b/docs/classes/TilingSprite.html @@ -3,11 +3,11 @@ TilingSprite - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -154,7 +178,7 @@ @@ -171,6 +195,7 @@

    A tiling sprite is a fast way of rendering a tiling image

    +
    @@ -230,7 +255,7 @@ - src/pixi/extras/TilingSprite.js:5 + src/pixi/extras/TilingSprite.js:5

    @@ -260,6 +285,7 @@

    the texture of the tiling sprite

    +
    @@ -275,6 +301,7 @@

    the width of the tiling sprite

    +
    @@ -290,6 +317,7 @@

    the height of the tiling sprite

    +
    @@ -392,6 +420,13 @@ + + +
  • + onTextureUpdate + + +
  • @@ -401,14 +436,23 @@
  • -
  • +
  • setInteractive + deprecated + +
  • + +
  • + setTexture + + +
  • -
  • +
  • swapChildren @@ -453,6 +497,13 @@ @@ -581,7 +702,7 @@
  • - DisplayObject + child
  • @@ -607,11 +728,11 @@

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:42 + src/pixi/display/DisplayObjectContainer.js:32

    @@ -623,6 +744,7 @@

    Adds a child to the container.

    +
    @@ -633,14 +755,15 @@
  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to add to the container

    +
    @@ -665,7 +788,7 @@
  • - DisplayObject + child
  • @@ -697,11 +820,11 @@

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:139 + src/pixi/display/DisplayObjectContainer.js:120

    @@ -713,6 +836,7 @@

    Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown

    +
    @@ -723,14 +847,15 @@
  • - DisplayObject + child DisplayObject
    - +

    The child to add

    +
    @@ -745,7 +870,8 @@
    - +

    The index to place the child in

    +
    @@ -796,11 +922,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:109 + src/pixi/display/DisplayObject.js:174

    @@ -812,6 +938,7 @@

    A callback that is used when the users clicks on the displayObject with their mouse

    +
    @@ -823,7 +950,7 @@
  • interactionData - InteractionData + InteractionData @@ -880,11 +1007,11 @@

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:274 + src/pixi/display/DisplayObjectContainer.js:256

    @@ -896,6 +1023,7 @@

    Returns the Child at the specified index

    +
    @@ -913,7 +1041,8 @@
    - +

    The index to get the child from

    +
    @@ -964,11 +1093,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:115 + src/pixi/display/DisplayObject.js:180

    @@ -980,6 +1109,7 @@

    A callback that is used when the user clicks the mouse down over the sprite

    +
    @@ -991,7 +1121,7 @@
  • interactionData - InteractionData + InteractionData @@ -1048,11 +1178,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:141 + src/pixi/display/DisplayObject.js:206

    @@ -1064,6 +1194,7 @@

    A callback that is used when the users mouse leaves the displayObject

    +
    @@ -1075,7 +1206,7 @@
  • interactionData - InteractionData + InteractionData @@ -1132,11 +1263,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:135 + src/pixi/display/DisplayObject.js:200

    @@ -1148,6 +1279,7 @@

    A callback that is used when the users mouse rolls over the displayObject

    +
    @@ -1159,7 +1291,7 @@
  • interactionData - InteractionData + InteractionData @@ -1216,11 +1348,11 @@

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:121 + src/pixi/display/DisplayObject.js:186

    @@ -1233,6 +1365,7 @@

    A callback that is used when the user releases the mouse that was over the displayObject for this callback to be fired the mouse must have been pressed down over the displayObject

    +
    @@ -1244,7 +1377,7 @@ for this callback to be fired the mouse must have been pressed down over the dis
  • interactionData - InteractionData + InteractionData @@ -1301,11 +1434,11 @@ for this callback to be fired the mouse must have been pressed down over the dis

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:128 + src/pixi/display/DisplayObject.js:193

    @@ -1318,6 +1451,7 @@ for this callback to be fired the mouse must have been pressed down over the dis

    A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject for this callback to be fired, The touch must have started over the displayObject

    +
    @@ -1329,7 +1463,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • interactionData - InteractionData + InteractionData @@ -1348,6 +1482,96 @@ for this callback to be fired, The touch must have started over the displayObjec +
  • + + +
    +

    onTextureUpdate

    + + +
    + (
      + +
    • + + event + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/extras/TilingSprite.js:84 + +

    + + + + + +
    + +
    +

    When the texture is updated, this event will fire to update the frame

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + event + Object + + + + +
      + +
      + + +
    • + +
    +
    + + + + +
    @@ -1360,7 +1584,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • - DisplayObject + child
  • @@ -1386,11 +1610,11 @@ for this callback to be fired, The touch must have started over the displayObjec

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:291 + src/pixi/display/DisplayObjectContainer.js:274

    @@ -1402,6 +1626,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    Removes a child from the container.

    +
    @@ -1412,14 +1637,15 @@ for this callback to be fired, The touch must have started over the displayObjec
  • - DisplayObject + child DisplayObject
    - +

    The DisplayObject to remove

    +
    @@ -1435,7 +1661,7 @@ for this callback to be fired, The touch must have started over the displayObjec
  • -
    +

    setInteractive

    @@ -1455,6 +1681,8 @@ for this callback to be fired, The touch must have started over the displayObjec + deprecated + @@ -1470,16 +1698,18 @@ for this callback to be fired, The touch must have started over the displayObjec

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:193 + src/pixi/display/DisplayObject.js:247

    +

    Deprecated: Simply set the `interactive` property directly

    +
    @@ -1487,6 +1717,7 @@ for this callback to be fired, The touch must have started over the displayObjec

    [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default Instead of using this function you can now simply set the interactive property to true or false

    +
    @@ -1520,8 +1751,8 @@ Instead of using this function you can now simply set the interactive property t
    -
    -

    swapChildren

    +
    +

    setTexture

    @@ -1529,13 +1760,7 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject - -
  • - -
  • - - DisplayObject2 + texture
  • @@ -1560,12 +1785,15 @@ Instead of using this function you can now simply set the interactive property t
    -

    Inherited from - DisplayObjectContainer: + +

    + + Defined in + - src/pixi/display/DisplayObjectContainer.js:227 + src/pixi/extras/TilingSprite.js:68

    @@ -1576,7 +1804,8 @@ Instead of using this function you can now simply set the interactive property t
    -

    Swaps the depth of 2 displayObjects

    +

    Sets the texture of the tiling sprite

    +
    @@ -1587,7 +1816,101 @@ Instead of using this function you can now simply set the interactive property t
  • - DisplayObject + texture + Texture + + + + +
    +

    The PIXI texture that is displayed by the sprite

    + +
    + + +
  • + + +
    + + + + + +
    + + +
    +

    swapChildren

    + + +
    + (
      + +
    • + + child + +
    • + +
    • + + child2 + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + +

    Inherited from + DisplayObjectContainer: + + + + src/pixi/display/DisplayObjectContainer.js:207 + +

    + + + + + +
    + +
    +

    [NYI] Swaps the depth of 2 displayObjects

    + +
    + + +
    +

    Parameters:

    + +
    -

    A callback that is used when the user touch's over the displayObject

    +

    A callback that is used when the user touch's over the displayObject

    +
    @@ -1941,7 +2268,7 @@ for this callback to be fired, The touch must have started over the sprite

  • interactionData - InteractionData + InteractionData @@ -1971,6 +2298,50 @@ for this callback to be fired, The touch must have started over the sprite

    Properties

    +
    +

    _interactive

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:115 + +

    + + + + +
    + +
    +

    [read-only] Whether or not the object is interactive, do not toggle directly! use the interactive property

    + +
    + + + + + + +
    + +

    alpha

    Number @@ -1987,11 +2358,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:43 + src/pixi/display/DisplayObject.js:47

    @@ -2002,6 +2373,7 @@ for this callback to be fired, The touch must have started over the sprite

    The opacity of the object.

    +
    @@ -2028,11 +2400,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:98 + src/pixi/display/DisplayObject.js:72

    @@ -2043,6 +2415,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is used to indicate if the displayObject should display a mouse hand cursor on rollover

    +
    @@ -2055,7 +2428,7 @@ for this callback to be fired, The touch must have started over the sprite

    children

    - Array + Array @@ -2069,11 +2442,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObjectContainer: + DisplayObjectContainer: - src/pixi/display/DisplayObjectContainer.js:16 + src/pixi/display/DisplayObjectContainer.js:18

    @@ -2084,6 +2457,184 @@ for this callback to be fired, The touch must have started over the sprite

    [read-only] The of children of this container.

    + +
    + + + + + + +
    + + +
    +

    color

    + Array<> + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:145 + +

    + + + + +
    + +
    +

    [NYI] Unkown

    + +
    + + + + + + +
    + + +
    +

    dynamic

    + Boolean + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:154 + +

    + + + + +
    + +
    +

    [NYI] Holds whether or not this object is dynamic, for rendering optimization

    + +
    + + + + + + +
    + + +
    +

    filters

    + Array An array of filters + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:318 + +

    + + + + +
    + +
    +

    Sets the filters for the displayObject. +* IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer. +To remove filters simply set this property to 'null'

    + +
    + + + + + + +
    + + +
    +

    height

    + Number + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/extras/TilingSprite.js:35 + +

    + + + + +
    + +
    +

    The height of the tiling sprite

    +
    @@ -2096,7 +2647,7 @@ for this callback to be fired, The touch must have started over the sprite

    hitArea

    - Rectangle + Rectangle | Circle | Ellipse | Polygon @@ -2110,11 +2661,11 @@ for this callback to be fired, The touch must have started over the sprite

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:72 + src/pixi/display/DisplayObject.js:63

    @@ -2126,6 +2677,7 @@ for this callback to be fired, The touch must have started over the sprite

    This is the defined area that will pick up mouse / touch events. It is null by default. Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)

    +
    @@ -2152,11 +2704,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:204 + src/pixi/display/DisplayObject.js:260

    @@ -2167,6 +2719,53 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Indicates if the sprite will have touch and mouse interactivity. It is false by default

    + +
    + + +

    Default: false

    + + + + + +
    + + +
    +

    localTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:135 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object locally

    +
    @@ -2179,7 +2778,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    mask

    - PIXI.Graphics + Graphics @@ -2193,11 +2792,11 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:222 + src/pixi/display/DisplayObject.js:280

    @@ -2210,6 +2809,7 @@ Setting it is a neat way of optimising the hitTest function that the interaction

    Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. To remove a mask, set this property to null.

    +
    @@ -2236,11 +2836,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:58 + src/pixi/display/DisplayObject.js:88

    @@ -2251,6 +2851,7 @@ To remove a mask, set this property to null.

    [read-only] The display object container that contains this display object.

    +
    @@ -2277,11 +2878,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:29 + src/pixi/display/DisplayObject.js:31

    @@ -2292,6 +2893,7 @@ To remove a mask, set this property to null.

    The pivot point of the displayObject that it rotates around

    +
    @@ -2318,11 +2920,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:15 + src/pixi/display/DisplayObject.js:15

    @@ -2333,6 +2935,49 @@ To remove a mask, set this property to null.

    The coordinate of the object relative to the local coordinates of the parent.

    + +
    + + + + + + +
    + + +
    +

    renderable

    + Boolean + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:80 + +

    + + + + +
    + +
    +

    Can this object be rendered

    +
    @@ -2359,11 +3004,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:36 + src/pixi/display/DisplayObject.js:39

    @@ -2374,6 +3019,7 @@ To remove a mask, set this property to null.

    The rotation of the object in radians.

    +
    @@ -2400,11 +3046,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:22 + src/pixi/display/DisplayObject.js:23

    @@ -2415,6 +3061,7 @@ To remove a mask, set this property to null.

    The scale factor of the object.

    +
    @@ -2441,11 +3088,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:65 + src/pixi/display/DisplayObject.js:97

    @@ -2456,6 +3103,52 @@ To remove a mask, set this property to null.

    [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.

    + +
    + + + + + + +
    + + +
    +

    texture

    + Texture + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/extras/TilingSprite.js:19 + +

    + + + + +
    + +
    +

    The texture that the sprite is using

    +
    @@ -2489,7 +3182,7 @@ To remove a mask, set this property to null.

    - src/pixi/extras/TilingSprite.js:28 + src/pixi/extras/TilingSprite.js:51

    @@ -2500,6 +3193,7 @@ To remove a mask, set this property to null.

    The offset position of the image that is being tiled

    +
    @@ -2533,7 +3227,7 @@ To remove a mask, set this property to null.

    - src/pixi/extras/TilingSprite.js:22 + src/pixi/extras/TilingSprite.js:43

    @@ -2544,6 +3238,7 @@ To remove a mask, set this property to null.

    The scaling of the image that is being tiled

    +
    @@ -2570,11 +3265,11 @@ To remove a mask, set this property to null.

    Inherited from - DisplayObject: + DisplayObject: - src/pixi/display/DisplayObject.js:50 + src/pixi/display/DisplayObject.js:55

    @@ -2585,6 +3280,138 @@ To remove a mask, set this property to null.

    The visibility of the object.

    + +
    + + + + + + +
    + + +
    +

    width

    + Number + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/extras/TilingSprite.js:27 + +

    + + + + +
    + +
    +

    The width of the tiling sprite

    + +
    + + + + + + +
    + + +
    +

    worldAlpha

    + Number + + + + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:106 + +

    + + + + +
    + +
    +

    [read-only] The multiplied alpha of the displayobject

    + +
    + + + + + + +
    + + +
    +

    worldTransform

    + Mat3 + + + + + private + + + + + + +
    + + +

    Inherited from + DisplayObject: + + + + src/pixi/display/DisplayObject.js:125 + +

    + + + + +
    + +
    +

    [read-only] Current transform of the object based on world (parent) factors

    +
    @@ -2610,13 +3437,13 @@ To remove a mask, set this property to null.

    - + - - - - - - + + + + + + diff --git a/docs/classes/WebGLBatch.html b/docs/classes/WebGLBatch.html index 39646be..28c727b 100644 --- a/docs/classes/WebGLBatch.html +++ b/docs/classes/WebGLBatch.html @@ -3,11 +3,11 @@ WebGLBatch - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -150,7 +174,7 @@ @@ -167,10 +191,107 @@

    A WebGLBatch Enables a group of sprites to be drawn using the same settings. -if a group of sprites all have the same baseTexture and blendMode then they can be grouped into a batch. All the sprites in a batch can then be drawn in one go by the GPU which is hugely efficient. ALL sprites in the webGL renderer are added to a batch even if the batch only contains one sprite. Batching is handled automatically by the webGL renderer. A good tip is: the smaller the number of batchs there are, the faster the webGL renderer will run.

    +if a group of sprites all have the same baseTexture and blendMode then they can be +grouped into a batch. All the sprites in a batch can then be drawn in one go by the +GPU which is hugely efficient. ALL sprites in the webGL renderer are added to a batch +even if the batch only contains one sprite. Batching is handled automatically by the +webGL renderer. A good tip is: the smaller the number of batchs there are, the faster +the webGL renderer will run.

    +
    +
    +

    Constructor

    +
    +

    WebGLBatch

    + + +
    + (
      + +
    • + + gl + +
    • + +
    ) +
    + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:5 + +

    + + + + + +
    + +
    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + gl + WebGLContext + + + + +
      +

      an instance of the webGL context

      + +
      + + +
    • + +
    +
    + + + + + +
    + +
    +
      @@ -194,11 +315,60 @@ if a group of sprites all have the same baseTexture and blendMode then they can @@ -273,6 +527,319 @@ if a group of sprites all have the same baseTexture and blendMode then they can

      Methods

      +
      +

      addDisplayObjectAndChildren

      + + +
      + (
        + +
      • + + displayObject + +
      • + +
      ) +
      + + + + + + + + private + + + + + + + + + + +
      + + + +

      + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:430 + +

      + + + + + +
      + +
      +

      Adds a display object and children to the webgl context

      + +
      + + +
      +

      Parameters:

      + + +
      + + + + + +
      + + +
      +

      addFilterBlocks

      + + +
      + (
        + +
      • + + start + +
      • + +
      • + + end + +
      • + +
      ) +
      + + + + + + + + private + + + + + + + + + + +
      + + + +

      + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:376 + +

      + + + + + +
      + +
      +

      Adds filter blocks

      + +
      + + +
      +

      Parameters:

      + +
        + +
      • + + start + FilterBlock + + + + +
        + +
        + + +
      • + +
      • + + end + FilterBlock + + + + +
        + +
        + + +
      • + +
      +
      + + + + + +
      + + +
      +

      clean

      + + + () + + + + + + + + + + + + + + + + +
      + + + +

      + + Defined in + + + + + src/pixi/renderers/webgl/WebGLBatch.js:71 + +

      + + + + + +
      + +
      +

      Cleans the batch so that is can be returned to an object pool and reused

      + +
      + + + + + + +
      + + +
      +

      growBatch

      + + + () + + + + + + + + + + + + + + + + +
      + + + +

      + + Defined in + + + + + src/pixi/renderers/webgl/WebGLBatch.js:292 + +

      + + + + + +
      + +
      +

      Grows the size of the batch. As the elements in the batch cannot have a dynamic size this +function is used to increase the size of the batch. It also creates a little extra room so +that the batch does not need to be resized every time a sprite is added

      + +
      + + + + + + +
      + +

      init

      @@ -315,7 +882,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can - src/pixi/renderers/webgl/WebGLBatch.js:98 + src/pixi/renderers/webgl/WebGLBatch.js:105

      @@ -326,7 +893,8 @@ if a group of sprites all have the same baseTexture and blendMode then they can
      -

      inits the batch's texture and blend mode based if the supplied sprite

      +

      inits the batch's texture and blend mode based if the supplied sprite

      +
      @@ -344,7 +912,303 @@ if a group of sprites all have the same baseTexture and blendMode then they can
      -

      the first sprite to be added to the batch. Only sprites with the same base texture and blend mode will be allowed to be added to this batch

      +

      the first sprite to be added to the batch. Only sprites with + the same base texture and blend mode will be allowed to be added to this batch

      + +
      + + + + +
    +
    + + + + + +
    + + +
    +

    initStrip

    + + +
    + (
      + +
    • + + strip + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:974 + +

    + + + + + +
    + +
    +

    Initializes a strip to be rendered

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + strip + Strip + + + + +
      +

      The strip to initialize

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    initTilingSprite

    + + +
    + (
      + +
    • + + sprite + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:781 + +

    + + + + + +
    + +
    +

    Initializes a tiling sprite

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + sprite + TilingSprite + + + + +
      +

      The tiling sprite to initialize

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    insertAfter

    + + +
    + (
      + +
    • + + item + +
    • + +
    • + + displayObject + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:647 + +

    + + + + + +
    + +
    +

    Inserts a displayObject into the linked list

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + item + DisplayObject + + + + +
      + +
      + + +
    • + +
    • + + displayObject + DisplayObject + + + + +
      +

      The object to insert

      +
      @@ -408,7 +1272,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can - src/pixi/renderers/webgl/WebGLBatch.js:145 + src/pixi/renderers/webgl/WebGLBatch.js:153

      @@ -420,6 +1284,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can

      inserts a sprite after the specified sprite

      +
      @@ -438,6 +1303,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can

      the sprite to be added

      +
      @@ -453,6 +1319,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can

      the first sprite will be inserted after this sprite

      +
      @@ -516,7 +1383,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can - src/pixi/renderers/webgl/WebGLBatch.js:117 + src/pixi/renderers/webgl/WebGLBatch.js:125

      @@ -528,6 +1395,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can

      inserts a sprite before the specified sprite

      +
      @@ -546,6 +1414,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can

      the sprite to be added

      +
      @@ -561,6 +1430,139 @@ if a group of sprites all have the same baseTexture and blendMode then they can

      the first sprite will be inserted before this sprite

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    insertObject

    + + +
    + (
      + +
    • + + displayObject + +
    • + +
    • + + previousObject + +
    • + +
    • + + nextObject + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:509 + +

    + + + + + +
    + +
    +

    Inserts a displayObject into the linked list

    + +
    + + +
    +

    Parameters:

    + +
    -

    Refresh's all the data in the batch and sync's it with the webGL buffers

    +

    Refresh's all the data in the batch and sync's it with the webGL buffers

    +
    @@ -759,7 +1764,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can - src/pixi/renderers/webgl/WebGLBatch.js:175 + src/pixi/renderers/webgl/WebGLBatch.js:182

    @@ -771,6 +1776,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can

    removes a sprite from the batch

    +
    @@ -789,6 +1795,299 @@ if a group of sprites all have the same baseTexture and blendMode then they can

    the sprite to be removed

    + +
    + + +
  • + + +
    + + + + + +
    + + +
    +

    removeDisplayObjectAndChildren

    + + +
    + () +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:487 + +

    + + + + + +
    + +
    +

    Removes a display object and children to the webgl context

    + +
    + + +
    +

    Parameters:

    + + +
    + + + + + +
    + + +
    +

    removeFilterBlocks

    + + +
    + () +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:416 + +

    + + + + + +
    + +
    +

    Remove filter blocks

    + +
    + + +
    +

    Parameters:

    + + +
    + + + + + +
    + + +
    +

    removeObject

    + + +
    + () +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:702 + +

    + + + + + +
    + +
    +

    Removes a displayObject from the linked list

    + +
    + + +
    +

    Parameters:

    + +
    + + +
    +

    render

    + + +
    + (
      + +
    • + + projection + +
    • + +
    ) +
    + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:55 + +

    + + + + + +
    + +
    +

    Renders the stage to its webgl view

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + projection + Object + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    renderSpecial

    + + +
    + (
      + +
    • + + renderable + +
    • + +
    • + + projection + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:251 + +

    + + + + + +
    + +
    +

    Renders a specific renderable

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + renderable + DisplayObject + + + + +
      + +
      + + +
    • + +
    • + + projection + Object + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    renderSpecific

    + + +
    + (
      + +
    • + + displayObject + +
    • + +
    • + + projection + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:91 + +

    + + + + + +
    + +
    +

    Renders a specific displayObject

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + displayObject + DisplayObject + + + + +
      + +
      + + +
    • + +
    • + + projection + Object + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    renderStrip

    + + +
    + (
      + +
    • + + strip + +
    • + +
    • + + projection + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:840 + +

    + + + + + +
    + +
    +

    Renders a Strip

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + strip + Strip + + + + +
      +

      The strip to render

      + +
      + + +
    • + +
    • + + projection + Object + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    renderTilingSprite

    + + +
    + (
      + +
    • + + sprite + +
    • + +
    • + + projectionMatrix + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:932 + +

    + + + + + +
    + +
    +

    Renders a TilingSprite

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + sprite + TilingSprite + + + + +
      +

      The tiling sprite to render

      + +
      + + +
    • + +
    • + + projectionMatrix + Object + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    restoreLostContext

    + + +
    + (
      + +
    • + + gl + +
    • + +
    ) +
    + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLBatch.js:90 + +

    + + + + + +
    + +
    +

    Recreates the buffers in the event of a context loss

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + gl + WebGLContext + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    setRenderable

    + + +
    + (
      + +
    • + + displayObject + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:33 + +

    + + + + + +
    + +
    +

    Add a display object to the webgl renderer

    + +
    + + +
    +

    Parameters:

    + + +
    + + + + +
    @@ -904,7 +2916,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can - src/pixi/renderers/webgl/WebGLBatch.js:218 + src/pixi/renderers/webgl/WebGLBatch.js:226

    @@ -916,6 +2928,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can

    Splits the batch into two with the specified sprite being the start of the new batch.

    +
    @@ -934,6 +2947,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can

    the sprite that indicates where the batch should be split

    +
    @@ -952,7 +2966,8 @@ if a group of sprites all have the same baseTexture and blendMode then they can WebGLBatch: - the new batch +

    the new batch

    +
    @@ -994,7 +3009,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can - src/pixi/renderers/webgl/WebGLBatch.js:401 + src/pixi/renderers/webgl/WebGLBatch.js:403

    @@ -1006,6 +3021,7 @@ if a group of sprites all have the same baseTexture and blendMode then they can

    Updates all the relevant geometry and uploads the data to the GPU

    +
    @@ -1013,6 +3029,96 @@ if a group of sprites all have the same baseTexture and blendMode then they can + + + +
    +

    updateTexture

    + + +
    + () +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderGroup.js:334 + +

    + + + + + +
    + +
    +

    Updates a webgl texture

    + +
    + + +
    +

    Parameters:

    + + +
    + + + + +
    @@ -1033,13 +3139,13 @@ if a group of sprites all have the same baseTexture and blendMode then they can - + - - - - - - + + + + + + diff --git a/docs/classes/WebGLRenderer.html b/docs/classes/WebGLRenderer.html index 4b5ffef..c0a37b3 100644 --- a/docs/classes/WebGLRenderer.html +++ b/docs/classes/WebGLRenderer.html @@ -3,11 +3,11 @@ WebGLRenderer - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -150,7 +174,7 @@ @@ -166,8 +190,11 @@
    -

    the WebGLRenderer is draws the stage and all its content onto a webGL enabled canvas. This renderer should be used for browsers support webGL. This Render works by automatically managing webGLBatchs. So no need for Sprite Batch's or Sprite Cloud's +

    the WebGLRenderer is draws the stage and all its content onto a webGL enabled canvas. This renderer +should be used for browsers support webGL. This Render works by automatically managing webGLBatchs. +So no need for Sprite Batch's or Sprite Cloud's Dont forget to add the view to your DOM or you will not see anything :)

    +
    @@ -182,13 +209,13 @@ Dont forget to add the view to your DOM or you will not see anything :)

  • - width + width=0
  • - height + height=0
  • @@ -200,7 +227,13 @@ Dont forget to add the view to your DOM or you will not see anything :)

  • - transparent + transparent=false + +
  • + +
  • + + antialias=false
  • @@ -233,7 +266,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    - src/pixi/renderers/webgl/WebGLRenderer.js:11 + src/pixi/renderers/webgl/WebGLRenderer.js:11

    @@ -255,7 +288,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

  • - width + width=0 Number @@ -263,6 +296,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    the width of the canvas view

    +
    @@ -270,7 +304,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

  • - height + height=0 Number @@ -278,6 +312,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    the height of the canvas view

    +
    @@ -293,6 +328,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    the canvas to use as a view, optional

    +
    @@ -300,7 +336,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

  • - transparent + transparent=false Boolean @@ -308,6 +344,23 @@ Dont forget to add the view to your DOM or you will not see anything :)

    the transparency of the render view, default false

    + +
    + + +
  • + +
  • + + antialias=false + Boolean + + + + +
    +

    sets antialias (only applicable in chrome at the moment)

    +
    @@ -347,6 +400,36 @@ Dont forget to add the view to your DOM or you will not see anything :)

    @@ -377,6 +487,352 @@ Dont forget to add the view to your DOM or you will not see anything :)

    Methods

    +
    +

    destroyTexture

    + + +
    + (
      + +
    • + + texture + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderer.js:269 + +

    + + + + + +
    + +
    +

    Destroys a loaded webgl texture

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + texture + Texture + + + + +
      +

      The texture to update

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    getBatch

    + + + () + + + + + WebGLBatch + + + + + + + private + + + + + + static + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderer.js:104 + +

    + + + + + +
    + +
    +

    Gets a new WebGLBatch from the pool

    + +
    + + + + +
    +

    Returns:

    + +
    + + + WebGLBatch: + + +
    +
    + + + +
    + + +
    +

    handleContextLost

    + + +
    + (
      + +
    • + + event + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderer.js:319 + +

    + + + + + +
    + +
    +

    Handles a lost webgl context

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + event + Event + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    handleContextRestored

    + + +
    + (
      + +
    • + + event + +
    • + +
    ) +
    + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderer.js:332 + +

    + + + + + +
    + +
    +

    Handles a restored webgl context

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + event + Event + + + + +
      + +
      + + +
    • + +
    +
    + + + + + +
    + +

    render

    @@ -419,7 +875,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    - src/pixi/renderers/webgl/WebGLRenderer.js:121 + src/pixi/renderers/webgl/WebGLRenderer.js:138

    @@ -431,6 +887,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    Renders the stage to its webGL view

    +
    @@ -448,7 +905,8 @@ Dont forget to add the view to your DOM or you will not see anything :)

    -

    the PIXI.Stage element to be rendered

    +

    the Stage element to be rendered

    +
    @@ -512,7 +970,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    - src/pixi/renderers/webgl/WebGLRenderer.js:263 + src/pixi/renderers/webgl/WebGLRenderer.js:288

    @@ -524,6 +982,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    resizes the webGL view to the specified width and height

    +
    @@ -542,6 +1001,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    the new width of the webGL view

    +
    @@ -557,6 +1017,7 @@ Dont forget to add the view to your DOM or you will not see anything :)

    the new height of the webGL view

    +
    @@ -569,6 +1030,251 @@ Dont forget to add the view to your DOM or you will not see anything :)

    +
    + + +
    +

    returnBatch

    + + +
    + (
      + +
    • + + batch + +
    • + +
    ) +
    + + + + + + + + private + + + + + + static + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderer.js:124 + +

    + + + + + +
    + +
    +

    Puts a batch back into the pool

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + batch + WebGLBatch + + + + +
      +

      The batch to return

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    updateTexture

    + + +
    + (
      + +
    • + + texture + +
    • + +
    ) +
    + + + + + + + + private + + + + + + static + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderer.js:225 + +

    + + + + + +
    + +
    +

    Updates a loaded webgl texture

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + texture + Texture + + + + +
      +

      The texture to update

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    +

    updateTextures

    + + + () + + + + + + + + private + + + + + + static + + + + + + +
    + + + +

    + + Defined in + + + + + src/pixi/renderers/webgl/WebGLRenderer.js:209 + +

    + + + + + +
    + +
    +

    Updates the textures loaded into this webgl renderer

    + +
    + + + + + +
    @@ -589,13 +1295,13 @@ Dont forget to add the view to your DOM or you will not see anything :)

  • - + - - - - - - + + + + + + diff --git a/docs/data.json b/docs/data.json index d450277..7f424e1 100644 --- a/docs/data.json +++ b/docs/data.json @@ -136,6 +136,56 @@ "fors": {}, "namespaces": {} }, + "src/pixi/filters/AbstractFilter.js": { + "name": "src/pixi/filters/AbstractFilter.js", + "modules": {}, + "classes": { + "AbstractFilter": 1 + }, + "fors": {}, + "namespaces": {} + }, + "src/pixi/filters/BlurFilter.js": { + "name": "src/pixi/filters/BlurFilter.js", + "modules": {}, + "classes": { + "BlurFilter": 1 + }, + "fors": {}, + "namespaces": {} + }, + "src/pixi/filters/BlurXFilter.js": { + "name": "src/pixi/filters/BlurXFilter.js", + "modules": {}, + "classes": {}, + "fors": {}, + "namespaces": {} + }, + "src/pixi/filters/BlurYFilter.js": { + "name": "src/pixi/filters/BlurYFilter.js", + "modules": {}, + "classes": {}, + "fors": {}, + "namespaces": {} + }, + "src/pixi/filters/ColorMatrixFilter.js": { + "name": "src/pixi/filters/ColorMatrixFilter.js", + "modules": {}, + "classes": { + "ColorMatrixFilter": 1 + }, + "fors": {}, + "namespaces": {} + }, + "src/pixi/filters/DisplacementFilter.js": { + "name": "src/pixi/filters/DisplacementFilter.js", + "modules": {}, + "classes": { + "DisplacementFilter": 1 + }, + "fors": {}, + "namespaces": {} + }, "src/pixi/filters/FilterBlock.js": { "name": "src/pixi/filters/FilterBlock.js", "modules": {}, @@ -143,8 +193,44 @@ "fors": {}, "namespaces": {} }, - "src/pixi/filters/MaskFilter.js": { - "name": "src/pixi/filters/MaskFilter.js", + "src/pixi/filters/GreyFilter.js": { + "name": "src/pixi/filters/GreyFilter.js", + "modules": {}, + "classes": { + "GreyFilter": 1 + }, + "fors": {}, + "namespaces": {} + }, + "src/pixi/filters/InvertFilter.js": { + "name": "src/pixi/filters/InvertFilter.js", + "modules": {}, + "classes": { + "InvertFilter": 1 + }, + "fors": {}, + "namespaces": {} + }, + "src/pixi/filters/PixelateFilter.js": { + "name": "src/pixi/filters/PixelateFilter.js", + "modules": {}, + "classes": { + "PixelateFilter": 1 + }, + "fors": {}, + "namespaces": {} + }, + "src/pixi/filters/SepiaFilter.js": { + "name": "src/pixi/filters/SepiaFilter.js", + "modules": {}, + "classes": { + "SepiaFilter": 1 + }, + "fors": {}, + "namespaces": {} + }, + "src/pixi/filters/SmartBlurFilter.js": { + "name": "src/pixi/filters/SmartBlurFilter.js", "modules": {}, "classes": {}, "fors": {}, @@ -229,6 +315,27 @@ "fors": {}, "namespaces": {} }, + "src/pixi/renderers/webgl/PixiShader.js": { + "name": "src/pixi/renderers/webgl/PixiShader.js", + "modules": {}, + "classes": {}, + "fors": {}, + "namespaces": {} + }, + "src/pixi/renderers/webgl/PrimitiveShader.js": { + "name": "src/pixi/renderers/webgl/PrimitiveShader.js", + "modules": {}, + "classes": {}, + "fors": {}, + "namespaces": {} + }, + "src/pixi/renderers/webgl/StripShader.js": { + "name": "src/pixi/renderers/webgl/StripShader.js", + "modules": {}, + "classes": {}, + "fors": {}, + "namespaces": {} + }, "src/pixi/renderers/webgl/WebGLBatch.js": { "name": "src/pixi/renderers/webgl/WebGLBatch.js", "modules": {}, @@ -236,6 +343,13 @@ "fors": {}, "namespaces": {} }, + "src/pixi/renderers/webgl/WebGLFilterManager.js": { + "name": "src/pixi/renderers/webgl/WebGLFilterManager.js", + "modules": {}, + "classes": {}, + "fors": {}, + "namespaces": {} + }, "src/pixi/renderers/webgl/WebGLGraphics.js": { "name": "src/pixi/renderers/webgl/WebGLGraphics.js", "modules": {}, @@ -325,14 +439,30 @@ "src/pixi/utils/EventTarget.js": { "name": "src/pixi/utils/EventTarget.js", "modules": {}, - "classes": {}, + "classes": { + "EventTarget": 1 + }, "fors": {}, "namespaces": {} }, + "src/pixi/utils/Polyk.js": { + "name": "src/pixi/utils/Polyk.js", + "modules": {}, + "classes": { + "PolyK._PointInTriangle": 1, + "PolyK._convex": 1 + }, + "fors": {}, + "namespaces": { + "PolyK": 1 + } + }, "src/pixi/utils/Utils.js": { "name": "src/pixi/utils/Utils.js", "modules": {}, - "classes": {}, + "classes": { + "PolyK.AjaxRequest": 1 + }, "fors": {}, "namespaces": {} }, @@ -340,8 +470,8 @@ "name": "src/pixi/InteractionManager.js", "modules": {}, "classes": { - "InteractionManager": 1, - "InteractionData": 1 + "PolyK.InteractionManager": 1, + "PolyK.InteractionData": 1 }, "fors": {}, "namespaces": {} @@ -388,6 +518,14 @@ "CustomRenderable": 1, "Spine": 1, "TilingSprite": 1, + "AbstractFilter": 1, + "BlurFilter": 1, + "ColorMatrixFilter": 1, + "DisplacementFilter": 1, + "GreyFilter": 1, + "InvertFilter": 1, + "PixelateFilter": 1, + "SepiaFilter": 1, "AssetLoader": 1, "BitmapFontLoader": 1, "ImageLoader": 1, @@ -403,14 +541,18 @@ "BaseTexture": 1, "RenderTexture": 1, "Texture": 1, - "InteractionManager": 1, - "InteractionData": 1 + "EventTarget": 1, + "PolyK._PointInTriangle": 1, + "PolyK._convex": 1, + "PolyK.AjaxRequest": 1, + "PolyK.InteractionManager": 1, + "PolyK.InteractionData": 1 }, "fors": {}, "namespaces": {}, "tag": "module", "file": "src/pixi/InteractionManager.js", - "line": 493 + "line": 646 } }, "classes": { @@ -425,6 +567,7 @@ "module": "PIXI", "file": "src/pixi/core/Circle.js", "line": 5, + "description": "The Circle object can be used to specify a hit area for displayobjects", "is_constructor": 1, "params": [ { @@ -455,26 +598,27 @@ "module": "PIXI", "file": "src/pixi/core/Ellipse.js", "line": 5, + "description": "The Ellipse object can be used to specify a hit area for displayobjects", "is_constructor": 1, "params": [ { "name": "x", - "description": "The X coord of the upper-left corner of the framing rectangle of this circle", + "description": "The X coord of the upper-left corner of the framing rectangle of this ellipse", "type": "Number" }, { "name": "y", - "description": "The Y coord of the upper-left corner of the framing rectangle of this circle", + "description": "The Y coord of the upper-left corner of the framing rectangle of this ellipse", "type": "Number" }, { "name": "width", - "description": "The overall height of this ellipse", + "description": "The overall width of this ellipse", "type": "Number" }, { "name": "height", - "description": "The overall width of this ellipse", + "description": "The overall height of this ellipse", "type": "Number" } ] @@ -520,8 +664,9 @@ "params": [ { "name": "points", - "description": "This cna be an array of Points or a flat array of numbers\n that will be interpreted as [x,y, x,y, ...]", - "type": "Array|Array" + "description": "This can be an array of Points that form the polygon,\n a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arguments passed can be\n all the points of the polygon e.g. `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the\n arguments passed can be flat x,y values e.g. `new PIXI.Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are\n Numbers.", + "type": "Array|Array|Point...|Number...", + "multiple": true } ] }, @@ -541,22 +686,22 @@ "params": [ { "name": "x", - "description": "position of the rectangle", + "description": "The X coord of the upper-left corner of the rectangle", "type": "Number" }, { "name": "y", - "description": "position of the rectangle", + "description": "The Y coord of the upper-left corner of the rectangle", "type": "Number" }, { "name": "width", - "description": "of the rectangle", + "description": "The overall width of this rectangle", "type": "Number" }, { "name": "height", - "description": "of the rectangle", + "description": "The overall height of this rectangle", "type": "Number" } ] @@ -572,7 +717,7 @@ "module": "PIXI", "file": "src/pixi/display/DisplayObject.js", "line": 5, - "description": "this is the base class for all objects that are rendered on the screen.", + "description": "The base class for all objects that are rendered on the screen.", "is_constructor": 1 }, "DisplayObjectContainer": { @@ -586,7 +731,7 @@ "module": "PIXI", "file": "src/pixi/display/DisplayObjectContainer.js", "line": 6, - "description": "A DisplayObjectContainer represents a collection of display objects. It is the base class of all display objects that act as a container for other objects.", + "description": "A DisplayObjectContainer represents a collection of display objects.\nIt is the base class of all display objects that act as a container for other objects.", "extends": "DisplayObject", "is_constructor": 1 }, @@ -608,7 +753,7 @@ { "name": "textures", "description": "an array of {Texture} objects that make up the animation", - "type": "Array" + "type": "Array" } ] }, @@ -623,12 +768,13 @@ "module": "PIXI", "file": "src/pixi/display/Sprite.js", "line": 10, + "description": "The SPrite object is the base for all textured objects that are rendered to the screen", "extends": "DisplayObjectContainer", "is_constructor": 1, "params": [ { "name": "texture", - "description": "", + "description": "The texture for this sprite", "type": "Texture" } ], @@ -651,13 +797,8 @@ "params": [ { "name": "backgroundColor", - "description": "the background color of the stage", + "description": "the background color of the stage, easiest way to pass this in is in hex format\n\t\tlike: 0xFFFFFF for white", "type": "Number" - }, - { - "name": "interactive", - "description": "enable / disable interaction (default is false)", - "type": "Boolean" } ] }, @@ -672,7 +813,7 @@ "module": "PIXI", "file": "src/pixi/extras/CustomRenderable.js", "line": 6, - "description": "Need to finalize this a bit more but works! Its in but will be working on this feature properly next..:)", + "description": "This object is one that will allow you to specify custom rendering functions based on render type", "extends": "DisplayObject", "is_constructor": 1 }, @@ -687,15 +828,18 @@ "module": "PIXI", "file": "src/pixi/loaders/SpineLoader.js", "line": 10, - "description": "The Spine loader is used to load in JSON spine data\nTo generate the data you need to use http://esotericsoftware.com/ and export the \"JSON\" format\nDue to a clash of names You will need to change the extension of the spine file from *.json to *.anim for it to load\nSee example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source\nYou will need to generate a sprite sheet to accompany the spine data \nWhen loaded this class will dispatch a \"loaded\" event", - "is_constructor": 1, + "description": "The Spine loader is used to load in JSON spine data\nTo generate the data you need to use http://esotericsoftware.com/ and export the \"JSON\" format\nDue to a clash of names You will need to change the extension of the spine file from *.json to *.anim for it to load\nSee example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source\nYou will need to generate a sprite sheet to accompany the spine data\nWhen loaded this class will dispatch a \"loaded\" event", "extends": "DisplayObjectContainer", + "is_constructor": 1, "params": [ { "name": "url", - "description": "the url of the spine anim file to be used", + "description": "The url of the spine anim file to be used", "type": "String" } + ], + "uses": [ + "EventTarget" ] }, "TilingSprite": { @@ -730,6 +874,135 @@ } ] }, + "AbstractFilter": { + "name": "AbstractFilter", + "shortname": "AbstractFilter", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "module": "PIXI", + "file": "src/pixi/filters/AbstractFilter.js", + "line": 6, + "description": "This is the base class for creating a pixi.js filter. Currently only webGL supports filters.\nIf you want to make a custom filter this should be your base class.", + "is_constructor": 1, + "params": [ + { + "name": "fragmentSrc", + "description": "" + }, + { + "name": "unifroms", + "description": "" + } + ] + }, + "BlurFilter": { + "name": "BlurFilter", + "shortname": "BlurFilter", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "module": "PIXI", + "file": "src/pixi/filters/BlurFilter.js", + "line": 6, + "description": "The BlurFilter applies a Gaussian blur to an object. \n The strength of the blur can be set for x- and y-axis separately (always relative to the stage).", + "contructor": "" + }, + "ColorMatrixFilter": { + "name": "ColorMatrixFilter", + "shortname": "ColorMatrixFilter", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "module": "PIXI", + "file": "src/pixi/filters/ColorMatrixFilter.js", + "line": 5, + "description": "The ColorMatrixFilter class lets you apply a 4x4 matrix transformation on the RGBA \n color and alpha values of every pixel on your displayObject to produce a result \n with a new set of RGBA color and alpha values. Its pretty powerful!", + "contructor": "" + }, + "DisplacementFilter": { + "name": "DisplacementFilter", + "shortname": "DisplacementFilter", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "module": "PIXI", + "file": "src/pixi/filters/DisplacementFilter.js", + "line": 6, + "description": "The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. \n You can use this filter to apply all manor of crazy warping effects\n Currently the r property of the texture is used offset the x and the g propery of the texture is used to offset the y.", + "contructor": "", + "params": [ + { + "name": "texture", + "description": "The texture used for the displacemtent map * must be power of 2 texture at the moment", + "type": "Texture" + } + ] + }, + "GreyFilter": { + "name": "GreyFilter", + "shortname": "GreyFilter", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "module": "PIXI", + "file": "src/pixi/filters/GreyFilter.js", + "line": 6, + "description": "This turns your displayObjects to black and white.", + "contructor": "" + }, + "InvertFilter": { + "name": "InvertFilter", + "shortname": "InvertFilter", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "module": "PIXI", + "file": "src/pixi/filters/InvertFilter.js", + "line": 5, + "description": "This inverts your displayObjects colors.", + "contructor": "" + }, + "PixelateFilter": { + "name": "PixelateFilter", + "shortname": "PixelateFilter", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "module": "PIXI", + "file": "src/pixi/filters/PixelateFilter.js", + "line": 5, + "description": "This filter applies a pixlate effect making display objects appear \"blocky\"", + "contructor": "" + }, + "SepiaFilter": { + "name": "SepiaFilter", + "shortname": "SepiaFilter", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "module": "PIXI", + "file": "src/pixi/filters/SepiaFilter.js", + "line": 7, + "description": "This applies a sepia effect to your displayObjects.", + "contructor": "" + }, "AssetLoader": { "name": "AssetLoader", "shortname": "AssetLoader", @@ -741,14 +1014,21 @@ "module": "PIXI", "file": "src/pixi/loaders/AssetLoader.js", "line": 5, - "description": "A Class that loads a bunch of images / sprite sheet / bitmap font files. Once the assets have been loaded they are added to the PIXI Texture cache and can be accessed easily through PIXI.Texture.fromImage() and PIXI.Sprite.fromImage()\nWhen all items have been loaded this class will dispatch a \"onLoaded\" event\nAs each individual item is loaded this class will dispatch a \"onProgress\" event", + "description": "A Class that loads a bunch of images / sprite sheet / bitmap font files. Once the\nassets have been loaded they are added to the PIXI Texture cache and can be accessed\neasily through PIXI.Texture.fromImage() and PIXI.Sprite.fromImage()\nWhen all items have been loaded this class will dispatch a \"onLoaded\" event\nAs each individual item is loaded this class will dispatch a \"onProgress\" event", "is_constructor": 1, - "extends": "EventTarget", + "uses": [ + "EventTarget" + ], "params": [ { "name": "assetURLs", - "description": "an array of image/sprite sheet urls that you would like loaded supported. Supported image formats include \"jpeg\", \"jpg\", \"png\", \"gif\". Supported sprite sheet data formats only include \"JSON\" at this time. Supported bitmap font data formats include \"xml\" and \"fnt\".", - "type": "Array" + "description": "an array of image/sprite sheet urls that you would like loaded\n supported. Supported image formats include \"jpeg\", \"jpg\", \"png\", \"gif\". Supported\n sprite sheet data formats only include \"JSON\" at this time. Supported bitmap font\n data formats include \"xml\" and \"fnt\".", + "type": "Array" + }, + { + "name": "crossorigin", + "description": "Whether requests should be treated as crossorigin", + "type": "Boolean" } ] }, @@ -764,17 +1044,19 @@ "file": "src/pixi/loaders/BitmapFontLoader.js", "line": 5, "description": "The xml loader is used to load in XML bitmap font data (\"xml\" or \"fnt\")\nTo generate the data you can use http://www.angelcode.com/products/bmfont/\nThis loader will also load the image file as the data.\nWhen loaded this class will dispatch a \"loaded\" event", - "extends": "EventTarget", + "uses": [ + "EventTarget" + ], "is_constructor": 1, "params": [ { "name": "url", - "description": "the url of the sprite sheet JSON file", + "description": "The url of the sprite sheet JSON file", "type": "String" }, { "name": "crossorigin", - "description": "", + "description": "Whether requests should be treated as crossorigin", "type": "Boolean" } ] @@ -791,7 +1073,9 @@ "file": "src/pixi/loaders/ImageLoader.js", "line": 5, "description": "The image loader class is responsible for loading images file formats (\"jpeg\", \"jpg\", \"png\" and \"gif\")\nOnce the image has been loaded it is stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId()\nWhen loaded this class will dispatch a 'loaded' event", - "extends": "EventTarget", + "uses": [ + "EventTarget" + ], "is_constructor": 1, "params": [ { @@ -801,7 +1085,7 @@ }, { "name": "crossorigin", - "description": "", + "description": "Whether requests should be treated as crossorigin", "type": "Boolean" } ] @@ -818,17 +1102,19 @@ "file": "src/pixi/loaders/JsonLoader.js", "line": 5, "description": "The json file loader is used to load in JSON data and parsing it\nWhen loaded this class will dispatch a \"loaded\" event\nIf load failed this class will dispatch a \"error\" event", - "extends": "EventTarget", + "uses": [ + "EventTarget" + ], "is_constructor": 1, "params": [ { "name": "url", - "description": "the url of the JSON file", + "description": "The url of the JSON file", "type": "String" }, { "name": "crossorigin", - "description": "", + "description": "Whether requests should be treated as crossorigin", "type": "Boolean" } ] @@ -845,17 +1131,19 @@ "file": "src/pixi/loaders/SpriteSheetLoader.js", "line": 5, "description": "The sprite sheet loader is used to load in JSON sprite sheet data\nTo generate the data you can use http://www.codeandweb.com/texturepacker and publish the \"JSON\" format\nThere is a free version so thats nice, although the paid version is great value for money.\nIt is highly recommended to use Sprite sheets (also know as texture atlas\") as it means sprite\"s can be batched and drawn together for highly increased rendering speed.\nOnce the data has been loaded the frames are stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId()\nThis loader will also load the image file that the Spritesheet points to as well as the data.\nWhen loaded this class will dispatch a \"loaded\" event", - "extends": "EventTarget", + "uses": [ + "EventTarget" + ], "is_constructor": 1, "params": [ { "name": "url", - "description": "the url of the sprite sheet JSON file", + "description": "The url of the sprite sheet JSON file", "type": "String" }, { "name": "crossorigin", - "description": "", + "description": "Whether requests should be treated as crossorigin", "type": "Boolean" } ] @@ -871,7 +1159,7 @@ "module": "PIXI", "file": "src/pixi/primitives/Graphics.js", "line": 6, - "description": "The Graphics class contains a set of methods that you can use to create primitive shapes and lines. \nIt is important to know that with the webGL renderer only simple polys can be filled at this stage\nComplex polys will not be filled. Heres an example of a complex poly: http://www.goodboydigital.com/wp-content/uploads/2013/06/complexPolygon.png", + "description": "The Graphics class contains a set of methods that you can use to create primitive shapes and lines.\nIt is important to know that with the webGL renderer only simple polys can be filled at this stage\nComplex polys will not be filled. Heres an example of a complex poly: http://www.goodboydigital.com/wp-content/uploads/2013/06/complexPolygon.png", "extends": "DisplayObjectContainer", "is_constructor": 1 }, @@ -885,7 +1173,7 @@ "extension_for": [], "module": "PIXI", "file": "src/pixi/renderers/webgl/WebGLGraphics.js", - "line": 7, + "line": 5, "description": "A set of functions used by the webGL renderer to draw the primitive graphics data" }, "CanvasRenderer": { @@ -903,12 +1191,12 @@ "is_constructor": 1, "params": [ { - "name": "width", + "name": "width=0", "description": "the width of the canvas view", "type": "Number" }, { - "name": "height", + "name": "height=0", "description": "the height of the canvas view", "type": "Number" }, @@ -918,12 +1206,11 @@ "type": "Canvas" }, { - "name": "transparent", + "name": "transparent=false", "description": "the transparency of the render view, default false", "type": "Boolean" } - ], - "default": "false" + ] }, "WebGLBatch": { "name": "WebGLBatch", @@ -935,18 +1222,17 @@ "extension_for": [], "module": "PIXI", "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", - "line": 8, - "description": "A WebGLBatch Enables a group of sprites to be drawn using the same settings.\nif a group of sprites all have the same baseTexture and blendMode then they can be grouped into a batch. All the sprites in a batch can then be drawn in one go by the GPU which is hugely efficient. ALL sprites in the webGL renderer are added to a batch even if the batch only contains one sprite. Batching is handled automatically by the webGL renderer. A good tip is: the smaller the number of batchs there are, the faster the webGL renderer will run.", + "line": 5, + "description": "A WebGLBatch Enables a group of sprites to be drawn using the same settings.\nif a group of sprites all have the same baseTexture and blendMode then they can be\ngrouped into a batch. All the sprites in a batch can then be drawn in one go by the\nGPU which is hugely efficient. ALL sprites in the webGL renderer are added to a batch\neven if the batch only contains one sprite. Batching is handled automatically by the\nwebGL renderer. A good tip is: the smaller the number of batchs there are, the faster\nthe webGL renderer will run.", + "is_constructor": 1, "params": [ { - "name": "an", - "description": "instance of the webGL context" + "name": "gl", + "description": "an instance of the webGL context", + "type": "WebGLContext" } ], - "return": { - "description": "WebGLBatch {@link PIXI.renderers.WebGLBatch}", - "type": "PIXI.renderers.WebGLBatch" - } + "contructor": "" }, "WebGLRenderer": { "name": "WebGLRenderer", @@ -959,16 +1245,16 @@ "module": "PIXI", "file": "src/pixi/renderers/webgl/WebGLRenderer.js", "line": 11, - "description": "the WebGLRenderer is draws the stage and all its content onto a webGL enabled canvas. This renderer should be used for browsers support webGL. This Render works by automatically managing webGLBatchs. So no need for Sprite Batch's or Sprite Cloud's\nDont forget to add the view to your DOM or you will not see anything :)", + "description": "the WebGLRenderer is draws the stage and all its content onto a webGL enabled canvas. This renderer\nshould be used for browsers support webGL. This Render works by automatically managing webGLBatchs.\nSo no need for Sprite Batch's or Sprite Cloud's\nDont forget to add the view to your DOM or you will not see anything :)", "is_constructor": 1, "params": [ { - "name": "width", + "name": "width=0", "description": "the width of the canvas view", "type": "Number" }, { - "name": "height", + "name": "height=0", "description": "the height of the canvas view", "type": "Number" }, @@ -978,12 +1264,16 @@ "type": "Canvas" }, { - "name": "transparent", + "name": "transparent=false", "description": "the transparency of the render view, default false", "type": "Boolean" + }, + { + "name": "antialias=false", + "description": "sets antialias (only applicable in chrome at the moment)", + "type": "Boolean" } - ], - "default": "false" + ] }, "BitmapText": { "name": "BitmapText", @@ -996,7 +1286,7 @@ "module": "PIXI", "file": "src/pixi/text/BitmapText.js", "line": 5, - "description": "A Text Object will create a line(s) of text using bitmap font. To split a line you can use \"\\n\", \"\\r\" or \"\\r\\n\"\nYou can generate the fnt files using \nhttp://www.angelcode.com/products/bmfont/ for windows or\nhttp://www.bmglyph.com/ for mac.", + "description": "A Text Object will create a line(s) of text using bitmap font. To split a line you can use \"\\n\", \"\\r\" or \"\\r\\n\"\nYou can generate the fnt files using\nhttp://www.angelcode.com/products/bmfont/ for windows or\nhttp://www.bmglyph.com/ for mac.", "extends": "DisplayObjectContainer", "is_constructor": 1, "params": [ @@ -1115,7 +1405,9 @@ "file": "src/pixi/textures/BaseTexture.js", "line": 9, "description": "A texture stores the information that represents an image. All textures have a base texture", - "extends": "EventTarget", + "uses": [ + "EventTarget" + ], "is_constructor": 1, "params": [ { @@ -1142,12 +1434,12 @@ "params": [ { "name": "width", - "description": "", + "description": "The width of the render texture", "type": "Number" }, { "name": "height", - "description": "", + "description": "The height of the render texture", "type": "Number" } ] @@ -1163,24 +1455,98 @@ "module": "PIXI", "file": "src/pixi/textures/Texture.js", "line": 8, - "description": "A texture stores the information that represents an image or part of an image. It cannot be added to the display list directly. To do this use PIXI.Sprite. If no frame is provided then the whole image is used", - "extends": "EventTarget", + "description": "A texture stores the information that represents an image or part of an image. It cannot be added\nto the display list directly. To do this use PIXI.Sprite. If no frame is provided then the whole image is used", + "uses": [ + "EventTarget" + ], "is_constructor": 1, "params": [ { "name": "baseTexture", - "description": "", + "description": "The base texture source to create the texture from", "type": "BaseTexture" }, { - "name": "frmae", - "description": "", + "name": "frame", + "description": "The rectangle frame of the texture to show", "type": "Rectangle" } ] }, - "InteractionManager": { - "name": "InteractionManager", + "EventTarget": { + "name": "EventTarget", + "shortname": "EventTarget", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [ + "Spine", + "AssetLoader", + "BitmapFontLoader", + "ImageLoader", + "JsonLoader", + "SpriteSheetLoader", + "BaseTexture", + "Texture" + ], + "module": "PIXI", + "file": "src/pixi/utils/EventTarget.js", + "line": 6, + "description": "Adds event emitter functionality to a class", + "example": [ + "\n\t\tfunction MyEmitter() {\n\t\t\tPIXI.EventTarget.call(this); //mixes in event target stuff\n\t\t}\n\n\t\tvar em = new MyEmitter();\n\t\tem.emit({ type: 'eventName', data: 'some data' });" + ] + }, + "PolyK._PointInTriangle": { + "name": "PolyK._PointInTriangle", + "shortname": "PolyK._PointInTriangle", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "module": "PIXI", + "namespace": "PolyK", + "file": "src/pixi/utils/Polyk.js", + "line": 109, + "description": "Checks if a point is within a triangle", + "access": "private", + "tagname": "" + }, + "PolyK._convex": { + "name": "PolyK._convex", + "shortname": "PolyK._convex", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "module": "PIXI", + "namespace": "PolyK", + "file": "src/pixi/utils/Polyk.js", + "line": 139, + "description": "Checks if a shape is convex", + "access": "private", + "tagname": "" + }, + "PolyK.AjaxRequest": { + "name": "PolyK.AjaxRequest", + "shortname": "AjaxRequest", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "module": "PIXI", + "namespace": "PolyK", + "file": "src/pixi/utils/Utils.js", + "line": 81, + "description": "A wrapper for ajax requests to be handled cross browser", + "is_constructor": 1 + }, + "PolyK.InteractionManager": { + "name": "PolyK.InteractionManager", "shortname": "InteractionManager", "classitems": [], "plugins": [], @@ -1188,21 +1554,21 @@ "plugin_for": [], "extension_for": [], "module": "PIXI", + "namespace": "PolyK", "file": "src/pixi/InteractionManager.js", - "line": 7, + "line": 5, "description": "The interaction manager deals with mouse and touch events. Any DisplayObject can be interactive\nThis manager also supports multitouch.", "is_constructor": 1, "params": [ { "name": "stage", - "description": "", + "description": "The stage to handle interactions", "type": "Stage" } - ], - "type": "Stage" + ] }, - "InteractionData": { - "name": "InteractionData", + "PolyK.InteractionData": { + "name": "PolyK.InteractionData", "shortname": "InteractionData", "classitems": [], "plugins": [], @@ -1210,8 +1576,10 @@ "plugin_for": [], "extension_for": [], "module": "PIXI", + "namespace": "PolyK", "file": "src/pixi/InteractionManager.js", - "line": 493, + "line": 646, + "description": "Holds all information related to an Interaction event", "is_constructor": 1 } }, @@ -1224,7 +1592,7 @@ }, { "file": "src/pixi/core/Circle.js", - "line": 14, + "line": 16, "itemtype": "property", "name": "x", "type": "Number", @@ -1233,7 +1601,7 @@ }, { "file": "src/pixi/core/Circle.js", - "line": 21, + "line": 23, "itemtype": "property", "name": "y", "type": "Number", @@ -1242,7 +1610,7 @@ }, { "file": "src/pixi/core/Circle.js", - "line": 28, + "line": 30, "itemtype": "property", "name": "radius", "type": "Number", @@ -1251,17 +1619,20 @@ }, { "file": "src/pixi/core/Circle.js", - "line": 36, + "line": 38, + "description": "Creates a clone of this Circle instance", "itemtype": "method", "name": "clone", "return": { - "description": "a copy of the polygon" + "description": "a copy of the polygon", + "type": "Circle" }, "class": "Circle" }, { "file": "src/pixi/core/Circle.js", - "line": 45, + "line": 49, + "description": "Checks if the x, and y coords passed to this function are contained within this circle", "itemtype": "method", "name": "contains", "params": [ @@ -1277,7 +1648,8 @@ } ], "return": { - "description": "if the x/y coords are within this polygon" + "description": "if the x/y coords are within this polygon", + "type": "Boolean" }, "class": "Circle" }, @@ -1289,7 +1661,7 @@ }, { "file": "src/pixi/core/Ellipse.js", - "line": 15, + "line": 17, "itemtype": "property", "name": "x", "type": "Number", @@ -1298,7 +1670,7 @@ }, { "file": "src/pixi/core/Ellipse.js", - "line": 22, + "line": 24, "itemtype": "property", "name": "y", "type": "Number", @@ -1307,7 +1679,7 @@ }, { "file": "src/pixi/core/Ellipse.js", - "line": 29, + "line": 31, "itemtype": "property", "name": "width", "type": "Number", @@ -1316,7 +1688,7 @@ }, { "file": "src/pixi/core/Ellipse.js", - "line": 36, + "line": 38, "itemtype": "property", "name": "height", "type": "Number", @@ -1325,17 +1697,20 @@ }, { "file": "src/pixi/core/Ellipse.js", - "line": 44, + "line": 46, + "description": "Creates a clone of this Ellipse instance", "itemtype": "method", "name": "clone", "return": { - "description": "a copy of the polygon" + "description": "a copy of the ellipse", + "type": "Ellipse" }, "class": "Ellipse" }, { "file": "src/pixi/core/Ellipse.js", - "line": 53, + "line": 57, + "description": "Checks if the x, and y coords passed to this function are contained within this ellipse", "itemtype": "method", "name": "contains", "params": [ @@ -1351,7 +1726,8 @@ } ], "return": { - "description": "if the x/y coords are within this polygon" + "description": "if the x/y coords are within this ellipse", + "type": "Boolean" }, "class": "Ellipse" }, @@ -1363,7 +1739,7 @@ }, { "file": "src/pixi/core/Point.js", - "line": 14, + "line": 15, "itemtype": "property", "name": "x", "type": "Number", @@ -1372,7 +1748,7 @@ }, { "file": "src/pixi/core/Point.js", - "line": 21, + "line": 22, "itemtype": "property", "name": "y", "type": "Number", @@ -1381,11 +1757,13 @@ }, { "file": "src/pixi/core/Point.js", - "line": 29, + "line": 30, + "description": "Creates a clone of this point", "itemtype": "method", "name": "clone", "return": { - "description": "a copy of the point" + "description": "a copy of the point", + "type": "Point" }, "class": "Point" }, @@ -1397,17 +1775,20 @@ }, { "file": "src/pixi/core/Polygon.js", - "line": 28, + "line": 35, + "description": "Creates a clone of this polygon", "itemtype": "method", "name": "clone", "return": { - "description": "a copy of the polygon" + "description": "a copy of the polygon", + "type": "Polygon" }, "class": "Polygon" }, { "file": "src/pixi/core/Polygon.js", - "line": 42, + "line": 51, + "description": "Checks if the x, and y coords passed to this function are contained within this polygon", "itemtype": "method", "name": "contains", "params": [ @@ -1423,7 +1804,8 @@ } ], "return": { - "description": "if the x/y coords are within this polygon" + "description": "if the x/y coords are within this polygon", + "type": "Boolean" }, "class": "Polygon" }, @@ -1435,7 +1817,7 @@ }, { "file": "src/pixi/core/Rectangle.js", - "line": 16, + "line": 17, "itemtype": "property", "name": "x", "type": "Number", @@ -1444,7 +1826,7 @@ }, { "file": "src/pixi/core/Rectangle.js", - "line": 23, + "line": 24, "itemtype": "property", "name": "y", "type": "Number", @@ -1453,7 +1835,7 @@ }, { "file": "src/pixi/core/Rectangle.js", - "line": 30, + "line": 31, "itemtype": "property", "name": "width", "type": "Number", @@ -1462,7 +1844,7 @@ }, { "file": "src/pixi/core/Rectangle.js", - "line": 37, + "line": 38, "itemtype": "property", "name": "height", "type": "Number", @@ -1471,17 +1853,20 @@ }, { "file": "src/pixi/core/Rectangle.js", - "line": 45, + "line": 46, + "description": "Creates a clone of this Rectangle", "itemtype": "method", "name": "clone", "return": { - "description": "a copy of the rectangle" + "description": "a copy of the rectangle", + "type": "Rectangle" }, "class": "Rectangle" }, { "file": "src/pixi/core/Rectangle.js", - "line": 54, + "line": 57, + "description": "Checks if the x, and y coords passed to this function are contained within this Rectangle", "itemtype": "method", "name": "contains", "params": [ @@ -1497,7 +1882,8 @@ } ], "return": { - "description": "if the x/y coords are within this polygon" + "description": "if the x/y coords are within this Rectangle", + "type": "Boolean" }, "class": "Rectangle" }, @@ -1518,7 +1904,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 22, + "line": 23, "description": "The scale factor of the object.", "itemtype": "property", "name": "scale", @@ -1527,7 +1913,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 29, + "line": 31, "description": "The pivot point of the displayObject that it rotates around", "itemtype": "property", "name": "pivot", @@ -1536,7 +1922,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 36, + "line": 39, "description": "The rotation of the object in radians.", "itemtype": "property", "name": "rotation", @@ -1545,7 +1931,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 43, + "line": 47, "description": "The opacity of the object.", "itemtype": "property", "name": "alpha", @@ -1554,7 +1940,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 50, + "line": 55, "description": "The visibility of the object.", "itemtype": "property", "name": "visible", @@ -1563,34 +1949,16 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 58, - "description": "[read-only] The display object container that contains this display object.", + "line": 63, + "description": "This is the defined area that will pick up mouse / touch events. It is null by default.\nSetting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)", "itemtype": "property", - "name": "parent", - "type": "DisplayObjectContainer", - "class": "DisplayObject" - }, - { - "file": "src/pixi/display/DisplayObject.js", - "line": 65, - "description": "[read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.", - "itemtype": "property", - "name": "stage", - "type": "Stage", + "name": "hitArea", + "type": "Rectangle|Circle|Ellipse|Polygon", "class": "DisplayObject" }, { "file": "src/pixi/display/DisplayObject.js", "line": 72, - "description": "This is the defined area that will pick up mouse / touch events. It is null by default.\nSetting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)", - "itemtype": "property", - "name": "hitArea", - "type": "Rectangle", - "class": "DisplayObject" - }, - { - "file": "src/pixi/display/DisplayObject.js", - "line": 98, "description": "This is used to indicate if the displayObject should display a mouse hand cursor on rollover", "itemtype": "property", "name": "buttonMode", @@ -1599,7 +1967,104 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 109, + "line": 80, + "description": "Can this object be rendered", + "itemtype": "property", + "name": "renderable", + "type": "Boolean", + "class": "DisplayObject" + }, + { + "file": "src/pixi/display/DisplayObject.js", + "line": 88, + "description": "[read-only] The display object container that contains this display object.", + "itemtype": "property", + "name": "parent", + "type": "DisplayObjectContainer", + "readonly": "", + "class": "DisplayObject" + }, + { + "file": "src/pixi/display/DisplayObject.js", + "line": 97, + "description": "[read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.", + "itemtype": "property", + "name": "stage", + "type": "Stage", + "readonly": "", + "class": "DisplayObject" + }, + { + "file": "src/pixi/display/DisplayObject.js", + "line": 106, + "description": "[read-only] The multiplied alpha of the displayobject", + "itemtype": "property", + "name": "worldAlpha", + "type": "Number", + "readonly": "", + "class": "DisplayObject" + }, + { + "file": "src/pixi/display/DisplayObject.js", + "line": 115, + "description": "[read-only] Whether or not the object is interactive, do not toggle directly! use the `interactive` property", + "itemtype": "property", + "name": "_interactive", + "type": "Boolean", + "readonly": "", + "access": "private", + "tagname": "", + "class": "DisplayObject" + }, + { + "file": "src/pixi/display/DisplayObject.js", + "line": 125, + "description": "[read-only] Current transform of the object based on world (parent) factors", + "itemtype": "property", + "name": "worldTransform", + "type": "Mat3", + "readonly": "", + "access": "private", + "tagname": "", + "class": "DisplayObject" + }, + { + "file": "src/pixi/display/DisplayObject.js", + "line": 135, + "description": "[read-only] Current transform of the object locally", + "itemtype": "property", + "name": "localTransform", + "type": "Mat3", + "readonly": "", + "access": "private", + "tagname": "", + "class": "DisplayObject" + }, + { + "file": "src/pixi/display/DisplayObject.js", + "line": 145, + "description": "[NYI] Unkown", + "itemtype": "property", + "name": "color", + "type": "Array<>", + "access": "private", + "tagname": "", + "class": "DisplayObject" + }, + { + "file": "src/pixi/display/DisplayObject.js", + "line": 154, + "description": "[NYI] Holds whether or not this object is dynamic, for rendering optimization", + "itemtype": "property", + "name": "dynamic", + "type": "Boolean", + "access": "private", + "tagname": "", + "class": "DisplayObject" + }, + { + "file": "src/pixi/display/DisplayObject.js", + "line": 174, "description": "A callback that is used when the users clicks on the displayObject with their mouse", "itemtype": "method", "name": "click", @@ -1614,7 +2079,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 115, + "line": 180, "description": "A callback that is used when the user clicks the mouse down over the sprite", "itemtype": "method", "name": "mousedown", @@ -1629,7 +2094,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 121, + "line": 186, "description": "A callback that is used when the user releases the mouse that was over the displayObject\nfor this callback to be fired the mouse must have been pressed down over the displayObject", "itemtype": "method", "name": "mouseup", @@ -1644,7 +2109,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 128, + "line": 193, "description": "A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject\nfor this callback to be fired, The touch must have started over the displayObject", "itemtype": "method", "name": "mouseupoutside", @@ -1659,7 +2124,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 135, + "line": 200, "description": "A callback that is used when the users mouse rolls over the displayObject", "itemtype": "method", "name": "mouseover", @@ -1674,7 +2139,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 141, + "line": 206, "description": "A callback that is used when the users mouse leaves the displayObject", "itemtype": "method", "name": "mouseout", @@ -1689,7 +2154,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 152, + "line": 217, "description": "A callback that is used when the users taps on the sprite with their finger\nbasically a touch version of click", "itemtype": "method", "name": "tap", @@ -1704,7 +2169,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 159, + "line": 224, "description": "A callback that is used when the user touch's over the displayObject", "itemtype": "method", "name": "touchstart", @@ -1719,7 +2184,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 165, + "line": 230, "description": "A callback that is used when the user releases a touch over the displayObject", "itemtype": "method", "name": "touchend", @@ -1734,7 +2199,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 171, + "line": 236, "description": "A callback that is used when the user releases the touch that was over the displayObject\nfor this callback to be fired, The touch must have started over the sprite", "itemtype": "method", "name": "touchendoutside", @@ -1749,7 +2214,7 @@ }, { "file": "src/pixi/display/DisplayObject.js", - "line": 193, + "line": 247, "description": "[Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default\nInstead of using this function you can now simply set the interactive property to true or false", "itemtype": "method", "name": "setInteractive", @@ -1760,31 +2225,36 @@ "type": "Boolean" } ], + "deprecated": true, + "deprecationMessage": "Simply set the `interactive` property directly", "class": "DisplayObject" }, { "file": "src/pixi/display/DisplayObject.js", - "line": 204, + "line": 260, "description": "Indicates if the sprite will have touch and mouse interactivity. It is false by default", "itemtype": "property", "name": "interactive", "type": "Boolean", + "default": "false", "class": "DisplayObject" }, { "file": "src/pixi/display/DisplayObject.js", - "line": 222, + "line": 280, "description": "Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it.\nIn PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping.\nTo remove a mask, set this property to null.", "itemtype": "property", "name": "mask", - "type": "PIXI.Graphics", + "type": "Graphics", "class": "DisplayObject" }, { "file": "src/pixi/display/DisplayObject.js", - "line": 399, - "access": "private", - "tagname": "", + "line": 318, + "description": "Sets the filters for the displayObject. \n* IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer.\nTo remove filters simply set this property to 'null'", + "itemtype": "property", + "name": "filters", + "type": "Array An array of filters", "class": "DisplayObject" }, { @@ -1795,23 +2265,24 @@ }, { "file": "src/pixi/display/DisplayObjectContainer.js", - "line": 16, + "line": 18, "description": "[read-only] The of children of this container.", "itemtype": "property", "name": "children", - "type": "Array", + "type": "Array", + "readonly": "", "class": "DisplayObjectContainer" }, { "file": "src/pixi/display/DisplayObjectContainer.js", - "line": 42, + "line": 32, "description": "Adds a child to the container.", "itemtype": "method", "name": "addChild", "params": [ { - "name": "DisplayObject", - "description": "", + "name": "child", + "description": "The DisplayObject to add to the container", "type": "DisplayObject" } ], @@ -1819,19 +2290,19 @@ }, { "file": "src/pixi/display/DisplayObjectContainer.js", - "line": 139, + "line": 120, "description": "Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown", "itemtype": "method", "name": "addChildAt", "params": [ { - "name": "DisplayObject", - "description": "", + "name": "child", + "description": "The child to add", "type": "DisplayObject" }, { "name": "index", - "description": "", + "description": "The index to place the child in", "type": "Number" } ], @@ -1839,61 +2310,56 @@ }, { "file": "src/pixi/display/DisplayObjectContainer.js", - "line": 227, - "description": "Swaps the depth of 2 displayObjects", + "line": 207, + "description": "[NYI] Swaps the depth of 2 displayObjects", "itemtype": "method", "name": "swapChildren", "params": [ { - "name": "DisplayObject", + "name": "child", "description": "", "type": "DisplayObject" }, { - "name": "DisplayObject2", + "name": "child2", "description": "", "type": "DisplayObject" } ], + "access": "private", + "tagname": "", + "class": "DisplayObjectContainer" + }, + { + "file": "src/pixi/display/DisplayObjectContainer.js", + "line": 256, + "description": "Returns the Child at the specified index", + "itemtype": "method", + "name": "getChildAt", + "params": [ + { + "name": "index", + "description": "The index to get the child from", + "type": "Number" + } + ], "class": "DisplayObjectContainer" }, { "file": "src/pixi/display/DisplayObjectContainer.js", "line": 274, - "description": "Returns the Child at the specified index", - "itemtype": "method", - "name": "getChildAt", - "params": [ - { - "name": "index", - "description": "", - "type": "Number" - } - ], - "class": "DisplayObjectContainer" - }, - { - "file": "src/pixi/display/DisplayObjectContainer.js", - "line": 291, "description": "Removes a child from the container.", "itemtype": "method", "name": "removeChild", "params": [ { - "name": "DisplayObject", - "description": "", + "name": "child", + "description": "The DisplayObject to remove", "type": "DisplayObject" } ], "class": "DisplayObjectContainer" }, - { - "file": "src/pixi/display/DisplayObjectContainer.js", - "line": 358, - "access": "private", - "tagname": "", - "class": "DisplayObjectContainer" - }, { "file": "src/pixi/display/MovieClip.js", "line": 1, @@ -1902,7 +2368,7 @@ }, { "file": "src/pixi/display/MovieClip.js", - "line": 16, + "line": 17, "description": "The array of textures that make up the animation", "itemtype": "property", "name": "textures", @@ -1911,34 +2377,27 @@ }, { "file": "src/pixi/display/MovieClip.js", - "line": 23, - "description": "[read only] The index MovieClips current frame (this may not have to be a whole number)", - "itemtype": "property", - "name": "currentFrame", - "type": "Number", - "class": "MovieClip" - }, - { - "file": "src/pixi/display/MovieClip.js", - "line": 30, + "line": 25, "description": "The speed that the MovieClip will play at. Higher is faster, lower is slower", "itemtype": "property", "name": "animationSpeed", "type": "Number", + "default": "1", "class": "MovieClip" }, { "file": "src/pixi/display/MovieClip.js", - "line": 37, + "line": 34, "description": "Whether or not the movie clip repeats after playing.", "itemtype": "property", "name": "loop", "type": "Boolean", + "default": "true", "class": "MovieClip" }, { "file": "src/pixi/display/MovieClip.js", - "line": 44, + "line": 43, "description": "Function to call when a MovieClip finishes playing", "itemtype": "property", "name": "onComplete", @@ -1948,15 +2407,38 @@ { "file": "src/pixi/display/MovieClip.js", "line": 51, - "description": "[read only] indicates if the MovieClip is currently playing", + "description": "[read-only] The index MovieClips current frame (this may not have to be a whole number)", "itemtype": "property", - "name": "playing", - "type": "Boolean", + "name": "currentFrame", + "type": "Number", + "default": "0", + "readonly": "", "class": "MovieClip" }, { "file": "src/pixi/display/MovieClip.js", - "line": 63, + "line": 61, + "description": "[read-only] Indicates if the MovieClip is currently playing", + "itemtype": "property", + "name": "playing", + "type": "Boolean", + "readonly": "", + "class": "MovieClip" + }, + { + "file": "src/pixi/display/MovieClip.js", + "line": 75, + "description": "[read-only] totalFrames is the total number of frames in the MovieClip. This is the same as number of textures\nassigned to the MovieClip.", + "itemtype": "property", + "name": "totalFrames", + "type": "Number", + "default": "0", + "readonly": "", + "class": "MovieClip" + }, + { + "file": "src/pixi/display/MovieClip.js", + "line": 92, "description": "Stops the MovieClip", "itemtype": "method", "name": "stop", @@ -1964,7 +2446,7 @@ }, { "file": "src/pixi/display/MovieClip.js", - "line": 72, + "line": 102, "description": "Plays the MovieClip", "itemtype": "method", "name": "play", @@ -1972,7 +2454,7 @@ }, { "file": "src/pixi/display/MovieClip.js", - "line": 81, + "line": 112, "description": "Stops the MovieClip and goes to a specific frame", "itemtype": "method", "name": "gotoAndStop", @@ -1987,7 +2469,7 @@ }, { "file": "src/pixi/display/MovieClip.js", - "line": 94, + "line": 126, "description": "Goes to a specific frame and begins playing the MovieClip", "itemtype": "method", "name": "gotoAndPlay", @@ -2008,7 +2490,7 @@ }, { "file": "src/pixi/display/Sprite.js", - "line": 21, + "line": 23, "description": "The anchor sets the origin point of the texture.\nThe default is 0,0 this means the textures origin is the top left \nSetting than anchor to 0.5,0.5 means the textures origin is centered\nSetting the anchor to 1,1 would mean the textures origin points will be the bottom right", "itemtype": "property", "name": "anchor", @@ -2017,7 +2499,7 @@ }, { "file": "src/pixi/display/Sprite.js", - "line": 31, + "line": 34, "description": "The texture that the sprite is using", "itemtype": "property", "name": "texture", @@ -2026,34 +2508,57 @@ }, { "file": "src/pixi/display/Sprite.js", - "line": 38, + "line": 42, "description": "The blend mode of sprite.\ncurrently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN", "itemtype": "property", "name": "blendMode", - "type": "uint", + "type": "Number", "class": "Sprite" }, { "file": "src/pixi/display/Sprite.js", - "line": 46, + "line": 51, "description": "The width of the sprite (this is initially set by the texture)", "itemtype": "property", - "name": "width", - "type": "#Number", + "name": "_width", + "type": "Number", + "access": "private", + "tagname": "", "class": "Sprite" }, { "file": "src/pixi/display/Sprite.js", - "line": 53, + "line": 60, "description": "The height of the sprite (this is initially set by the texture)", "itemtype": "property", - "name": "height", - "type": "#Number", + "name": "_height", + "type": "Number", + "access": "private", + "tagname": "", "class": "Sprite" }, { "file": "src/pixi/display/Sprite.js", - "line": 103, + "line": 86, + "description": "The width of the sprite, setting this will actually modify the scale to acheive the value set", + "itemtype": "property", + "name": "width", + "type": "Number", + "class": "Sprite" + }, + { + "file": "src/pixi/display/Sprite.js", + "line": 102, + "description": "The height of the sprite, setting this will actually modify the scale to acheive the value set", + "itemtype": "property", + "name": "height", + "type": "Number", + "class": "Sprite" + }, + { + "file": "src/pixi/display/Sprite.js", + "line": 118, + "description": "Sets the texture of the sprite", "itemtype": "method", "name": "setTexture", "params": [ @@ -2067,14 +2572,23 @@ }, { "file": "src/pixi/display/Sprite.js", - "line": 119, + "line": 145, + "description": "When the texture is updated, this event will fire to update the scale and frame", + "itemtype": "method", + "name": "onTextureUpdate", + "params": [ + { + "name": "event", + "description": "" + } + ], "access": "private", "tagname": "", "class": "Sprite" }, { "file": "src/pixi/display/Sprite.js", - "line": 135, + "line": 165, "description": "Helper function that creates a sprite that will contain a texture from the TextureCache based on the frameId\n The frame ids are created when a Texture packer file has been loaded", "itemtype": "method", "name": "fromFrame", @@ -2094,15 +2608,16 @@ }, { "file": "src/pixi/display/Sprite.js", - "line": 151, + "line": 182, "description": "Helper function that creates a sprite that will contain a texture based on an image url\n If the image is not in the texture cache it will be loaded", "itemtype": "method", "name": "fromImage", "static": 1, "params": [ { - "name": "The", - "description": "image url of the texture" + "name": "imageId", + "description": "The image url of the texture", + "type": "String" } ], "return": { @@ -2119,21 +2634,70 @@ }, { "file": "src/pixi/display/Stage.js", - "line": 42, - "itemtype": "method", - "name": "updateTransform", - "internal": "", + "line": 18, + "description": "[read-only] Current transform of the object based on world (parent) factors", + "itemtype": "property", + "name": "worldTransform", + "type": "Mat3", + "readonly": "", + "access": "private", + "tagname": "", "class": "Stage" }, { "file": "src/pixi/display/Stage.js", - "line": 65, + "line": 28, + "description": "Whether or not the stage is interactive", + "itemtype": "property", + "name": "interactive", + "type": "Boolean", + "class": "Stage" + }, + { + "file": "src/pixi/display/Stage.js", + "line": 36, + "description": "The interaction manage for this stage, manages all interactive activity on the stage", + "itemtype": "property", + "name": "interactive", + "type": "InteractionManager", + "class": "Stage" + }, + { + "file": "src/pixi/display/Stage.js", + "line": 44, + "description": "Whether the stage is dirty and needs to have interactions updated", + "itemtype": "property", + "name": "dirty", + "type": "Boolean", + "access": "private", + "tagname": "", + "class": "Stage" + }, + { + "file": "src/pixi/display/Stage.js", + "line": 70, + "description": "Sets another DOM element which can receive mouse/touch interactions instead of the default Canvas element.\nThis is useful for when you have other DOM elements ontop of the Canvas element.", + "itemtype": "method", + "name": "setInteractionDelegate", + "params": [ + { + "name": "domElement", + "description": "This new domElement which will receive mouse/touch events", + "type": "DOMElement" + } + ], + "class": "Stage" + }, + { + "file": "src/pixi/display/Stage.js", + "line": 109, + "description": "Sets the background color for the stage", "itemtype": "method", "name": "setBackgroundColor", "params": [ { "name": "backgroundColor", - "description": "", + "description": "the color of the background, easiest way to pass this in is in hex format\n\t\tlike: 0xFFFFFF for white", "type": "Number" } ], @@ -2141,7 +2705,7 @@ }, { "file": "src/pixi/display/Stage.js", - "line": 78, + "line": 125, "description": "This will return the point containing global coords of the mouse.", "itemtype": "method", "name": "getMousePosition", @@ -2157,6 +2721,51 @@ "author": "Mat Groves http://matgroves.com/ @Doormat23", "class": "CustomRenderable" }, + { + "file": "src/pixi/extras/CustomRenderable.js", + "line": 24, + "description": "If this object is being rendered by a CanvasRenderer it will call this callback", + "itemtype": "method", + "name": "renderCanvas", + "params": [ + { + "name": "renderer", + "description": "The renderer instance", + "type": "CanvasRenderer" + } + ], + "class": "CustomRenderable" + }, + { + "file": "src/pixi/extras/CustomRenderable.js", + "line": 35, + "description": "If this object is being rendered by a WebGLRenderer it will call this callback to initialize", + "itemtype": "method", + "name": "initWebGL", + "params": [ + { + "name": "renderer", + "description": "The renderer instance", + "type": "WebGLRenderer" + } + ], + "class": "CustomRenderable" + }, + { + "file": "src/pixi/extras/CustomRenderable.js", + "line": 46, + "description": "If this object is being rendered by a WebGLRenderer it will call this callback", + "itemtype": "method", + "name": "renderWebGL", + "params": [ + { + "name": "renderer", + "description": "The renderer instance", + "type": "WebGLRenderer" + } + ], + "class": "CustomRenderable" + }, { "file": "src/pixi/extras/Rope.js", "line": 1, @@ -2171,20 +2780,10 @@ }, { "file": "src/pixi/extras/Spine.js", - "line": 308, + "line": 327, "description": "cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of", "class": "Spine" }, - { - "file": "src/pixi/extras/Spine.js", - "line": 604, - "class": "Spine" - }, - { - "file": "src/pixi/extras/Spine.js", - "line": 611, - "class": "Spine" - }, { "file": "src/pixi/extras/Spine.js", "line": 618, @@ -2192,12 +2791,12 @@ }, { "file": "src/pixi/extras/Spine.js", - "line": 626, + "line": 625, "class": "Spine" }, { "file": "src/pixi/extras/Spine.js", - "line": 633, + "line": 632, "class": "Spine" }, { @@ -2207,27 +2806,27 @@ }, { "file": "src/pixi/extras/Spine.js", - "line": 675, + "line": 647, "class": "Spine" }, { "file": "src/pixi/extras/Spine.js", - "line": 683, + "line": 654, "class": "Spine" }, { "file": "src/pixi/extras/Spine.js", - "line": 698, + "line": 689, "class": "Spine" }, { "file": "src/pixi/extras/Spine.js", - "line": 702, + "line": 697, "class": "Spine" }, { "file": "src/pixi/extras/Spine.js", - "line": 709, + "line": 712, "class": "Spine" }, { @@ -2242,33 +2841,33 @@ }, { "file": "src/pixi/extras/Spine.js", - "line": 735, + "line": 730, + "class": "Spine" + }, + { + "file": "src/pixi/extras/Spine.js", + "line": 737, + "class": "Spine" + }, + { + "file": "src/pixi/extras/Spine.js", + "line": 749, "description": "from the new skin are attached if the corresponding attachment from the old skin was attached.", "class": "Spine" }, { "file": "src/pixi/extras/Spine.js", - "line": 742, + "line": 756, "class": "Spine" }, { "file": "src/pixi/extras/Spine.js", - "line": 746, + "line": 760, "class": "Spine" }, { "file": "src/pixi/extras/Spine.js", - "line": 755, - "class": "Spine" - }, - { - "file": "src/pixi/extras/Spine.js", - "line": 948, - "class": "Spine" - }, - { - "file": "src/pixi/extras/Spine.js", - "line": 954, + "line": 769, "class": "Spine" }, { @@ -2283,12 +2882,22 @@ }, { "file": "src/pixi/extras/Spine.js", - "line": 984, + "line": 972, "class": "Spine" }, { "file": "src/pixi/extras/Spine.js", - "line": 1401, + "line": 978, + "class": "Spine" + }, + { + "file": "src/pixi/extras/Spine.js", + "line": 996, + "class": "Spine" + }, + { + "file": "src/pixi/extras/Spine.js", + "line": 1415, "class": "Spine" }, { @@ -2305,7 +2914,34 @@ }, { "file": "src/pixi/extras/TilingSprite.js", - "line": 22, + "line": 19, + "description": "The texture that the sprite is using", + "itemtype": "property", + "name": "texture", + "type": "Texture", + "class": "TilingSprite" + }, + { + "file": "src/pixi/extras/TilingSprite.js", + "line": 27, + "description": "The width of the tiling sprite", + "itemtype": "property", + "name": "width", + "type": "Number", + "class": "TilingSprite" + }, + { + "file": "src/pixi/extras/TilingSprite.js", + "line": 35, + "description": "The height of the tiling sprite", + "itemtype": "property", + "name": "height", + "type": "Number", + "class": "TilingSprite" + }, + { + "file": "src/pixi/extras/TilingSprite.js", + "line": 43, "description": "The scaling of the image that is being tiled", "itemtype": "property", "name": "tileScale", @@ -2314,21 +2950,232 @@ }, { "file": "src/pixi/extras/TilingSprite.js", - "line": 28, + "line": 51, "description": "The offset position of the image that is being tiled", "itemtype": "property", "name": "tilePosition", "type": "Point", "class": "TilingSprite" }, + { + "file": "src/pixi/extras/TilingSprite.js", + "line": 68, + "description": "Sets the texture of the tiling sprite", + "itemtype": "method", + "name": "setTexture", + "params": [ + { + "name": "texture", + "description": "The PIXI texture that is displayed by the sprite", + "type": "Texture" + } + ], + "class": "TilingSprite" + }, + { + "file": "src/pixi/extras/TilingSprite.js", + "line": 84, + "description": "When the texture is updated, this event will fire to update the frame", + "itemtype": "method", + "name": "onTextureUpdate", + "params": [ + { + "name": "event", + "description": "" + } + ], + "access": "private", + "tagname": "", + "class": "TilingSprite" + }, + { + "file": "src/pixi/filters/AbstractFilter.js", + "line": 1, + "author": "Mat Groves http://matgroves.com/ @Doormat23", + "class": "AbstractFilter" + }, + { + "file": "src/pixi/filters/AbstractFilter.js", + "line": 16, + "description": "An array of passes - some filters contain a few steps this array simply stores the steps in a liniear fashion.\nFor example the blur filter has two passes blurX and blurY.", + "itemtype": "property", + "name": "passes", + "type": "Array an array of filter objects", + "access": "private", + "tagname": "", + "class": "AbstractFilter" + }, + { + "file": "src/pixi/filters/AbstractFilter.js", + "line": 29, + "itemtype": "property", + "name": "uniforms", + "access": "private", + "tagname": "", + "class": "AbstractFilter" + }, + { + "file": "src/pixi/filters/BlurFilter.js", + "line": 1, + "author": "Mat Groves http://matgroves.com/ @Doormat23", + "class": "BlurFilter" + }, + { + "file": "src/pixi/filters/BlurFilter.js", + "line": 24, + "description": "Sets the strength of both the blurX and blurY properties simultaneously", + "itemtype": "property", + "name": "blur", + "type": "Number the strength of the blur", + "default": "2", + "class": "BlurFilter" + }, + { + "file": "src/pixi/filters/BlurFilter.js", + "line": 40, + "description": "Sets the strength of the blurX property simultaneously", + "itemtype": "property", + "name": "blurX", + "type": "Number the strength of the blurX", + "default": "2", + "class": "BlurFilter" + }, + { + "file": "src/pixi/filters/BlurFilter.js", + "line": 56, + "description": "Sets the strength of the blurX property simultaneously", + "itemtype": "property", + "name": "blurY", + "type": "Number the strength of the blurY", + "default": "2", + "class": "BlurFilter" + }, + { + "file": "src/pixi/filters/BlurXFilter.js", + "line": 1, + "author": "Mat Groves http://matgroves.com/ @Doormat23", + "class": "ColorMatrixFilter" + }, + { + "file": "src/pixi/filters/BlurYFilter.js", + "line": 1, + "author": "Mat Groves http://matgroves.com/ @Doormat23", + "class": "ColorMatrixFilter" + }, + { + "file": "src/pixi/filters/ColorMatrixFilter.js", + "line": 1, + "author": "Mat Groves http://matgroves.com/ @Doormat23", + "class": "ColorMatrixFilter" + }, + { + "file": "src/pixi/filters/ColorMatrixFilter.js", + "line": 45, + "description": "Sets the matrix of the color matrix filter", + "itemtype": "property", + "name": "matrix", + "type": "Array and array of 26 numbers", + "default": "[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]", + "class": "ColorMatrixFilter" + }, + { + "file": "src/pixi/filters/DisplacementFilter.js", + "line": 1, + "author": "Mat Groves http://matgroves.com/ @Doormat23", + "class": "DisplacementFilter" + }, + { + "file": "src/pixi/filters/DisplacementFilter.js", + "line": 92, + "description": "The texture used for the displacemtent map * must be power of 2 texture at the moment", + "itemtype": "property", + "name": "map", + "type": "Texture", + "class": "DisplacementFilter" + }, + { + "file": "src/pixi/filters/DisplacementFilter.js", + "line": 107, + "description": "The multiplier used to scale the displacement result from the map calculation.", + "itemtype": "property", + "name": "scale", + "type": "Point", + "class": "DisplacementFilter" + }, + { + "file": "src/pixi/filters/DisplacementFilter.js", + "line": 122, + "description": "The offset used to move the displacement map.", + "itemtype": "property", + "name": "offset", + "type": "Point", + "class": "DisplacementFilter" + }, { "file": "src/pixi/filters/FilterBlock.js", "line": 1, "author": "Mat Groves http://matgroves.com/ @Doormat23", - "class": "AssetLoader" + "class": "GreyFilter" }, { - "file": "src/pixi/filters/MaskFilter.js", + "file": "src/pixi/filters/GreyFilter.js", + "line": 1, + "author": "Mat Groves http://matgroves.com/ @Doormat23", + "class": "GreyFilter" + }, + { + "file": "src/pixi/filters/GreyFilter.js", + "line": 40, + "description": "The strength of the grey. 1 will make the object black and white, 0 will make the object its normal color", + "itemtype": "property", + "name": "grey", + "class": "GreyFilter" + }, + { + "file": "src/pixi/filters/InvertFilter.js", + "line": 1, + "author": "Mat Groves http://matgroves.com/ @Doormat23", + "class": "InvertFilter" + }, + { + "file": "src/pixi/filters/InvertFilter.js", + "line": 41, + "description": "The strength of the invert. 1 will fully invert the colors, 0 will make the object its normal color", + "itemtype": "property", + "name": "invert", + "class": "InvertFilter" + }, + { + "file": "src/pixi/filters/PixelateFilter.js", + "line": 1, + "author": "Mat Groves http://matgroves.com/ @Doormat23", + "class": "PixelateFilter" + }, + { + "file": "src/pixi/filters/PixelateFilter.js", + "line": 50, + "description": "This a point that describes the size of the blocs. x is the width of the block and y is the the height", + "itemtype": "property", + "name": "size", + "type": "Point", + "class": "PixelateFilter" + }, + { + "file": "src/pixi/filters/SepiaFilter.js", + "line": 1, + "description": "/**\n * @author Mat Groves http://matgroves.com/ @Doormat23", + "class": "SepiaFilter" + }, + { + "file": "src/pixi/filters/SepiaFilter.js", + "line": 44, + "description": "The strength of the sepia. 1 will apply the full sepia effect, 0 will make the object its normal color", + "itemtype": "property", + "name": "sepia", + "class": "SepiaFilter" + }, + { + "file": "src/pixi/filters/SmartBlurFilter.js", "line": 1, "author": "Mat Groves http://matgroves.com/ @Doormat23", "class": "AssetLoader" @@ -2341,16 +3188,34 @@ }, { "file": "src/pixi/loaders/AssetLoader.js", - "line": 18, + "line": 25, "description": "The array of asset URLs that are going to be loaded", "itemtype": "property", "name": "assetURLs", - "type": "Array", + "type": "Array", + "class": "AssetLoader" + }, + { + "file": "src/pixi/loaders/AssetLoader.js", + "line": 33, + "description": "Whether the requests should be treated as cross origin", + "itemtype": "property", + "name": "crossorigin", + "type": "Boolean", "class": "AssetLoader" }, { "file": "src/pixi/loaders/AssetLoader.js", "line": 41, + "description": "Maps file extension to loader types", + "itemtype": "property", + "name": "loadersByType", + "type": "Object", + "class": "AssetLoader" + }, + { + "file": "src/pixi/loaders/AssetLoader.js", + "line": 61, "description": "Fired when an item has loaded", "itemtype": "event", "name": "onProgress", @@ -2358,7 +3223,7 @@ }, { "file": "src/pixi/loaders/AssetLoader.js", - "line": 46, + "line": 66, "description": "Fired when all the assets have loaded", "itemtype": "event", "name": "onComplete", @@ -2366,14 +3231,18 @@ }, { "file": "src/pixi/loaders/AssetLoader.js", - "line": 54, - "description": "This will begin loading the assets sequentially", + "line": 74, + "description": "Starts loading the assets sequentially", + "itemtype": "method", + "name": "load", "class": "AssetLoader" }, { "file": "src/pixi/loaders/AssetLoader.js", - "line": 82, + "line": 104, "description": "Invoked after each file is loaded", + "itemtype": "method", + "name": "onAssetLoaded", "access": "private", "tagname": "", "class": "AssetLoader" @@ -2384,24 +3253,67 @@ "author": "Mat Groves http://matgroves.com/ @Doormat23", "class": "BitmapFontLoader" }, + { + "file": "src/pixi/loaders/BitmapFontLoader.js", + "line": 26, + "description": "The url of the bitmap font data", + "itemtype": "property", + "name": "url", + "type": "String", + "class": "BitmapFontLoader" + }, { "file": "src/pixi/loaders/BitmapFontLoader.js", "line": 34, - "description": "This will begin loading the JSON file", + "description": "Whether the requests should be treated as cross origin", + "itemtype": "property", + "name": "crossorigin", + "type": "Boolean", + "class": "BitmapFontLoader" + }, + { + "file": "src/pixi/loaders/BitmapFontLoader.js", + "line": 42, + "description": "[read-only] The base url of the bitmap font data", + "itemtype": "property", + "name": "baseUrl", + "type": "String", + "readonly": "", "class": "BitmapFontLoader" }, { "file": "src/pixi/loaders/BitmapFontLoader.js", "line": 51, - "description": "Invoked when XML file is loaded", + "description": "[read-only] The texture of the bitmap font", + "itemtype": "property", + "name": "baseUrl", + "type": "String", + "class": "BitmapFontLoader" + }, + { + "file": "src/pixi/loaders/BitmapFontLoader.js", + "line": 63, + "description": "Loads the XML font data", + "itemtype": "method", + "name": "load", + "class": "BitmapFontLoader" + }, + { + "file": "src/pixi/loaders/BitmapFontLoader.js", + "line": 82, + "description": "Invoked when XML file is loaded, parses the data", + "itemtype": "method", + "name": "onXMLLoaded", "access": "private", "tagname": "", "class": "BitmapFontLoader" }, { "file": "src/pixi/loaders/BitmapFontLoader.js", - "line": 121, + "line": 153, "description": "Invoked when all files are loaded (xml/fnt and texture)", + "itemtype": "method", + "name": "onLoaded", "access": "private", "tagname": "", "class": "BitmapFontLoader" @@ -2414,18 +3326,62 @@ }, { "file": "src/pixi/loaders/ImageLoader.js", - "line": 24, - "description": "Loads image or takes it from cache", + "line": 20, + "description": "The texture being loaded", + "itemtype": "property", + "name": "texture", + "type": "Texture", "class": "ImageLoader" }, { "file": "src/pixi/loaders/ImageLoader.js", - "line": 43, + "line": 28, + "description": "if the image is loaded with loadFramedSpriteSheet\nframes will contain the sprite sheet frames", + "class": "ImageLoader" + }, + { + "file": "src/pixi/loaders/ImageLoader.js", + "line": 39, + "description": "Loads image or takes it from cache", + "itemtype": "method", + "name": "load", + "class": "ImageLoader" + }, + { + "file": "src/pixi/loaders/ImageLoader.js", + "line": 60, "description": "Invoked when image file is loaded or it is already cached and ready to use", + "itemtype": "method", + "name": "onLoaded", "access": "private", "tagname": "", "class": "ImageLoader" }, + { + "file": "src/pixi/loaders/ImageLoader.js", + "line": 71, + "description": "Loads image and split it to uniform sized frames", + "itemtype": "method", + "name": "loadFramedSpriteSheet", + "params": [ + { + "name": "frameWidth", + "description": "with of each frame", + "type": "Number" + }, + { + "name": "frameHeight", + "description": "height of each frame", + "type": "Number" + }, + { + "name": "textureName", + "description": "if given, the frames will be cached in - format", + "type": "String" + } + ], + "class": "ImageLoader" + }, { "file": "src/pixi/loaders/JsonLoader.js", "line": 1, @@ -2434,30 +3390,76 @@ }, { "file": "src/pixi/loaders/JsonLoader.js", - "line": 28, - "description": "This will begin loading the JSON file", + "line": 19, + "description": "The url of the bitmap font data", + "itemtype": "property", + "name": "url", + "type": "String", "class": "JsonLoader" }, { "file": "src/pixi/loaders/JsonLoader.js", - "line": 43, + "line": 27, + "description": "Whether the requests should be treated as cross origin", + "itemtype": "property", + "name": "crossorigin", + "type": "Boolean", + "class": "JsonLoader" + }, + { + "file": "src/pixi/loaders/JsonLoader.js", + "line": 35, + "description": "[read-only] The base url of the bitmap font data", + "itemtype": "property", + "name": "baseUrl", + "type": "String", + "readonly": "", + "class": "JsonLoader" + }, + { + "file": "src/pixi/loaders/JsonLoader.js", + "line": 44, + "description": "[read-only] Whether the data has loaded yet", + "itemtype": "property", + "name": "loaded", + "type": "Boolean", + "readonly": "", + "class": "JsonLoader" + }, + { + "file": "src/pixi/loaders/JsonLoader.js", + "line": 58, + "description": "Loads the JSON data", + "itemtype": "method", + "name": "load", + "class": "JsonLoader" + }, + { + "file": "src/pixi/loaders/JsonLoader.js", + "line": 75, "description": "Invoke when JSON file is loaded", + "itemtype": "method", + "name": "onJSONLoaded", "access": "private", "tagname": "", "class": "JsonLoader" }, { "file": "src/pixi/loaders/JsonLoader.js", - "line": 108, + "line": 140, "description": "Invoke when json file loaded", + "itemtype": "method", + "name": "onLoaded", "access": "private", "tagname": "", "class": "JsonLoader" }, { "file": "src/pixi/loaders/JsonLoader.js", - "line": 120, + "line": 154, "description": "Invoke when error occured", + "itemtype": "method", + "name": "onError", "access": "private", "tagname": "", "class": "JsonLoader" @@ -2470,8 +3472,56 @@ }, { "file": "src/pixi/loaders/SpineLoader.js", - "line": 54, + "line": 28, + "description": "The url of the bitmap font data", + "itemtype": "property", + "name": "url", + "type": "String", + "class": "Spine" + }, + { + "file": "src/pixi/loaders/SpineLoader.js", + "line": 36, + "description": "Whether the requests should be treated as cross origin", + "itemtype": "property", + "name": "crossorigin", + "type": "Boolean", + "class": "Spine" + }, + { + "file": "src/pixi/loaders/SpineLoader.js", + "line": 44, + "description": "[read-only] Whether the data has loaded yet", + "itemtype": "property", + "name": "loaded", + "type": "Boolean", + "readonly": "", + "class": "Spine" + }, + { + "file": "src/pixi/loaders/SpineLoader.js", + "line": 56, + "description": "Loads the JSON data", + "itemtype": "method", + "name": "load", + "class": "Spine" + }, + { + "file": "src/pixi/loaders/SpineLoader.js", + "line": 72, "description": "Invoke when JSON file is loaded", + "itemtype": "method", + "name": "onJSONLoaded", + "access": "private", + "tagname": "", + "class": "Spine" + }, + { + "file": "src/pixi/loaders/SpineLoader.js", + "line": 87, + "description": "Invoke when JSON file is loaded", + "itemtype": "method", + "name": "onLoaded", "access": "private", "tagname": "", "class": "Spine" @@ -2484,22 +3534,74 @@ }, { "file": "src/pixi/loaders/SpriteSheetLoader.js", - "line": 37, - "description": "This will begin loading the JSON file", + "line": 29, + "description": "The url of the bitmap font data", + "itemtype": "property", + "name": "url", + "type": "String", "class": "SpriteSheetLoader" }, { "file": "src/pixi/loaders/SpriteSheetLoader.js", - "line": 50, + "line": 37, + "description": "Whether the requests should be treated as cross origin", + "itemtype": "property", + "name": "crossorigin", + "type": "Boolean", + "class": "SpriteSheetLoader" + }, + { + "file": "src/pixi/loaders/SpriteSheetLoader.js", + "line": 45, + "description": "[read-only] The base url of the bitmap font data", + "itemtype": "property", + "name": "baseUrl", + "type": "String", + "readonly": "", + "class": "SpriteSheetLoader" + }, + { + "file": "src/pixi/loaders/SpriteSheetLoader.js", + "line": 54, + "description": "The texture being loaded", + "itemtype": "property", + "name": "texture", + "type": "Texture", + "class": "SpriteSheetLoader" + }, + { + "file": "src/pixi/loaders/SpriteSheetLoader.js", + "line": 62, + "description": "The frames of the sprite sheet", + "itemtype": "property", + "name": "frames", + "type": "Object", + "class": "SpriteSheetLoader" + }, + { + "file": "src/pixi/loaders/SpriteSheetLoader.js", + "line": 74, + "description": "This will begin loading the JSON file", + "itemtype": "method", + "name": "load", + "class": "SpriteSheetLoader" + }, + { + "file": "src/pixi/loaders/SpriteSheetLoader.js", + "line": 89, "description": "Invoke when JSON file is loaded", + "itemtype": "method", + "name": "onJSONLoaded", "access": "private", "tagname": "", "class": "SpriteSheetLoader" }, { "file": "src/pixi/loaders/SpriteSheetLoader.js", - "line": 85, + "line": 126, "description": "Invoke when all files are loaded (json and texture)", + "itemtype": "method", + "name": "onLoaded", "access": "private", "tagname": "", "class": "SpriteSheetLoader" @@ -2512,24 +3614,73 @@ }, { "file": "src/pixi/primitives/Graphics.js", - "line": 34, + "line": 21, + "description": "The alpha of the fill of this graphics object", + "itemtype": "property", + "name": "fillAlpha", + "type": "Number", + "class": "Graphics" + }, + { + "file": "src/pixi/primitives/Graphics.js", + "line": 29, + "description": "The width of any lines drawn", + "itemtype": "property", + "name": "lineWidth", + "type": "Number", + "class": "Graphics" + }, + { + "file": "src/pixi/primitives/Graphics.js", + "line": 37, + "description": "The color of any lines drawn", + "itemtype": "property", + "name": "lineColor", + "type": "String", + "class": "Graphics" + }, + { + "file": "src/pixi/primitives/Graphics.js", + "line": 45, + "description": "Graphics data", + "itemtype": "property", + "name": "graphicsData", + "type": "Array", + "access": "private", + "tagname": "", + "class": "Graphics" + }, + { + "file": "src/pixi/primitives/Graphics.js", + "line": 54, + "description": "Current path", + "itemtype": "property", + "name": "currentPath", + "type": "Object", + "access": "private", + "tagname": "", + "class": "Graphics" + }, + { + "file": "src/pixi/primitives/Graphics.js", + "line": 68, "description": "Specifies a line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method.", "itemtype": "method", "name": "lineStyle", "params": [ { "name": "lineWidth", - "description": "", + "description": "width of the line to draw, will update the object's stored style", "type": "Number" }, { "name": "color", - "description": "", + "description": "color of the line to draw, will update the object's stored style", "type": "Number" }, { "name": "alpha", - "description": "", + "description": "alpha of the line to draw, will update the object's stored style", "type": "Number" } ], @@ -2537,19 +3688,19 @@ }, { "file": "src/pixi/primitives/Graphics.js", - "line": 55, + "line": 90, "description": "Moves the current drawing position to (x, y).", "itemtype": "method", "name": "moveTo", "params": [ { "name": "x", - "description": "", + "description": "the X coord to move to", "type": "Number" }, { "name": "y", - "description": "", + "description": "the Y coord to move to", "type": "Number" } ], @@ -2557,19 +3708,19 @@ }, { "file": "src/pixi/primitives/Graphics.js", - "line": 73, - "description": "Draws a line using the current line style from the current drawing position to (x, y); the current drawing position is then set to (x, y).", + "line": 109, + "description": "Draws a line using the current line style from the current drawing position to (x, y);\nthe current drawing position is then set to (x, y).", "itemtype": "method", "name": "lineTo", "params": [ { "name": "x", - "description": "", + "description": "the X coord to draw to", "type": "Number" }, { "name": "y", - "description": "", + "description": "the Y coord to draw to", "type": "Number" } ], @@ -2577,8 +3728,8 @@ }, { "file": "src/pixi/primitives/Graphics.js", - "line": 85, - "description": "Specifies a simple one-color fill that subsequent calls to other Graphics methods (such as lineTo() or drawCircle()) use when drawing.", + "line": 123, + "description": "Specifies a simple one-color fill that subsequent calls to other Graphics methods\n(such as lineTo() or drawCircle()) use when drawing.", "itemtype": "method", "name": "beginFill", "params": [ @@ -2597,7 +3748,7 @@ }, { "file": "src/pixi/primitives/Graphics.js", - "line": 98, + "line": 138, "description": "Applies a fill to the lines and shapes that were added since the last call to the beginFill() method.", "itemtype": "method", "name": "endFill", @@ -2605,28 +3756,28 @@ }, { "file": "src/pixi/primitives/Graphics.js", - "line": 109, + "line": 150, "itemtype": "method", "name": "drawRect", "params": [ { "name": "x", - "description": "", + "description": "The X coord of the top-left of the rectangle", "type": "Number" }, { "name": "y", - "description": "", + "description": "The Y coord of the top-left of the rectangle", "type": "Number" }, { "name": "width", - "description": "", + "description": "The width of the rectangle", "type": "Number" }, { "name": "height", - "description": "", + "description": "The height of the rectangle", "type": "Number" } ], @@ -2634,24 +3785,24 @@ }, { "file": "src/pixi/primitives/Graphics.js", - "line": 128, + "line": 170, "description": "Draws a circle.", "itemtype": "method", "name": "drawCircle", "params": [ { "name": "x", - "description": "", + "description": "The X coord of the center of the circle", "type": "Number" }, { "name": "y", - "description": "", + "description": "The Y coord of the center of the circle", "type": "Number" }, { "name": "radius", - "description": "", + "description": "The radius of the circle", "type": "Number" } ], @@ -2659,7 +3810,7 @@ }, { "file": "src/pixi/primitives/Graphics.js", - "line": 147, + "line": 190, "description": "Draws an elipse.", "itemtype": "method", "name": "drawElipse", @@ -2689,7 +3840,7 @@ }, { "file": "src/pixi/primitives/Graphics.js", - "line": 167, + "line": 211, "description": "Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings.", "itemtype": "method", "name": "clear", @@ -2709,7 +3860,7 @@ }, { "file": "src/pixi/renderers/canvas/CanvasRenderer.js", - "line": 24, + "line": 21, "description": "The width of the canvas view", "itemtype": "property", "name": "width", @@ -2719,7 +3870,7 @@ }, { "file": "src/pixi/renderers/canvas/CanvasRenderer.js", - "line": 31, + "line": 30, "description": "The height of the canvas view", "itemtype": "property", "name": "height", @@ -2729,7 +3880,7 @@ }, { "file": "src/pixi/renderers/canvas/CanvasRenderer.js", - "line": 41, + "line": 39, "description": "The canvas element that the everything is drawn to", "itemtype": "property", "name": "view", @@ -2738,7 +3889,7 @@ }, { "file": "src/pixi/renderers/canvas/CanvasRenderer.js", - "line": 55, + "line": 47, "description": "The canvas context that the everything is drawn to", "itemtype": "property", "name": "context", @@ -2762,48 +3913,110 @@ }, { "file": "src/pixi/renderers/canvas/CanvasRenderer.js", - "line": 110, + "line": 113, "description": "resizes the canvas view to the specified width and height", + "itemtype": "method", + "name": "resize", "params": [ { - "name": "the", - "description": "new width of the canvas view" + "name": "width", + "description": "the new width of the canvas view", + "type": "Number" }, { - "name": "the", - "description": "new height of the canvas view" + "name": "height", + "description": "the new height of the canvas view", + "type": "Number" } ], "class": "CanvasRenderer" }, { "file": "src/pixi/renderers/canvas/CanvasRenderer.js", - "line": 124, + "line": 129, + "description": "Renders a display object", + "itemtype": "method", + "name": "renderDisplayObject", + "params": [ + { + "name": "displayObject", + "description": "The displayObject to render", + "type": "DisplayObject" + } + ], "access": "private", "tagname": "", "class": "CanvasRenderer" }, { "file": "src/pixi/renderers/canvas/CanvasRenderer.js", - "line": 235, + "line": 250, + "description": "Renders a flat strip", + "itemtype": "method", + "name": "renderStripFlat", + "params": [ + { + "name": "strip", + "description": "The Strip to render", + "type": "Strip" + } + ], "access": "private", "tagname": "", "class": "CanvasRenderer" }, { "file": "src/pixi/renderers/canvas/CanvasRenderer.js", - "line": 268, + "line": 287, + "description": "Renders a tiling sprite", + "itemtype": "method", + "name": "renderTilingSprite", + "params": [ + { + "name": "sprite", + "description": "The tilingsprite to render", + "type": "TilingSprite" + } + ], "access": "private", "tagname": "", "class": "CanvasRenderer" }, { "file": "src/pixi/renderers/canvas/CanvasRenderer.js", - "line": 299, + "line": 320, + "description": "Renders a strip", + "itemtype": "method", + "name": "renderStrip", + "params": [ + { + "name": "strip", + "description": "The Strip to render", + "type": "Strip" + } + ], "access": "private", "tagname": "", "class": "CanvasRenderer" }, + { + "file": "src/pixi/renderers/webgl/PixiShader.js", + "line": 1, + "author": "Mat Groves http://matgroves.com/ @Doormat23", + "class": "WebGLBatch" + }, + { + "file": "src/pixi/renderers/webgl/PrimitiveShader.js", + "line": 1, + "author": "Mat Groves http://matgroves.com/ @Doormat23", + "class": "WebGLBatch" + }, + { + "file": "src/pixi/renderers/webgl/StripShader.js", + "line": 1, + "author": "Mat Groves http://matgroves.com/ @Doormat23", + "class": "WebGLBatch" + }, { "file": "src/pixi/renderers/webgl/WebGLBatch.js", "line": 1, @@ -2833,20 +4046,37 @@ }, { "file": "src/pixi/renderers/webgl/WebGLBatch.js", - "line": 67, + "line": 71, "description": "Cleans the batch so that is can be returned to an object pool and reused", + "itemtype": "method", + "name": "clean", "class": "WebGLBatch" }, { "file": "src/pixi/renderers/webgl/WebGLBatch.js", - "line": 98, + "line": 90, + "description": "Recreates the buffers in the event of a context loss", + "itemtype": "method", + "name": "restoreLostContext", + "params": [ + { + "name": "gl", + "description": "", + "type": "WebGLContext" + } + ], + "class": "WebGLBatch" + }, + { + "file": "src/pixi/renderers/webgl/WebGLBatch.js", + "line": 105, "description": "inits the batch's texture and blend mode based if the supplied sprite", "itemtype": "method", "name": "init", "params": [ { "name": "sprite", - "description": "the first sprite to be added to the batch. Only sprites with the same base texture and blend mode will be allowed to be added to this batch", + "description": "the first sprite to be added to the batch. Only sprites with\n\t\tthe same base texture and blend mode will be allowed to be added to this batch", "type": "Sprite" } ], @@ -2854,7 +4084,7 @@ }, { "file": "src/pixi/renderers/webgl/WebGLBatch.js", - "line": 117, + "line": 125, "description": "inserts a sprite before the specified sprite", "itemtype": "method", "name": "insertBefore", @@ -2874,7 +4104,7 @@ }, { "file": "src/pixi/renderers/webgl/WebGLBatch.js", - "line": 145, + "line": 153, "description": "inserts a sprite after the specified sprite", "itemtype": "method", "name": "insertAfter", @@ -2894,7 +4124,7 @@ }, { "file": "src/pixi/renderers/webgl/WebGLBatch.js", - "line": 175, + "line": 182, "description": "removes a sprite from the batch", "itemtype": "method", "name": "remove", @@ -2909,7 +4139,7 @@ }, { "file": "src/pixi/renderers/webgl/WebGLBatch.js", - "line": 218, + "line": 226, "description": "Splits the batch into two with the specified sprite being the start of the new batch.", "itemtype": "method", "name": "split", @@ -2928,7 +4158,7 @@ }, { "file": "src/pixi/renderers/webgl/WebGLBatch.js", - "line": 268, + "line": 267, "description": "Merges two batchs together", "itemtype": "method", "name": "merge", @@ -2943,14 +4173,15 @@ }, { "file": "src/pixi/renderers/webgl/WebGLBatch.js", - "line": 293, - "description": "Grows the size of the batch. As the elements in the batch cannot have a dynamic size this function is used to increase the size of the batch. It also creates a little extra room so that the batch does not need to be resized every time a sprite is added", - "methos": "growBatch", + "line": 292, + "description": "Grows the size of the batch. As the elements in the batch cannot have a dynamic size this\nfunction is used to increase the size of the batch. It also creates a little extra room so\nthat the batch does not need to be resized every time a sprite is added", + "itemtype": "method", + "name": "growBatch", "class": "WebGLBatch" }, { "file": "src/pixi/renderers/webgl/WebGLBatch.js", - "line": 346, + "line": 347, "description": "Refresh's all the data in the batch and sync's it with the webGL buffers", "itemtype": "method", "name": "refresh", @@ -2958,7 +4189,7 @@ }, { "file": "src/pixi/renderers/webgl/WebGLBatch.js", - "line": 401, + "line": 403, "description": "Updates all the relevant geometry and uploads the data to the GPU", "itemtype": "method", "name": "update", @@ -2966,18 +4197,157 @@ }, { "file": "src/pixi/renderers/webgl/WebGLBatch.js", - "line": 513, + "line": 508, "description": "Draws the batch to the frame buffer", "itemtype": "method", "name": "render", "class": "WebGLBatch" }, + { + "file": "src/pixi/renderers/webgl/WebGLFilterManager.js", + "line": 1, + "author": "Mat Groves http://matgroves.com/ @Doormat23", + "class": "CanvasGraphics" + }, { "file": "src/pixi/renderers/webgl/WebGLGraphics.js", "line": 1, "author": "Mat Groves http://matgroves.com/ @Doormat23", "class": "CanvasGraphics" }, + { + "file": "src/pixi/renderers/webgl/WebGLGraphics.js", + "line": 15, + "description": "Renders the graphics object", + "static": 1, + "access": "private", + "tagname": "", + "itemtype": "method", + "name": "renderGraphics", + "params": [ + { + "name": "graphics", + "description": "", + "type": "Graphics" + }, + { + "name": "projection", + "description": "", + "type": "Object" + } + ], + "class": "CanvasGraphics" + }, + { + "file": "src/pixi/renderers/webgl/WebGLGraphics.js", + "line": 87, + "description": "Updates the graphics object", + "static": 1, + "access": "private", + "tagname": "", + "itemtype": "method", + "name": "updateGraphics", + "params": [ + { + "name": "graphics", + "description": "", + "type": "Graphics" + } + ], + "class": "CanvasGraphics" + }, + { + "file": "src/pixi/renderers/webgl/WebGLGraphics.js", + "line": 139, + "description": "Builds a rectangle to draw", + "static": 1, + "access": "private", + "tagname": "", + "itemtype": "method", + "name": "buildRectangle", + "params": [ + { + "name": "graphics", + "description": "", + "type": "Graphics" + }, + { + "name": "webGLData", + "description": "", + "type": "Object" + } + ], + "class": "CanvasGraphics" + }, + { + "file": "src/pixi/renderers/webgl/WebGLGraphics.js", + "line": 204, + "description": "Builds a circle to draw", + "static": 1, + "access": "private", + "tagname": "", + "itemtype": "method", + "name": "buildCircle", + "params": [ + { + "name": "graphics", + "description": "", + "type": "Graphics" + }, + { + "name": "webGLData", + "description": "", + "type": "Object" + } + ], + "class": "CanvasGraphics" + }, + { + "file": "src/pixi/renderers/webgl/WebGLGraphics.js", + "line": 272, + "description": "Builds a line to draw", + "static": 1, + "access": "private", + "tagname": "", + "itemtype": "method", + "name": "buildLine", + "params": [ + { + "name": "graphics", + "description": "", + "type": "Graphics" + }, + { + "name": "webGLData", + "description": "", + "type": "Object" + } + ], + "class": "CanvasGraphics" + }, + { + "file": "src/pixi/renderers/webgl/WebGLGraphics.js", + "line": 463, + "description": "Builds a polygon to draw", + "static": 1, + "access": "private", + "tagname": "", + "itemtype": "method", + "name": "buildPoly", + "params": [ + { + "name": "graphics", + "description": "", + "type": "Graphics" + }, + { + "name": "webGLData", + "description": "", + "type": "Object" + } + ], + "class": "CanvasGraphics" + }, { "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", "line": 1, @@ -2986,35 +4356,315 @@ }, { "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", - "line": 725, + "line": 33, + "description": "Add a display object to the webgl renderer", + "itemtype": "method", + "name": "setRenderable", + "params": [ + { + "name": "displayObject", + "description": "", + "type": "DisplayObject" + } + ], "access": "private", "tagname": "", "class": "WebGLBatch" }, { "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", - "line": 732, + "line": 55, + "description": "Renders the stage to its webgl view", + "itemtype": "method", + "name": "render", + "params": [ + { + "name": "projection", + "description": "", + "type": "Object" + } + ], + "class": "WebGLBatch" + }, + { + "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", + "line": 91, + "description": "Renders a specific displayObject", + "itemtype": "method", + "name": "renderSpecific", + "params": [ + { + "name": "displayObject", + "description": "", + "type": "DisplayObject" + }, + { + "name": "projection", + "description": "", + "type": "Object" + } + ], "access": "private", "tagname": "", "class": "WebGLBatch" }, { "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", - "line": 787, + "line": 251, + "description": "Renders a specific renderable", + "itemtype": "method", + "name": "renderSpecial", + "params": [ + { + "name": "renderable", + "description": "", + "type": "DisplayObject" + }, + { + "name": "projection", + "description": "", + "type": "Object" + } + ], "access": "private", "tagname": "", "class": "WebGLBatch" }, { "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", - "line": 875, + "line": 334, + "description": "Updates a webgl texture", + "itemtype": "method", + "name": "updateTexture", + "params": [ + { + "name": "displayObject", + "description": "", + "type": "DisplayObject" + } + ], "access": "private", "tagname": "", "class": "WebGLBatch" }, { "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", - "line": 912, + "line": 376, + "description": "Adds filter blocks", + "itemtype": "method", + "name": "addFilterBlocks", + "params": [ + { + "name": "start", + "description": "", + "type": "FilterBlock" + }, + { + "name": "end", + "description": "", + "type": "FilterBlock" + } + ], + "access": "private", + "tagname": "", + "class": "WebGLBatch" + }, + { + "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", + "line": 416, + "description": "Remove filter blocks", + "itemtype": "method", + "name": "removeFilterBlocks", + "params": [ + { + "name": "start", + "description": "", + "type": "FilterBlock" + }, + { + "name": "end", + "description": "", + "type": "FilterBlock" + } + ], + "access": "private", + "tagname": "", + "class": "WebGLBatch" + }, + { + "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", + "line": 430, + "description": "Adds a display object and children to the webgl context", + "itemtype": "method", + "name": "addDisplayObjectAndChildren", + "params": [ + { + "name": "displayObject", + "description": "", + "type": "DisplayObject" + } + ], + "access": "private", + "tagname": "", + "class": "WebGLBatch" + }, + { + "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", + "line": 487, + "description": "Removes a display object and children to the webgl context", + "itemtype": "method", + "name": "removeDisplayObjectAndChildren", + "params": [ + { + "name": "displayObject", + "description": "", + "type": "DisplayObject" + } + ], + "access": "private", + "tagname": "", + "class": "WebGLBatch" + }, + { + "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", + "line": 509, + "description": "Inserts a displayObject into the linked list", + "itemtype": "method", + "name": "insertObject", + "params": [ + { + "name": "displayObject", + "description": "", + "type": "DisplayObject" + }, + { + "name": "previousObject", + "description": "", + "type": "DisplayObject" + }, + { + "name": "nextObject", + "description": "", + "type": "DisplayObject" + } + ], + "access": "private", + "tagname": "", + "class": "WebGLBatch" + }, + { + "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", + "line": 647, + "description": "Inserts a displayObject into the linked list", + "itemtype": "method", + "name": "insertAfter", + "params": [ + { + "name": "item", + "description": "", + "type": "DisplayObject" + }, + { + "name": "displayObject", + "description": "The object to insert", + "type": "DisplayObject" + } + ], + "access": "private", + "tagname": "", + "class": "WebGLBatch" + }, + { + "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", + "line": 702, + "description": "Removes a displayObject from the linked list", + "itemtype": "method", + "name": "removeObject", + "params": [ + { + "name": "displayObject", + "description": "The object to remove", + "type": "DisplayObject" + } + ], + "access": "private", + "tagname": "", + "class": "WebGLBatch" + }, + { + "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", + "line": 781, + "description": "Initializes a tiling sprite", + "itemtype": "method", + "name": "initTilingSprite", + "params": [ + { + "name": "sprite", + "description": "The tiling sprite to initialize", + "type": "TilingSprite" + } + ], + "access": "private", + "tagname": "", + "class": "WebGLBatch" + }, + { + "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", + "line": 840, + "description": "Renders a Strip", + "itemtype": "method", + "name": "renderStrip", + "params": [ + { + "name": "strip", + "description": "The strip to render", + "type": "Strip" + }, + { + "name": "projection", + "description": "", + "type": "Object" + } + ], + "access": "private", + "tagname": "", + "class": "WebGLBatch" + }, + { + "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", + "line": 932, + "description": "Renders a TilingSprite", + "itemtype": "method", + "name": "renderTilingSprite", + "params": [ + { + "name": "sprite", + "description": "The tiling sprite to render", + "type": "TilingSprite" + }, + { + "name": "projectionMatrix", + "description": "", + "type": "Object" + } + ], + "access": "private", + "tagname": "", + "class": "WebGLBatch" + }, + { + "file": "src/pixi/renderers/webgl/WebGLRenderGroup.js", + "line": 974, + "description": "Initializes a strip to be rendered", + "itemtype": "method", + "name": "initStrip", + "params": [ + { + "name": "strip", + "description": "The strip to initialize", + "type": "Strip" + } + ], "access": "private", "tagname": "", "class": "WebGLBatch" @@ -3027,35 +4677,47 @@ }, { "file": "src/pixi/renderers/webgl/WebGLRenderer.js", - "line": 90, + "line": 104, + "description": "Gets a new WebGLBatch from the pool", + "static": 1, + "itemtype": "method", + "name": "getBatch", + "return": { + "description": "", + "type": "WebGLBatch" + }, "access": "private", "tagname": "", "class": "WebGLRenderer" }, { "file": "src/pixi/renderers/webgl/WebGLRenderer.js", - "line": 105, + "line": 124, + "description": "Puts a batch back into the pool", + "static": 1, + "itemtype": "method", + "name": "returnBatch", + "params": [ + { + "name": "batch", + "description": "The batch to return", + "type": "WebGLBatch" + } + ], "access": "private", "tagname": "", "class": "WebGLRenderer" }, { "file": "src/pixi/renderers/webgl/WebGLRenderer.js", - "line": 115, - "access": "private", - "tagname": "", - "class": "WebGLRenderer" - }, - { - "file": "src/pixi/renderers/webgl/WebGLRenderer.js", - "line": 121, + "line": 138, "description": "Renders the stage to its webGL view", "itemtype": "method", "name": "render", "params": [ { "name": "stage", - "description": "the PIXI.Stage element to be rendered", + "description": "the Stage element to be rendered", "type": "Stage" } ], @@ -3063,14 +4725,53 @@ }, { "file": "src/pixi/renderers/webgl/WebGLRenderer.js", - "line": 204, + "line": 209, + "description": "Updates the textures loaded into this webgl renderer", + "static": 1, + "itemtype": "method", + "name": "updateTextures", "access": "private", "tagname": "", "class": "WebGLRenderer" }, { "file": "src/pixi/renderers/webgl/WebGLRenderer.js", - "line": 263, + "line": 225, + "description": "Updates a loaded webgl texture", + "static": 1, + "itemtype": "method", + "name": "updateTexture", + "params": [ + { + "name": "texture", + "description": "The texture to update", + "type": "Texture" + } + ], + "access": "private", + "tagname": "", + "class": "WebGLRenderer" + }, + { + "file": "src/pixi/renderers/webgl/WebGLRenderer.js", + "line": 269, + "description": "Destroys a loaded webgl texture", + "itemtype": "method", + "name": "destroyTexture", + "params": [ + { + "name": "texture", + "description": "The texture to update", + "type": "Texture" + } + ], + "access": "private", + "tagname": "", + "class": "WebGLRenderer" + }, + { + "file": "src/pixi/renderers/webgl/WebGLRenderer.js", + "line": 288, "description": "resizes the webGL view to the specified width and height", "itemtype": "method", "name": "resize", @@ -3090,21 +4791,41 @@ }, { "file": "src/pixi/renderers/webgl/WebGLRenderer.js", - "line": 290, + "line": 319, + "description": "Handles a lost webgl context", + "itemtype": "method", + "name": "handleContextLost", + "params": [ + { + "name": "event", + "description": "", + "type": "Event" + } + ], "access": "private", "tagname": "", "class": "WebGLRenderer" }, { "file": "src/pixi/renderers/webgl/WebGLRenderer.js", - "line": 299, + "line": 332, + "description": "Handles a restored webgl context", + "itemtype": "method", + "name": "handleContextRestored", + "params": [ + { + "name": "event", + "description": "", + "type": "Event" + } + ], "access": "private", "tagname": "", "class": "WebGLRenderer" }, { "file": "src/pixi/renderers/webgl/WebGLShaders.js", - "line": 2, + "line": 1, "author": "Mat Groves http://matgroves.com/ @Doormat23", "class": "BitmapText" }, @@ -3116,7 +4837,7 @@ }, { "file": "src/pixi/text/BitmapText.js", - "line": 33, + "line": 34, "description": "Set the copy for the text object", "itemtype": "method", "name": "setText", @@ -3131,7 +4852,7 @@ }, { "file": "src/pixi/text/BitmapText.js", - "line": 44, + "line": 46, "description": "Set the style of the text", "itemtype": "method", "name": "setStyle", @@ -3160,15 +4881,20 @@ }, { "file": "src/pixi/text/BitmapText.js", - "line": 64, + "line": 67, "description": "Renders text", + "itemtype": "method", + "name": "updateText", "access": "private", "tagname": "", "class": "BitmapText" }, { "file": "src/pixi/text/BitmapText.js", - "line": 137, + "line": 142, + "description": "Updates the transfor of this object", + "itemtype": "method", + "name": "updateTransform", "access": "private", "tagname": "", "class": "BitmapText" @@ -3181,7 +4907,7 @@ }, { "file": "src/pixi/text/Text.js", - "line": 37, + "line": 38, "description": "Set the style of the text", "itemtype": "method", "name": "setStyle", @@ -3238,7 +4964,7 @@ }, { "name": "[style.font=\"bold", - "description": "20pt Arial\"] The style and size of the font", + "description": "20pt Arial\"] The style and size of the font", "type": "String" } ], @@ -3246,7 +4972,7 @@ }, { "file": "src/pixi/text/Text.js", - "line": 63, + "line": 65, "description": "Set the copy for the text object. To split a line you can use \"\\n\"", "methos": "setText", "params": [ @@ -3260,35 +4986,66 @@ }, { "file": "src/pixi/text/Text.js", - "line": 74, + "line": 77, "description": "Renders text", + "itemtype": "method", + "name": "updateText", "access": "private", "tagname": "", "class": "Text" }, { "file": "src/pixi/text/Text.js", - "line": 143, + "line": 148, "description": "Updates texture size based on canvas size", + "itemtype": "method", + "name": "updateTexture", "access": "private", "tagname": "", "class": "Text" }, { "file": "src/pixi/text/Text.js", - "line": 161, + "line": 167, + "description": "Updates the transfor of this object", + "itemtype": "method", + "name": "updateTransform", "access": "private", "tagname": "", "class": "Text" }, { "file": "src/pixi/text/Text.js", - "line": 203, + "line": 216, "description": "A Text Object will apply wordwrap", + "itemtype": "method", + "name": "wordWrap", + "params": [ + { + "name": "text", + "description": "", + "type": "String" + } + ], "access": "private", "tagname": "", "class": "Text" }, + { + "file": "src/pixi/text/Text.js", + "line": 270, + "description": "Destroys this text object", + "itemtype": "method", + "name": "destroy", + "params": [ + { + "name": "destroyTexture", + "description": "", + "type": "Boolean" + } + ], + "class": "Text" + }, { "file": "src/pixi/textures/BaseTexture.js", "line": 1, @@ -3297,25 +5054,37 @@ }, { "file": "src/pixi/textures/BaseTexture.js", - "line": 27, - "description": "[read only] The width of the base texture set when the image has loaded", + "line": 21, + "description": "[read-only] The width of the base texture set when the image has loaded", "itemtype": "property", "name": "width", "type": "Number", + "readonly": "", "class": "BaseTexture" }, { "file": "src/pixi/textures/BaseTexture.js", - "line": 33, - "description": "[read only] The height of the base texture set when the image has loaded", + "line": 30, + "description": "[read-only] The height of the base texture set when the image has loaded", "itemtype": "property", "name": "height", "type": "Number", + "readonly": "", "class": "BaseTexture" }, { "file": "src/pixi/textures/BaseTexture.js", - "line": 40, + "line": 39, + "description": "[read-only] Describes if the base texture has loaded or not", + "itemtype": "property", + "name": "hasLoaded", + "type": "Boolean", + "readonly": "", + "class": "BaseTexture" + }, + { + "file": "src/pixi/textures/BaseTexture.js", + "line": 48, "description": "The source that is loaded to create the texture", "itemtype": "property", "name": "source", @@ -3324,8 +5093,16 @@ }, { "file": "src/pixi/textures/BaseTexture.js", - "line": 101, - "description": "Helper function that returns a base texture based on an image url\n If the image is not in the base texture cache it will be created and loaded", + "line": 99, + "description": "Destroys this base texture", + "itemtype": "method", + "name": "destroy", + "class": "BaseTexture" + }, + { + "file": "src/pixi/textures/BaseTexture.js", + "line": 114, + "description": "Helper function that returns a base texture based on an image url\nIf the image is not in the base texture cache it will be created and loaded", "static": 1, "itemtype": "method", "name": "fromImage", @@ -3349,14 +5126,34 @@ }, { "file": "src/pixi/textures/RenderTexture.js", - "line": 112, + "line": 57, + "description": "Initializes the webgl data for this texture", + "itemtype": "method", + "name": "initWebGL", + "access": "private", + "tagname": "", + "class": "RenderTexture" + }, + { + "file": "src/pixi/textures/RenderTexture.js", + "line": 125, + "description": "Initializes the canvas data for this texture", + "itemtype": "method", + "name": "initCanvas", + "access": "private", + "tagname": "", + "class": "RenderTexture" + }, + { + "file": "src/pixi/textures/RenderTexture.js", + "line": 141, "description": "This function will draw the display object to the texture.", "itemtype": "method", - "name": "render", + "name": "renderWebGL", "params": [ { "name": "displayObject", - "description": "", + "description": "The display object to render this texture on", "type": "DisplayObject" }, { @@ -3365,6 +5162,30 @@ "type": "Boolean" } ], + "access": "private", + "tagname": "", + "class": "RenderTexture" + }, + { + "file": "src/pixi/textures/RenderTexture.js", + "line": 214, + "description": "This function will draw the display object to the texture.", + "itemtype": "method", + "name": "renderCanvas", + "params": [ + { + "name": "displayObject", + "description": "The display object to render this texture on", + "type": "DisplayObject" + }, + { + "name": "clear", + "description": "If true the texture will be cleared before the displayObject is drawn", + "type": "Boolean" + } + ], + "access": "private", + "tagname": "", "class": "RenderTexture" }, { @@ -3384,23 +5205,63 @@ }, { "file": "src/pixi/textures/Texture.js", - "line": 40, + "line": 39, "description": "The frame specifies the region of the base texture that this texture uses", "itemtype": "property", "name": "frame", - "type": "#Rectangle", + "type": "Rectangle", "class": "Texture" }, { "file": "src/pixi/textures/Texture.js", - "line": 83, + "line": 47, + "description": "The trim point", + "itemtype": "property", + "name": "trim", + "type": "Point", + "class": "Texture" + }, + { + "file": "src/pixi/textures/Texture.js", + "line": 73, + "description": "Called when the base texture is loaded", + "itemtype": "method", + "name": "onBaseTextureLoaded", + "params": [ + { + "name": "event", + "description": "" + } + ], + "access": "private", + "tagname": "", + "class": "Texture" + }, + { + "file": "src/pixi/textures/Texture.js", + "line": 93, + "description": "Destroys this texture", + "itemtype": "method", + "name": "destroy", + "params": [ + { + "name": "destroyBase", + "description": "Whether to destroy the base texture as well", + "type": "Boolean" + } + ], + "class": "Texture" + }, + { + "file": "src/pixi/textures/Texture.js", + "line": 104, "description": "Specifies the rectangle region of the baseTexture", "itemtype": "method", "name": "setFrame", "params": [ { "name": "frame", - "description": "", + "description": "The frame of the texture to set it to", "type": "Rectangle" } ], @@ -3408,8 +5269,8 @@ }, { "file": "src/pixi/textures/Texture.js", - "line": 105, - "description": "Helper function that returns a texture based on an image url\n If the image is not in the texture cache it will be created and loaded", + "line": 127, + "description": "Helper function that returns a texture based on an image url\nIf the image is not in the texture cache it will be created and loaded", "static": 1, "itemtype": "method", "name": "fromImage", @@ -3418,6 +5279,11 @@ "name": "imageUrl", "description": "The image url of the texture", "type": "String" + }, + { + "name": "crossorigin", + "description": "Whether requests should be treated as crossorigin", + "type": "Boolean" } ], "return": { @@ -3427,8 +5293,9 @@ }, { "file": "src/pixi/textures/Texture.js", - "line": 127, - "description": "Helper function that returns a texture based on a frame id\n If the frame id is not in the texture cache an error will be thrown", + "line": 150, + "description": "Helper function that returns a texture based on a frame id\nIf the frame id is not in the texture cache an error will be thrown", + "static": 1, "itemtype": "method", "name": "fromFrame", "params": [ @@ -3445,8 +5312,8 @@ }, { "file": "src/pixi/textures/Texture.js", - "line": 142, - "description": "Helper function that returns a texture based on a canvas element\n If the canvas is not in the texture cache it will be created and loaded", + "line": 166, + "description": "Helper function that returns a texture based on a canvas element\nIf the canvas is not in the texture cache it will be created and loaded", "static": 1, "itemtype": "method", "name": "fromCanvas", @@ -3464,7 +5331,7 @@ }, { "file": "src/pixi/textures/Texture.js", - "line": 158, + "line": 182, "description": "Adds a texture to the textureCache.", "static": 1, "itemtype": "method", @@ -3485,7 +5352,7 @@ }, { "file": "src/pixi/textures/Texture.js", - "line": 171, + "line": 195, "description": "Remove a texture from the textureCache.", "static": 1, "itemtype": "method", @@ -3507,12 +5374,12 @@ "file": "src/pixi/utils/Detector.js", "line": 1, "author": "Mat Groves http://matgroves.com/ @Doormat23", - "class": "InteractionManager" + "class": "EventTarget" }, { "file": "src/pixi/utils/Detector.js", "line": 5, - "description": "This helper function will automatically detect which renderer you should be using.\nWebGL is the preferred renderer as it is a lot fastest. If webGL is not supported by the browser then this function will return a canvas renderer", + "description": "This helper function will automatically detect which renderer you should be using.\nWebGL is the preferred renderer as it is a lot fastest. If webGL is not supported by\nthe browser then this function will return a canvas renderer", "itemtype": "method", "name": "autoDetectRenderer", "static": 1, @@ -3533,89 +5400,348 @@ "type": "Canvas" }, { - "name": "transparent", + "name": "transparent=false", "description": "the transparency of the render view, default false", "type": "Boolean" + }, + { + "name": "antialias=false", + "description": "sets antialias (only applicable in webGL chrome at the moment)\n\nantialias", + "type": "Boolean" } ], - "default": "false", - "class": "InteractionManager" + "class": "EventTarget" }, { "file": "src/pixi/utils/EventTarget.js", "line": 1, "description": "https://github.com/mrdoob/eventtarget.js/\nTHankS mr DOob!", - "class": "InteractionManager" + "class": "EventTarget" + }, + { + "file": "src/pixi/utils/Polyk.js", + "line": 36, + "description": "Triangulates shapes for webGL graphic fills", + "itemtype": "method", + "name": "Triangulate", + "is_constructor": 1, + "class": "PolyK._PointInTriangle", + "namespace": "PolyK" }, { "file": "src/pixi/utils/Utils.js", - "line": 38, - "description": "Provides bind in a cross browser way.", - "class": "InteractionManager" + "line": 8, + "description": "A polyfill for requestAnimationFrame", + "itemtype": "method", + "name": "requestAnimationFrame", + "class": "PolyK.AjaxRequest", + "namespace": "PolyK" + }, + { + "file": "src/pixi/utils/Utils.js", + "line": 13, + "description": "A polyfill for cancelAnimationFrame", + "itemtype": "method", + "name": "cancelAnimationFrame", + "class": "PolyK.AjaxRequest", + "namespace": "PolyK" + }, + { + "file": "src/pixi/utils/Utils.js", + "line": 43, + "description": "Converts a hex color number to an [R, G, B] array", + "itemtype": "method", + "name": "HEXtoRGB", + "params": [ + { + "name": "hex", + "description": "", + "type": "Number" + } + ], + "class": "PolyK.AjaxRequest", + "namespace": "PolyK" + }, + { + "file": "src/pixi/utils/Utils.js", + "line": 53, + "description": "A polyfill for Function.prototype.bind", + "itemtype": "method", + "name": "bind", + "class": "PolyK.AjaxRequest", + "namespace": "PolyK" }, { "file": "src/pixi/InteractionManager.js", "line": 1, "author": "Mat Groves http://matgroves.com/ @Doormat23", - "class": "InteractionManager" + "class": "PolyK.InteractionManager", + "namespace": "PolyK" }, { "file": "src/pixi/InteractionManager.js", - "line": 17, + "line": 15, "description": "a refference to the stage", "itemtype": "property", "name": "stage", "type": "Stage", - "class": "InteractionManager" + "class": "PolyK.InteractionManager", + "namespace": "PolyK" }, { "file": "src/pixi/InteractionManager.js", - "line": 30, + "line": 23, "description": "the mouse data", "itemtype": "property", "name": "mouse", "type": "InteractionData", - "class": "InteractionManager" + "class": "PolyK.InteractionManager", + "namespace": "PolyK" }, { "file": "src/pixi/InteractionManager.js", - "line": 37, + "line": 31, "description": "an object that stores current touches (InteractionData) by id reference", "itemtype": "property", "name": "touchs", "type": "Object", - "class": "InteractionManager" + "class": "PolyK.InteractionManager", + "namespace": "PolyK" }, { "file": "src/pixi/InteractionManager.js", - "line": 499, + "line": 70, + "description": "Collects an interactive sprite recursively to have their interactions managed", + "itemtype": "method", + "name": "collectInteractiveSprite", + "params": [ + { + "name": "displayObject", + "description": "the displayObject to collect", + "type": "DisplayObject" + }, + { + "name": "iParent", + "description": "", + "type": "DisplayObject" + } + ], + "access": "private", + "tagname": "", + "class": "PolyK.InteractionManager", + "namespace": "PolyK" + }, + { + "file": "src/pixi/InteractionManager.js", + "line": 114, + "description": "Sets the target for event delegation", + "itemtype": "method", + "name": "setTarget", + "params": [ + { + "name": "target", + "description": "the renderer to bind events to", + "type": "WebGLRenderer|CanvasRenderer" + } + ], + "access": "private", + "tagname": "", + "class": "PolyK.InteractionManager", + "namespace": "PolyK" + }, + { + "file": "src/pixi/InteractionManager.js", + "line": 135, + "description": "Sets the dom element which will receive mouse/touch events. This is useful for when you have other DOM\nelements ontop of the renderers Canvas element. With this you'll be able to delegate another dom element\nto receive those events", + "itemtype": "method", + "name": "setTargetDomElement", + "params": [ + { + "name": "domElement", + "description": "the dom element which will receive mouse and touch events", + "type": "DOMElement" + } + ], + "access": "private", + "tagname": "", + "class": "PolyK.InteractionManager", + "namespace": "PolyK" + }, + { + "file": "src/pixi/InteractionManager.js", + "line": 185, + "description": "updates the state of interactive objects", + "itemtype": "method", + "name": "update", + "access": "private", + "tagname": "", + "class": "PolyK.InteractionManager", + "namespace": "PolyK" + }, + { + "file": "src/pixi/InteractionManager.js", + "line": 273, + "description": "Is called when the mouse moves accross the renderer element", + "itemtype": "method", + "name": "onMouseMove", + "params": [ + { + "name": "event", + "description": "The DOM event of the mouse moving", + "type": "Event" + } + ], + "access": "private", + "tagname": "", + "class": "PolyK.InteractionManager", + "namespace": "PolyK" + }, + { + "file": "src/pixi/InteractionManager.js", + "line": 305, + "description": "Is called when the mouse button is pressed down on the renderer element", + "itemtype": "method", + "name": "onMouseDown", + "params": [ + { + "name": "event", + "description": "The DOM event of a mouse button being pressed down", + "type": "Event" + } + ], + "access": "private", + "tagname": "", + "class": "PolyK.InteractionManager", + "namespace": "PolyK" + }, + { + "file": "src/pixi/InteractionManager.js", + "line": 370, + "description": "Is called when the mouse button is released on the renderer element", + "itemtype": "method", + "name": "onMouseUp", + "params": [ + { + "name": "event", + "description": "The DOM event of a mouse button being released", + "type": "Event" + } + ], + "access": "private", + "tagname": "", + "class": "PolyK.InteractionManager", + "namespace": "PolyK" + }, + { + "file": "src/pixi/InteractionManager.js", + "line": 422, + "description": "Tests if the current mouse coords hit a sprite", + "itemtype": "method", + "name": "hitTest", + "params": [ + { + "name": "item", + "description": "The displayObject to test for a hit", + "type": "DisplayObject" + }, + { + "name": "interactionData", + "description": "The interactiondata object to update in the case of a hit", + "type": "InteractionData" + } + ], + "access": "private", + "tagname": "", + "class": "PolyK.InteractionManager", + "namespace": "PolyK" + }, + { + "file": "src/pixi/InteractionManager.js", + "line": 495, + "description": "Is called when a touch is moved accross the renderer element", + "itemtype": "method", + "name": "onTouchMove", + "params": [ + { + "name": "event", + "description": "The DOM event of a touch moving accross the renderer view", + "type": "Event" + } + ], + "access": "private", + "tagname": "", + "class": "PolyK.InteractionManager", + "namespace": "PolyK" + }, + { + "file": "src/pixi/InteractionManager.js", + "line": 526, + "description": "Is called when a touch is started on the renderer element", + "itemtype": "method", + "name": "onTouchStart", + "params": [ + { + "name": "event", + "description": "The DOM event of a touch starting on the renderer view", + "type": "Event" + } + ], + "access": "private", + "tagname": "", + "class": "PolyK.InteractionManager", + "namespace": "PolyK" + }, + { + "file": "src/pixi/InteractionManager.js", + "line": 575, + "description": "Is called when a touch is ended on the renderer element", + "itemtype": "method", + "name": "onTouchEnd", + "params": [ + { + "name": "event", + "description": "The DOM event of a touch ending on the renderer view", + "type": "Event" + } + ], + "access": "private", + "tagname": "", + "class": "PolyK.InteractionManager", + "namespace": "PolyK" + }, + { + "file": "src/pixi/InteractionManager.js", + "line": 654, "description": "This point stores the global coords of where the touch/mouse event happened", "itemtype": "property", "name": "global", "type": "Point", - "class": "InteractionData" + "class": "PolyK.InteractionData", + "namespace": "PolyK" }, { "file": "src/pixi/InteractionManager.js", - "line": 509, + "line": 665, "description": "The target Sprite that was interacted with", "itemtype": "property", "name": "target", "type": "Sprite", - "class": "InteractionData" + "class": "PolyK.InteractionData", + "namespace": "PolyK" }, { "file": "src/pixi/InteractionManager.js", - "line": 516, + "line": 673, "description": "When passed to an event handler, this will be the original DOM Event that was captured", "itemtype": "property", "name": "originalEvent", "type": "Event", - "class": "InteractionData" + "class": "PolyK.InteractionData", + "namespace": "PolyK" }, { "file": "src/pixi/InteractionManager.js", - "line": 524, + "line": 682, "description": "This will return the local coords of the specified displayObject for this InteractionData", "itemtype": "method", "name": "getLocalPosition", @@ -3630,39 +5756,67 @@ "description": "A point containing the coords of the InteractionData position relative to the DisplayObject", "type": "Point" }, - "class": "InteractionData" + "class": "PolyK.InteractionData", + "namespace": "PolyK" }, { "file": "src/pixi/Intro.js", "line": 1, "author": "Mat Groves http://matgroves.com/ @Doormat23", - "class": "" + "class": "", + "namespace": "PolyK" }, { "file": "src/pixi/Outro.js", "line": 1, "author": "Mat Groves http://matgroves.com/ @Doormat23", - "class": "" + "class": "", + "namespace": "PolyK" }, { "file": "src/pixi/Pixi.js", "line": 1, "author": "Mat Groves http://matgroves.com/ @Doormat23", - "class": "" + "class": "", + "namespace": "PolyK" } ], "warnings": [ { - "message": "unknown tag: internal", - "line": " src/pixi/display/Stage.js:42" + "message": "unknown tag: contructor", + "line": " src/pixi/filters/BlurFilter.js:6" + }, + { + "message": "unknown tag: contructor", + "line": " src/pixi/filters/ColorMatrixFilter.js:5" + }, + { + "message": "unknown tag: contructor", + "line": " src/pixi/filters/DisplacementFilter.js:6" + }, + { + "message": "unknown tag: contructor", + "line": " src/pixi/filters/GreyFilter.js:6" + }, + { + "message": "unknown tag: contructor", + "line": " src/pixi/filters/InvertFilter.js:5" + }, + { + "message": "unknown tag: contructor", + "line": " src/pixi/filters/PixelateFilter.js:5" + }, + { + "message": "unknown tag: contructor", + "line": " src/pixi/filters/SepiaFilter.js:7" + }, + { + "message": "unknown tag: contructor", + "line": " src/pixi/renderers/webgl/WebGLRenderGroup.js:5" }, { "message": "unknown tag: methos", - "line": " src/pixi/renderers/webgl/WebGLBatch.js:293" - }, - { - "message": "unknown tag: methos", - "line": " src/pixi/text/Text.js:63" + "line": " src/pixi/text/Text.js:65" }, { "message": "Missing item type", @@ -3688,18 +5842,10 @@ "message": "Missing item type", "line": " src/pixi/display/DisplayObject.js:1" }, - { - "message": "Missing item type", - "line": " src/pixi/display/DisplayObject.js:399" - }, { "message": "Missing item type", "line": " src/pixi/display/DisplayObjectContainer.js:1" }, - { - "message": "Missing item type", - "line": " src/pixi/display/DisplayObjectContainer.js:358" - }, { "message": "Missing item type", "line": " src/pixi/display/MovieClip.js:1" @@ -3708,10 +5854,6 @@ "message": "Missing item type", "line": " src/pixi/display/Sprite.js:1" }, - { - "message": "Missing item type", - "line": " src/pixi/display/Sprite.js:119" - }, { "message": "Missing item type", "line": " src/pixi/display/Stage.js:1" @@ -3730,15 +5872,7 @@ }, { "message": "Missing item type\ncx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of", - "line": " src/pixi/extras/Spine.js:308" - }, - { - "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:604" - }, - { - "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:611" + "line": " src/pixi/extras/Spine.js:327" }, { "message": "Missing item type", @@ -3746,11 +5880,11 @@ }, { "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:626" + "line": " src/pixi/extras/Spine.js:625" }, { "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:633" + "line": " src/pixi/extras/Spine.js:632" }, { "message": "Missing item type", @@ -3758,23 +5892,23 @@ }, { "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:675" + "line": " src/pixi/extras/Spine.js:647" }, { "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:683" + "line": " src/pixi/extras/Spine.js:654" }, { "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:698" + "line": " src/pixi/extras/Spine.js:689" }, { "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:702" + "line": " src/pixi/extras/Spine.js:697" }, { "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:709" + "line": " src/pixi/extras/Spine.js:712" }, { "message": "Missing item type", @@ -3784,29 +5918,29 @@ "message": "Missing item type", "line": " src/pixi/extras/Spine.js:723" }, + { + "message": "Missing item type", + "line": " src/pixi/extras/Spine.js:730" + }, + { + "message": "Missing item type", + "line": " src/pixi/extras/Spine.js:737" + }, { "message": "Missing item type\nfrom the new skin are attached if the corresponding attachment from the old skin was attached.", - "line": " src/pixi/extras/Spine.js:735" + "line": " src/pixi/extras/Spine.js:749" }, { "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:742" + "line": " src/pixi/extras/Spine.js:756" }, { "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:746" + "line": " src/pixi/extras/Spine.js:760" }, { "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:755" - }, - { - "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:948" - }, - { - "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:954" + "line": " src/pixi/extras/Spine.js:769" }, { "message": "Missing item type", @@ -3818,11 +5952,19 @@ }, { "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:984" + "line": " src/pixi/extras/Spine.js:972" }, { "message": "Missing item type", - "line": " src/pixi/extras/Spine.js:1401" + "line": " src/pixi/extras/Spine.js:978" + }, + { + "message": "Missing item type", + "line": " src/pixi/extras/Spine.js:996" + }, + { + "message": "Missing item type", + "line": " src/pixi/extras/Spine.js:1415" }, { "message": "Missing item type", @@ -3832,98 +5974,82 @@ "message": "Missing item type", "line": " src/pixi/extras/TilingSprite.js:1" }, + { + "message": "Missing item type", + "line": " src/pixi/filters/AbstractFilter.js:1" + }, + { + "message": "Missing item type", + "line": " src/pixi/filters/BlurFilter.js:1" + }, + { + "message": "Missing item type", + "line": " src/pixi/filters/BlurXFilter.js:1" + }, + { + "message": "Missing item type", + "line": " src/pixi/filters/BlurYFilter.js:1" + }, + { + "message": "Missing item type", + "line": " src/pixi/filters/ColorMatrixFilter.js:1" + }, + { + "message": "Missing item type", + "line": " src/pixi/filters/DisplacementFilter.js:1" + }, { "message": "Missing item type", "line": " src/pixi/filters/FilterBlock.js:1" }, { "message": "Missing item type", - "line": " src/pixi/filters/MaskFilter.js:1" + "line": " src/pixi/filters/GreyFilter.js:1" + }, + { + "message": "Missing item type", + "line": " src/pixi/filters/InvertFilter.js:1" + }, + { + "message": "Missing item type", + "line": " src/pixi/filters/PixelateFilter.js:1" + }, + { + "message": "Missing item type\n/**\n * @author Mat Groves http://matgroves.com/ @Doormat23", + "line": " src/pixi/filters/SepiaFilter.js:1" + }, + { + "message": "Missing item type", + "line": " src/pixi/filters/SmartBlurFilter.js:1" }, { "message": "Missing item type", "line": " src/pixi/loaders/AssetLoader.js:1" }, - { - "message": "Missing item type\nThis will begin loading the assets sequentially", - "line": " src/pixi/loaders/AssetLoader.js:54" - }, - { - "message": "Missing item type\nInvoked after each file is loaded", - "line": " src/pixi/loaders/AssetLoader.js:82" - }, { "message": "Missing item type", "line": " src/pixi/loaders/BitmapFontLoader.js:1" }, - { - "message": "Missing item type\nThis will begin loading the JSON file", - "line": " src/pixi/loaders/BitmapFontLoader.js:34" - }, - { - "message": "Missing item type\nInvoked when XML file is loaded", - "line": " src/pixi/loaders/BitmapFontLoader.js:51" - }, - { - "message": "Missing item type\nInvoked when all files are loaded (xml/fnt and texture)", - "line": " src/pixi/loaders/BitmapFontLoader.js:121" - }, { "message": "Missing item type", "line": " src/pixi/loaders/ImageLoader.js:1" }, { - "message": "Missing item type\nLoads image or takes it from cache", - "line": " src/pixi/loaders/ImageLoader.js:24" - }, - { - "message": "Missing item type\nInvoked when image file is loaded or it is already cached and ready to use", - "line": " src/pixi/loaders/ImageLoader.js:43" + "message": "Missing item type\nif the image is loaded with loadFramedSpriteSheet\nframes will contain the sprite sheet frames", + "line": " src/pixi/loaders/ImageLoader.js:28" }, { "message": "Missing item type", "line": " src/pixi/loaders/JsonLoader.js:1" }, - { - "message": "Missing item type\nThis will begin loading the JSON file", - "line": " src/pixi/loaders/JsonLoader.js:28" - }, - { - "message": "Missing item type\nInvoke when JSON file is loaded", - "line": " src/pixi/loaders/JsonLoader.js:43" - }, - { - "message": "Missing item type\nInvoke when json file loaded", - "line": " src/pixi/loaders/JsonLoader.js:108" - }, - { - "message": "Missing item type\nInvoke when error occured", - "line": " src/pixi/loaders/JsonLoader.js:120" - }, { "message": "Missing item type", "line": " src/pixi/loaders/SpineLoader.js:1" }, - { - "message": "Missing item type\nInvoke when JSON file is loaded", - "line": " src/pixi/loaders/SpineLoader.js:54" - }, { "message": "Missing item type", "line": " src/pixi/loaders/SpriteSheetLoader.js:1" }, - { - "message": "Missing item type\nThis will begin loading the JSON file", - "line": " src/pixi/loaders/SpriteSheetLoader.js:37" - }, - { - "message": "Missing item type\nInvoke when JSON file is loaded", - "line": " src/pixi/loaders/SpriteSheetLoader.js:50" - }, - { - "message": "Missing item type\nInvoke when all files are loaded (json and texture)", - "line": " src/pixi/loaders/SpriteSheetLoader.js:85" - }, { "message": "Missing item type", "line": " src/pixi/primitives/Graphics.js:1" @@ -3937,24 +6063,16 @@ "line": " src/pixi/renderers/canvas/CanvasRenderer.js:1" }, { - "message": "Missing item type\nresizes the canvas view to the specified width and height", - "line": " src/pixi/renderers/canvas/CanvasRenderer.js:110" + "message": "Missing item type", + "line": " src/pixi/renderers/webgl/PixiShader.js:1" }, { "message": "Missing item type", - "line": " src/pixi/renderers/canvas/CanvasRenderer.js:124" + "line": " src/pixi/renderers/webgl/PrimitiveShader.js:1" }, { "message": "Missing item type", - "line": " src/pixi/renderers/canvas/CanvasRenderer.js:235" - }, - { - "message": "Missing item type", - "line": " src/pixi/renderers/canvas/CanvasRenderer.js:268" - }, - { - "message": "Missing item type", - "line": " src/pixi/renderers/canvas/CanvasRenderer.js:299" + "line": " src/pixi/renderers/webgl/StripShader.js:1" }, { "message": "Missing item type", @@ -3973,12 +6091,8 @@ "line": " src/pixi/renderers/webgl/WebGLBatch.js:31" }, { - "message": "Missing item type\nCleans the batch so that is can be returned to an object pool and reused", - "line": " src/pixi/renderers/webgl/WebGLBatch.js:67" - }, - { - "message": "Missing item type\nGrows the size of the batch. As the elements in the batch cannot have a dynamic size this function is used to increase the size of the batch. It also creates a little extra room so that the batch does not need to be resized every time a sprite is added", - "line": " src/pixi/renderers/webgl/WebGLBatch.js:293" + "message": "Missing item type", + "line": " src/pixi/renderers/webgl/WebGLFilterManager.js:1" }, { "message": "Missing item type", @@ -3988,93 +6102,25 @@ "message": "Missing item type", "line": " src/pixi/renderers/webgl/WebGLRenderGroup.js:1" }, - { - "message": "Missing item type", - "line": " src/pixi/renderers/webgl/WebGLRenderGroup.js:725" - }, - { - "message": "Missing item type", - "line": " src/pixi/renderers/webgl/WebGLRenderGroup.js:732" - }, - { - "message": "Missing item type", - "line": " src/pixi/renderers/webgl/WebGLRenderGroup.js:787" - }, - { - "message": "Missing item type", - "line": " src/pixi/renderers/webgl/WebGLRenderGroup.js:875" - }, - { - "message": "Missing item type", - "line": " src/pixi/renderers/webgl/WebGLRenderGroup.js:912" - }, { "message": "Missing item type", "line": " src/pixi/renderers/webgl/WebGLRenderer.js:1" }, { "message": "Missing item type", - "line": " src/pixi/renderers/webgl/WebGLRenderer.js:90" - }, - { - "message": "Missing item type", - "line": " src/pixi/renderers/webgl/WebGLRenderer.js:105" - }, - { - "message": "Missing item type", - "line": " src/pixi/renderers/webgl/WebGLRenderer.js:115" - }, - { - "message": "Missing item type", - "line": " src/pixi/renderers/webgl/WebGLRenderer.js:204" - }, - { - "message": "Missing item type", - "line": " src/pixi/renderers/webgl/WebGLRenderer.js:290" - }, - { - "message": "Missing item type", - "line": " src/pixi/renderers/webgl/WebGLRenderer.js:299" - }, - { - "message": "Missing item type", - "line": " src/pixi/renderers/webgl/WebGLShaders.js:2" + "line": " src/pixi/renderers/webgl/WebGLShaders.js:1" }, { "message": "Missing item type", "line": " src/pixi/text/BitmapText.js:1" }, - { - "message": "Missing item type\nRenders text", - "line": " src/pixi/text/BitmapText.js:64" - }, - { - "message": "Missing item type", - "line": " src/pixi/text/BitmapText.js:137" - }, { "message": "Missing item type", "line": " src/pixi/text/Text.js:1" }, { "message": "Missing item type\nSet the copy for the text object. To split a line you can use \"\\n\"", - "line": " src/pixi/text/Text.js:63" - }, - { - "message": "Missing item type\nRenders text", - "line": " src/pixi/text/Text.js:74" - }, - { - "message": "Missing item type\nUpdates texture size based on canvas size", - "line": " src/pixi/text/Text.js:143" - }, - { - "message": "Missing item type", - "line": " src/pixi/text/Text.js:161" - }, - { - "message": "Missing item type\nA Text Object will apply wordwrap", - "line": " src/pixi/text/Text.js:203" + "line": " src/pixi/text/Text.js:65" }, { "message": "Missing item type", @@ -4096,10 +6142,6 @@ "message": "Missing item type\nhttps://github.com/mrdoob/eventtarget.js/\nTHankS mr DOob!", "line": " src/pixi/utils/EventTarget.js:1" }, - { - "message": "Missing item type\nProvides bind in a cross browser way.", - "line": " src/pixi/utils/Utils.js:38" - }, { "message": "Missing item type", "line": " src/pixi/InteractionManager.js:1" diff --git a/docs/files/src_pixi_InteractionManager.js.html b/docs/files/src_pixi_InteractionManager.js.html index e30e1a9..224d190 100644 --- a/docs/files/src_pixi_InteractionManager.js.html +++ b/docs/files/src_pixi_InteractionManager.js.html @@ -2,12 +2,12 @@ - src/pixi/InteractionManager.js - Pixi.JS - - - - - + src/pixi/InteractionManager.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,80 +166,103 @@
    -

    File: src/pixi/InteractionManager.js

    +

    File: src/pixi/InteractionManager.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    -
    -
    -
    -/**
    -The interaction manager deals with mouse and touch events. Any DisplayObject can be interactive
    -This manager also supports multitouch.
    -@class InteractionManager
    -@constructor
    -@param stage {Stage}
    -@type Stage
    -*/
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    + 
    + /**
    + * The interaction manager deals with mouse and touch events. Any DisplayObject can be interactive
    + * This manager also supports multitouch.
    + *
    + * @class InteractionManager
    + * @constructor
    + * @param stage {Stage} The stage to handle interactions
    + */
     PIXI.InteractionManager = function(stage)
     {
    -	/**
    +	/**
     	 * a refference to the stage
    +	 *
     	 * @property stage
     	 * @type Stage
    -	 */
    +	 */
     	this.stage = stage;
     
    -	// helpers
    -	this.tempPoint = new PIXI.Point();
    -	//this.tempMatrix =  mat3.create();
    -	
    -	this.mouseoverEnabled = true;
    -	
    -	/**
    -	 * the mouse data 
    +	/**
    +	 * the mouse data
    +	 *
     	 * @property mouse
     	 * @type InteractionData
    -	 */
    +	 */
     	this.mouse = new PIXI.InteractionData();
    -	
    -	/**
    -	 * an object that stores current touches (InteractionData) by id reference 
    +
    +	/**
    +	 * an object that stores current touches (InteractionData) by id reference
    +	 *
     	 * @property touchs
     	 * @type Object
    -	 */
    +	 */
     	this.touchs = {};
    -	
    -	//tiny little interactiveData pool!
    -	this.pool = [];
    -	
    -	this.interactiveItems = [];
     
    +
    +	
    +	// helpers
    +	this.tempPoint = new PIXI.Point();
    +	//this.tempMatrix =  mat3.create();
    +
    +	this.mouseoverEnabled = true;
    +
    +	//tiny little interactiveData pool!
    +	this.pool = [];
    +
    +	this.interactiveItems = [];
    +	this.interactionDOMElement = null;
    +
    +	//this will make it so that you dont have to call bind all the time
    +	this.onMouseMove = this.onMouseMove.bind( this );
    +	this.onMouseDown = this.onMouseDown.bind(this);
    +	this.onMouseOut = this.onMouseOut.bind(this);
    +	this.onMouseUp = this.onMouseUp.bind(this);
    +
    +	this.onTouchStart = this.onTouchStart.bind(this);
    +	this.onTouchEnd = this.onTouchEnd.bind(this);
    +	this.onTouchMove = this.onTouchMove.bind(this);
    +	
    +	
     	this.last = 0;
     }
     
    -// constructor
    -PIXI.InteractionManager.constructor = PIXI.InteractionManager;
    +// constructor
    +PIXI.InteractionManager.prototype.constructor = PIXI.InteractionManager;
     
    +/**
    + * Collects an interactive sprite recursively to have their interactions managed
    + *
    + * @method collectInteractiveSprite
    + * @param displayObject {DisplayObject} the displayObject to collect
    + * @param iParent {DisplayObject}
    + * @private
    + */
     PIXI.InteractionManager.prototype.collectInteractiveSprite = function(displayObject, iParent)
     {
     	var children = displayObject.children;
     	var length = children.length;
     	
    -	/// make an interaction tree... {item.__interactiveParent}
    +	/// make an interaction tree... {item.__interactiveParent}
     	for (var i = length-1; i >= 0; i--)
     	{
     		var child = children[i];
     		
    -		if(child.visible) {
    -			// push all interactive bits
    +//		if(child.visible) {
    +			// push all interactive bits
     			if(child.interactive)
     			{
     				iParent.interactiveChildren = true;
    -				//child.__iParent = iParent;
    +				//child.__iParent = iParent;
     				this.interactiveItems.push(child);
     
     				if(child.children.length > 0)
    @@ -232,48 +279,102 @@ PIXI.InteractionManager.prototype.collectInteractiveSprite = function(displayObj
     					this.collectInteractiveSprite(child, iParent);
     				}
     			}
    -		}
    +//		}
     	}
     }
     
    +/**
    + * Sets the target for event delegation
    + *
    + * @method setTarget
    + * @param target {WebGLRenderer|CanvasRenderer} the renderer to bind events to
    + * @private
    + */
     PIXI.InteractionManager.prototype.setTarget = function(target)
     {
    -	if (window.navigator.msPointerEnabled) 
    -	{
    -		// time to remove some of that zoom in ja..
    -		target.view.style["-ms-content-zooming"] = "none";
    -    	target.view.style["-ms-touch-action"] = "none"
    -    
    -		// DO some window specific touch!
    -	}
    -	
     	this.target = target;
    -	target.view.addEventListener('mousemove',  this.onMouseMove.bind(this), true);
    -	target.view.addEventListener('mousedown',  this.onMouseDown.bind(this), true);
    - 	document.body.addEventListener('mouseup',  this.onMouseUp.bind(this), true);
    - 	target.view.addEventListener('mouseout',   this.onMouseUp.bind(this), true);
    -	
    -	// aint no multi touch just yet!
    -	target.view.addEventListener("touchstart", this.onTouchStart.bind(this), true);
    -	target.view.addEventListener("touchend", this.onTouchEnd.bind(this), true);
    -	target.view.addEventListener("touchmove", this.onTouchMove.bind(this), true);
    +
    +	//check if the dom element has been set. If it has don't do anything
    +	if( this.interactionDOMElement === null ) {
    +
    +		this.setTargetDomElement( target.view );
    +	}
    +
    + 	document.body.addEventListener('mouseup',  this.onMouseUp, true);
     }
     
    +
    +/**
    + * Sets the dom element which will receive mouse/touch events. This is useful for when you have other DOM
    + * elements ontop of the renderers Canvas element. With this you'll be able to delegate another dom element
    + * to receive those events
    + *
    + * @method setTargetDomElement
    + * @param domElement {DOMElement} the dom element which will receive mouse and touch events
    + * @private
    + */
    +PIXI.InteractionManager.prototype.setTargetDomElement = function(domElement)
    +{
    +	//remove previouse listeners
    +	if( this.interactionDOMElement !== null ) 
    +	{
    +		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);
    +
    +	 	// 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);
    +	}
    +
    +
    +	if (window.navigator.msPointerEnabled) 
    +	{
    +		// time to remove some of that zoom in ja..
    +		domElement.style['-ms-content-zooming'] = 'none';
    +    	domElement.style['-ms-touch-action'] = 'none';
    +    
    +		// DO some window specific touch!
    +	}
    +
    +	this.interactionDOMElement = domElement;
    +
    +	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.addEventListener('touchstart', this.onTouchStart, true);
    +	domElement.addEventListener('touchend', this.onTouchEnd, true);
    +	domElement.addEventListener('touchmove', this.onTouchMove, true);
    +}
    +
    +
    +/**
    + * updates the state of interactive objects
    + *
    + * @method update
    + * @private
    + */
     PIXI.InteractionManager.prototype.update = function()
     {
     	if(!this.target)return;
     	
    -	// frequency of 30fps??
    +	// frequency of 30fps??
     	var now = Date.now();
     	var diff = now - this.last;
    -	diff = (diff * 30) / 1000;
    +	diff = (diff * 30) / 1000;
     	if(diff < 1)return;
     	this.last = now;
    -	//
    +	//
     	
    -	// ok.. so mouse events??
    -	// yes for now :)
    -	// OPTIMSE - how often to check??
    +	// ok.. so mouse events??
    +	// yes for now :)
    +	// OPTIMSE - how often to check??
     	if(this.dirty)
     	{
     		this.dirty = false;
    @@ -287,34 +388,37 @@ PIXI.InteractionManager.prototype.update = function()
     		this.interactiveItems = [];
     		
     		if(this.stage.interactive)this.interactiveItems.push(this.stage);
    -		// go through and collect all the objects that are interactive..
    +		// go through and collect all the objects that are interactive..
     		this.collectInteractiveSprite(this.stage, this.stage);
     	}
     	
    -	// loop through interactive objects!
    +	// loop through interactive objects!
     	var length = this.interactiveItems.length;
     	
    -	this.target.view.style.cursor = "default";	
    +	this.interactionDOMElement.style.cursor = "default";	
     				
     	for (var i = 0; i < length; i++)
     	{
     		var item = this.interactiveItems[i];
    -		if(!item.visible)continue;
     		
    -		// OPTIMISATION - only calculate every time if the mousemove function exists..
    -		// OK so.. does the object have any other interactive functions?
    -		// hit-test the clip!
    +		
    +		//if(!item.visible)continue;
    +		
    +		// OPTIMISATION - only calculate every time if the mousemove function exists..
    +		// OK so.. does the object have any other interactive functions?
    +		// hit-test the clip!
     		
     		
     		if(item.mouseover || item.mouseout || item.buttonMode)
     		{
    -			// ok so there are some functions so lets hit test it..
    +			// ok so there are some functions so lets hit test it..
     			item.__hit = this.hitTest(item, this.mouse);
    -			// ok so deal with interactions..
    -			// loks like there was a hit!
    +			this.mouse.target = item;
    +			// ok so deal with interactions..
    +			// loks like there was a hit!
     			if(item.__hit)
     			{
    -				if(item.buttonMode)this.target.view.style.cursor = "pointer";	
    +				if(item.buttonMode) this.interactionDOMElement.style.cursor = "pointer";	
     				
     				if(!item.__isOver)
     				{
    @@ -327,25 +431,32 @@ PIXI.InteractionManager.prototype.update = function()
     			{
     				if(item.__isOver)
     				{
    -					// roll out!
    +					// roll out!
     					if(item.mouseout)item.mouseout(this.mouse);
     					item.__isOver = false;	
     				}
     			}
     		}
     		
    -		// --->
    +		// --->
     	}
     }
     
    +/**
    + * Is called when the mouse moves accross the renderer element
    + *
    + * @method onMouseMove
    + * @param event {Event} The DOM event of the mouse moving
    + * @private
    + */
     PIXI.InteractionManager.prototype.onMouseMove = function(event)
     {
    -	this.mouse.originalEvent = event || window.event; //IE uses window.event
    -	// TODO optimize by not check EVERY TIME! maybe half as often? //
    -	var rect = this.target.view.getBoundingClientRect();
    +	this.mouse.originalEvent = event || window.event; //IE uses window.event
    +	// TODO optimize by not check EVERY TIME! maybe half as often? //
    +	var rect = this.interactionDOMElement.getBoundingClientRect();
     	
    -	this.mouse.global.x = (event.clientX - rect.left) * (this.target.width / rect.width);
    -	this.mouse.global.y = (event.clientY - rect.top) * ( this.target.height / rect.height);
    +	this.mouse.global.x = (event.clientX - rect.left) * (this.target.width / rect.width);
    +	this.mouse.global.y = (event.clientY - rect.top) * ( this.target.height / rect.height);
     	
     	var length = this.interactiveItems.length;
     	var global = this.mouse.global;
    @@ -357,29 +468,35 @@ PIXI.InteractionManager.prototype.onMouseMove = function(event)
     		
     		if(item.mousemove)
     		{
    -			//call the function!
    +			//call the function!
     			item.mousemove(this.mouse);
     		}
     	}
     }
     
    +/**
    + * Is called when the mouse button is pressed down on the renderer element
    + *
    + * @method onMouseDown
    + * @param event {Event} The DOM event of a mouse button being pressed down
    + * @private
    + */
     PIXI.InteractionManager.prototype.onMouseDown = function(event)
     {
    -	event.preventDefault();
    -	this.mouse.originalEvent = event || window.event; //IE uses window.event
    +	this.mouse.originalEvent = event || window.event; //IE uses window.event
     	
    -	// loop through inteaction tree...
    -	// hit test each item! -> 
    -	// get interactive items under point??
    -	//stage.__i
    +	// loop through inteaction tree...
    +	// hit test each item! -> 
    +	// get interactive items under point??
    +	//stage.__i
     	var length = this.interactiveItems.length;
     	var global = this.mouse.global;
     	
     	var index = 0;
     	var parent = this.stage;
     	
    -	// while 
    -	// hit test 
    +	// while 
    +	// hit test 
     	for (var i = 0; i < length; i++)
     	{
     		var item = this.interactiveItems[i];
    @@ -391,20 +508,47 @@ PIXI.InteractionManager.prototype.onMouseDown = function(event)
     			
     			if(item.__hit)
     			{
    -				//call the function!
    +				//call the function!
     				if(item.mousedown)item.mousedown(this.mouse);
     				item.__isDown = true;
     				
    -				// just the one!
    +				// just the one!
     				if(!item.interactiveChildren)break;
     			}
     		}
     	}
     }
     
    +
    +PIXI.InteractionManager.prototype.onMouseOut = function(event)
    +{
    +	var length = this.interactiveItems.length;
    +	
    +	this.interactionDOMElement.style.cursor = "default";	
    +				
    +	for (var i = 0; i < length; i++)
    +	{
    +		var item = this.interactiveItems[i];
    +		
    +		if(item.__isOver)
    +		{
    +			this.mouse.target = item;
    +			if(item.mouseout)item.mouseout(this.mouse);
    +			item.__isOver = false;	
    +		}
    +	}
    +}
    +
    +/**
    + * Is called when the mouse button is released on the renderer element
    + *
    + * @method onMouseUp
    + * @param event {Event} The DOM event of a mouse button being released
    + * @private
    + */
     PIXI.InteractionManager.prototype.onMouseUp = function(event)
     {
    -	this.mouse.originalEvent = event || window.event; //IE uses window.event
    +	this.mouse.originalEvent = event || window.event; //IE uses window.event
     	
     	var global = this.mouse.global;
     	
    @@ -422,7 +566,7 @@ PIXI.InteractionManager.prototype.onMouseUp = function(event)
     			
     			if(item.__hit && !up)
     			{
    -				//call the function!
    +				//call the function!
     				if(item.mouseup)
     				{
     					item.mouseup(this.mouse);
    @@ -447,30 +591,42 @@ PIXI.InteractionManager.prototype.onMouseUp = function(event)
     	}
     }
     
    +/**
    + * Tests if the current mouse coords hit a sprite
    + *
    + * @method hitTest
    + * @param item {DisplayObject} The displayObject to test for a hit
    + * @param interactionData {InteractionData} The interactiondata object to update in the case of a hit
    + * @private
    + */
     PIXI.InteractionManager.prototype.hitTest = function(item, interactionData)
     {
     	var global = interactionData.global;
     	
    -	if(!item.visible)return false;
    +	if(item.vcount !== PIXI.visibleCount)return false;
     
     	var isSprite = (item instanceof PIXI.Sprite),
     		worldTransform = item.worldTransform,
     		a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2],
     		a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5],
    -		id = 1 / (a00 * a11 + a01 * -a10),
    +		id = 1 / (a00 * a11 + a01 * -a10),
     		x = a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id,
     		y = a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id;
     
    -	//a sprite or display object with a hit area defined
    +	interactionData.target = item;
    +	
    +	//a sprite or display object with a hit area defined
     	if(item.hitArea && item.hitArea.contains) {
     		if(item.hitArea.contains(x, y)) {
    -			if(isSprite)
    -				interactionData.target = item;
    +			//if(isSprite)
    +			interactionData.target = item;
     
     			return true;
     		}
    +		
    +		return false;
     	}
    -	// a sprite with no hitarea defined
    +	// a sprite with no hitarea defined
     	else if(isSprite)
     	{
     		var width = item.texture.frame.width,
    @@ -484,7 +640,7 @@ PIXI.InteractionManager.prototype.hitTest = function(item, interactionData)
     		
     			if(y > y1 && y < y1 + height)
     			{
    -				// set the target property if a hit is true!
    +				// set the target property if a hit is true!
     				interactionData.target = item
     				return true;
     			}
    @@ -497,28 +653,38 @@ PIXI.InteractionManager.prototype.hitTest = function(item, interactionData)
     	{
     		var tempItem = item.children[i];
     		var hit = this.hitTest(tempItem, interactionData);
    -		if(hit)return true;
    +		if(hit)
    +		{
    +			// hmm.. TODO SET CORRECT TARGET?
    +			interactionData.target = item
    +			return true;
    +		}
     	}
     
     	return false;	
     }
     
    -
    -
    +/**
    + * Is called when a touch is moved accross the renderer element
    + *
    + * @method onTouchMove
    + * @param event {Event} The DOM event of a touch moving accross the renderer view
    + * @private
    + */
     PIXI.InteractionManager.prototype.onTouchMove = function(event)
     {
    -	this.mouse.originalEvent = event || window.event; //IE uses window.event
    -	var rect = this.target.view.getBoundingClientRect();
    +	var rect = this.interactionDOMElement.getBoundingClientRect();
     	var changedTouches = event.changedTouches;
     	
     	for (var i=0; i < changedTouches.length; i++) 
     	{
     		var touchEvent = changedTouches[i];
     		var touchData = this.touchs[touchEvent.identifier];
    +		touchData.originalEvent =  event || window.event;
     		
    -		// update the touch position
    -		touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
    -		touchData.global.y = (touchEvent.clientY - rect.top)  * (this.target.height / rect.height);
    +		// update the touch position
    +		touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
    +		touchData.global.y = (touchEvent.clientY - rect.top)  * (this.target.height / rect.height);
     	}
     	
     	var length = this.interactiveItems.length;
    @@ -529,12 +695,16 @@ PIXI.InteractionManager.prototype.onTouchMove = function(event)
     	}
     }
     
    +/**
    + * Is called when a touch is started on the renderer element
    + *
    + * @method onTouchStart
    + * @param event {Event} The DOM event of a touch starting on the renderer view
    + * @private
    + */
     PIXI.InteractionManager.prototype.onTouchStart = function(event)
     {
    -	event.preventDefault();
    -	this.mouse.originalEvent = event || window.event; //IE uses window.event
    -	
    -	var rect = this.target.view.getBoundingClientRect();
    +	var rect = this.interactionDOMElement.getBoundingClientRect();
     	
     	var changedTouches = event.changedTouches;
     	for (var i=0; i < changedTouches.length; i++) 
    @@ -544,9 +714,11 @@ PIXI.InteractionManager.prototype.onTouchStart = function(event)
     		var touchData = this.pool.pop();
     		if(!touchData)touchData = new PIXI.InteractionData();
     		
    +		touchData.originalEvent =  event || window.event;
    +		
     		this.touchs[touchEvent.identifier] = touchData;
    -		touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
    -		touchData.global.y = (touchEvent.clientY - rect.top)  * (this.target.height / rect.height);
    +		touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
    +		touchData.global.y = (touchEvent.clientY - rect.top)  * (this.target.height / rect.height);
     		
     		var length = this.interactiveItems.length;
     		
    @@ -560,7 +732,7 @@ PIXI.InteractionManager.prototype.onTouchStart = function(event)
     				
     				if(item.__hit)
     				{
    -					//call the function!
    +					//call the function!
     					if(item.touchstart)item.touchstart(touchData);
     					item.__isDown = true;
     					item.__touchData = touchData;
    @@ -570,36 +742,41 @@ PIXI.InteractionManager.prototype.onTouchStart = function(event)
     			}
     		}
     	}
    -	
     }
     
    +/**
    + * Is called when a touch is ended on the renderer element
    + *
    + * @method onTouchEnd
    + * @param event {Event} The DOM event of a touch ending on the renderer view
    + * @private
    + */
     PIXI.InteractionManager.prototype.onTouchEnd = function(event)
     {
    -	this.mouse.originalEvent = event || window.event; //IE uses window.event
    -	var rect = this.target.view.getBoundingClientRect();
    +	//this.mouse.originalEvent = event || window.event; //IE uses window.event
    +	var rect = this.interactionDOMElement.getBoundingClientRect();
     	var changedTouches = event.changedTouches;
     	
     	for (var i=0; i < changedTouches.length; i++) 
     	{
    -		 
     		var touchEvent = changedTouches[i];
     		var touchData = this.touchs[touchEvent.identifier];
     		var up = false;
    -		touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
    -		touchData.global.y = (touchEvent.clientY - rect.top)  * (this.target.height / rect.height);
    +		touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
    +		touchData.global.y = (touchEvent.clientY - rect.top)  * (this.target.height / rect.height);
     		
     		var length = this.interactiveItems.length;
     		for (var j = 0; j < length; j++)
     		{
     			var item = this.interactiveItems[j];
    -			var itemTouchData = item.__touchData; // <-- Here!
    +			var itemTouchData = item.__touchData; // <-- Here!
     			item.__hit = this.hitTest(item, touchData);
     		
     			if(itemTouchData == touchData)
     			{
    -				// so this one WAS down...
    -				
    -				// hitTest??
    +				// so this one WAS down...
    +				touchData.originalEvent =  event || window.event;
    +				// hitTest??
     				
     				if(item.touchend || item.tap)
     				{
    @@ -632,67 +809,71 @@ PIXI.InteractionManager.prototype.onTouchEnd = function(event)
     				
     			}
     		}
    -		// remove the touch..
    +		// remove the touch..
     		this.pool.push(touchData);
     		this.touchs[touchEvent.identifier] = null;
     	}
     }
     
    -/**
    -@class InteractionData
    -@constructor
    -*/
    +/**
    + * Holds all information related to an Interaction event
    + *
    + * @class InteractionData
    + * @constructor
    + */
     PIXI.InteractionData = function()
     {
    -	/**
    -	 * This point stores the global coords of where the touch/mouse event happened
    +	/**
    +	 * This point stores the global coords of where the touch/mouse event happened
    +	 *
     	 * @property global 
     	 * @type Point
    -	 */
    +	 */
     	this.global = new PIXI.Point();
     	
    -	// this is here for legacy... but will remove
    +	// this is here for legacy... but will remove
     	this.local = new PIXI.Point();
     
    -	/**
    +	/**
     	 * The target Sprite that was interacted with
    +	 *
     	 * @property target
     	 * @type Sprite
    -	 */
    +	 */
     	this.target;
     
    -	/**
    +	/**
     	 * When passed to an event handler, this will be the original DOM Event that was captured
    +	 *
     	 * @property originalEvent
     	 * @type Event
    -	 */
    +	 */
     	this.originalEvent;
     }
     
    -/**
    +/**
      * This will return the local coords of the specified displayObject for this InteractionData
    + *
      * @method getLocalPosition
      * @param displayObject {DisplayObject} The DisplayObject that you would like the local coords off
      * @return {Point} A point containing the coords of the InteractionData position relative to the DisplayObject
    - */
    + */
     PIXI.InteractionData.prototype.getLocalPosition = function(displayObject)
     {
     	var worldTransform = displayObject.worldTransform;
     	var global = this.global;
     	
    -	// do a cheeky transform to get the mouse coords;
    +	// do a cheeky transform to get the mouse coords;
     	var a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2],
             a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5],
    -        id = 1 / (a00 * a11 + a01 * -a10);
    -	// set the mouse coords...
    +        id = 1 / (a00 * a11 + a01 * -a10);
    +	// set the mouse coords...
     	return new PIXI.Point(a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id,
     							   a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id)
     }
     
    -// constructor
    -PIXI.InteractionData.constructor = PIXI.InteractionData;
    -
    -
    +// constructor
    +PIXI.InteractionData.prototype.constructor = PIXI.InteractionData;
     
         
    @@ -703,13 +884,13 @@ PIXI.InteractionData.constructor = PIXI.InteractionData;
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_Intro.js.html b/docs/files/src_pixi_Intro.js.html index e5f2ae9..f44df3b 100644 --- a/docs/files/src_pixi_Intro.js.html +++ b/docs/files/src_pixi_Intro.js.html @@ -2,12 +2,12 @@ - src/pixi/Intro.js - Pixi.JS - - - - - + src/pixi/Intro.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,13 +166,13 @@
    -

    File: src/pixi/Intro.js

    +

    File: src/pixi/Intro.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
     (function(){
     
    @@ -163,13 +187,13 @@
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_Outro.js.html b/docs/files/src_pixi_Outro.js.html index 1eacb07..b8e33d6 100644 --- a/docs/files/src_pixi_Outro.js.html +++ b/docs/files/src_pixi_Outro.js.html @@ -2,12 +2,12 @@ - src/pixi/Outro.js - Pixi.JS - - - - - + src/pixi/Outro.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,24 +166,24 @@
    -

    File: src/pixi/Outro.js

    +

    File: src/pixi/Outro.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    -
    - if (typeof exports !== 'undefined') {
    -    if (typeof module !== 'undefined' && module.exports) {
    -      exports = module.exports = PIXI;
    -    }
    -    exports.PIXI = PIXI;
    -  } else {
    -    root.PIXI = PIXI;
    -  }
    -
    -
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +    if (typeof exports !== 'undefined') {
    +        if (typeof module !== 'undefined' && module.exports) {
    +            exports = module.exports = PIXI;
    +        }
    +        exports.PIXI = PIXI;
    +    } else if (typeof define !== 'undefined' && define.amd) {
    +        define(PIXI);
    +    } else {
    +        root.PIXI = PIXI;
    +    }
     }).call(this);
         
    @@ -170,13 +194,13 @@
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_Pixi.js.html b/docs/files/src_pixi_Pixi.js.html index 3ac2a71..08affe9 100644 --- a/docs/files/src_pixi_Pixi.js.html +++ b/docs/files/src_pixi_Pixi.js.html @@ -2,12 +2,12 @@ - src/pixi/Pixi.js - Pixi.JS - - - - - + src/pixi/Pixi.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,17 +166,17 @@
    -

    File: src/pixi/Pixi.js

    +

    File: src/pixi/Pixi.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -/**
    -@module PIXI
    - */
    +/**
    + * @module PIXI
    + */
     var PIXI = PIXI || {};
     
         
    @@ -164,13 +188,13 @@ var PIXI = PIXI || {};
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_core_Circle.js.html b/docs/files/src_pixi_core_Circle.js.html index a3eb2f7..5eef8ec 100644 --- a/docs/files/src_pixi_core_Circle.js.html +++ b/docs/files/src_pixi_core_Circle.js.html @@ -2,12 +2,12 @@ - src/pixi/core/Circle.js - Pixi.JS - - - - - + src/pixi/core/Circle.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,60 +166,66 @@
    -

    File: src/pixi/core/Circle.js

    +

    File: src/pixi/core/Circle.js

    -/**
    +/**
      * @author Chad Engler <chad@pantherdev.com>
    - */
    + */
     
    -/**
    +/**
    + * The Circle object can be used to specify a hit area for displayobjects
    + *
      * @class Circle
      * @constructor
      * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this circle
      * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this circle
      * @param radius {Number} The radius of the circle
    - */
    + */
     PIXI.Circle = function(x, y, radius)
     {
    -    /**
    +    /**
          * @property x
          * @type Number
          * @default 0
    -     */
    +     */
         this.x = x || 0;
    -    
    -    /**
    +
    +    /**
          * @property y
          * @type Number
          * @default 0
    -     */
    +     */
         this.y = y || 0;
     
    -    /**
    +    /**
          * @property radius
          * @type Number
          * @default 0
    -     */
    +     */
         this.radius = radius || 0;
     }
     
    -/**
    +/**
    + * Creates a clone of this Circle instance
    + *
      * @method clone
    - * @return a copy of the polygon
    - */
    + * @return {Circle} a copy of the polygon
    + */
     PIXI.Circle.prototype.clone = function()
     {
         return new PIXI.Circle(this.x, this.y, this.radius);
     }
     
    -/**
    +/**
    + * Checks if the x, and y coords passed to this function are contained within this circle
    + *
      * @method contains
      * @param x {Number} The X coord of the point to test
      * @param y {Number} The Y coord of the point to test
    - * @return if the x/y coords are within this polygon
    - */
    + * @return {Boolean} if the x/y coords are within this polygon
    + */
     PIXI.Circle.prototype.contains = function(x, y)
     {
         if(this.radius <= 0)
    @@ -211,7 +241,8 @@ PIXI.Circle.prototype.contains = function(x, y)
         return (dx + dy <= r2);
     }
     
    -PIXI.Circle.constructor = PIXI.Circle;
    +// constructor
    +PIXI.Circle.prototype.constructor = PIXI.Circle;
     
     
         
    @@ -223,13 +254,13 @@ PIXI.Circle.constructor = PIXI.Circle;
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_core_Ellipse.js.html b/docs/files/src_pixi_core_Ellipse.js.html index 756dc05..c6e13fa 100644 --- a/docs/files/src_pixi_core_Ellipse.js.html +++ b/docs/files/src_pixi_core_Ellipse.js.html @@ -2,12 +2,12 @@ - src/pixi/core/Ellipse.js - Pixi.JS - - - - - + src/pixi/core/Ellipse.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,77 +166,83 @@
    -

    File: src/pixi/core/Ellipse.js

    +

    File: src/pixi/core/Ellipse.js

    -/**
    +/**
      * @author Chad Engler <chad@pantherdev.com>
    - */
    + */
     
    -/**
    +/**
    + * The Ellipse object can be used to specify a hit area for displayobjects
    + *
      * @class Ellipse
      * @constructor
    - * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this circle
    - * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this circle
    - * @param width {Number} The overall height of this ellipse
    - * @param height {Number} The overall width of this ellipse
    - */
    + * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this ellipse
    + * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this ellipse
    + * @param width {Number} The overall width of this ellipse
    + * @param height {Number} The overall height of this ellipse
    + */
     PIXI.Ellipse = function(x, y, width, height)
     {
    -    /**
    +    /**
          * @property x
          * @type Number
          * @default 0
    -     */
    +     */
         this.x = x || 0;
    -    
    -    /**
    +
    +    /**
          * @property y
          * @type Number
          * @default 0
    -     */
    +     */
         this.y = y || 0;
    -    
    -    /**
    +
    +    /**
          * @property width
          * @type Number
          * @default 0
    -     */
    +     */
         this.width = width || 0;
    -    
    -    /**
    +
    +    /**
          * @property height
          * @type Number
          * @default 0
    -     */
    +     */
         this.height = height || 0;
     }
     
    -/**
    +/**
    + * Creates a clone of this Ellipse instance
    + *
      * @method clone
    - * @return a copy of the polygon
    - */
    + * @return {Ellipse} a copy of the ellipse
    + */
     PIXI.Ellipse.prototype.clone = function()
     {
         return new PIXI.Ellipse(this.x, this.y, this.width, this.height);
     }
     
    -/**
    +/**
    + * Checks if the x, and y coords passed to this function are contained within this ellipse
    + *
      * @method contains
      * @param x {Number} The X coord of the point to test
      * @param y {Number} The Y coord of the point to test
    - * @return if the x/y coords are within this polygon
    - */
    + * @return {Boolean} if the x/y coords are within this ellipse
    + */
     PIXI.Ellipse.prototype.contains = function(x, y)
     {
         if(this.width <= 0 || this.height <= 0)
             return false;
     
    -    //normalize the coords to an ellipse with center 0,0
    -    //and a radius of 0.5
    -    var normx = ((x - this.x) / this.width) - 0.5,
    -        normy = ((y - this.y) / this.height) - 0.5;
    +    //normalize the coords to an ellipse with center 0,0
    +    //and a radius of 0.5
    +    var normx = ((x - this.x) / this.width) - 0.5,
    +        normy = ((y - this.y) / this.height) - 0.5;
     
         normx *= normx;
         normy *= normy;
    @@ -225,8 +255,8 @@ PIXI.Ellipse.getBounds = function()
         return new PIXI.Rectangle(this.x, this.y, this.width, this.height);
     }
     
    -PIXI.Ellipse.constructor = PIXI.Ellipse;
    -
    +// constructor
    +PIXI.Ellipse.prototype.constructor = PIXI.Ellipse;
     
         
    @@ -237,13 +267,13 @@ PIXI.Ellipse.constructor = PIXI.Ellipse;
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_core_Point.js.html b/docs/files/src_pixi_core_Point.js.html index 0d67d6c..04e593d 100644 --- a/docs/files/src_pixi_core_Point.js.html +++ b/docs/files/src_pixi_core_Point.js.html @@ -2,12 +2,12 @@ - src/pixi/core/Point.js - Pixi.JS - - - - - + src/pixi/core/Point.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,49 +166,52 @@
    -

    File: src/pixi/core/Point.js

    +

    File: src/pixi/core/Point.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -/**
    +/**
      * The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
    + *
      * @class Point
    - * @constructor 
    + * @constructor
      * @param x {Number} position of the point
      * @param y {Number} position of the point
    - */
    + */
     PIXI.Point = function(x, y)
     {
    -	/**
    -	 * @property x 
    +	/**
    +	 * @property x
     	 * @type Number
     	 * @default 0
    -	 */
    +	 */
     	this.x = x || 0;
    -	
    -	/**
    +
    +	/**
     	 * @property y
     	 * @type Number
     	 * @default 0
    -	 */
    +	 */
     	this.y = y || 0;
     }
     
    -/** 
    +/**
    + * Creates a clone of this point
    + *
      * @method clone
    - * @return a copy of the point
    - */
    + * @return {Point} a copy of the point
    + */
     PIXI.Point.prototype.clone = function()
     {
     	return new PIXI.Point(this.x, this.y);
     }
     
    -// constructor
    -PIXI.Point.constructor = PIXI.Point;
    +// constructor
    +PIXI.Point.prototype.constructor = PIXI.Point;
     
     
         
    @@ -196,13 +223,13 @@ PIXI.Point.constructor = PIXI.Point;
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_core_Polygon.js.html b/docs/files/src_pixi_core_Polygon.js.html index 4ea7868..2ba82b6 100644 --- a/docs/files/src_pixi_core_Polygon.js.html +++ b/docs/files/src_pixi_core_Polygon.js.html @@ -2,12 +2,12 @@ - src/pixi/core/Polygon.js - Pixi.JS - - - - - + src/pixi/core/Polygon.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,23 +166,30 @@
    -

    File: src/pixi/core/Polygon.js

    +

    File: src/pixi/core/Polygon.js

    -/**
    +/**
      * @author Adrien Brault <adrien.brault@gmail.com>
    - */
    + */
     
    -/**
    +/**
      * @class Polygon
      * @constructor
    - * @param points {Array<Point>|Array<Number>} This cna be an array of Points or a flat array of numbers
    - *      that will be interpreted as [x,y, x,y, ...]
    - */
    + * @param points* {Array<Point>|Array<Number>|Point...|Number...} This can be an array of Points that form the polygon,
    + *      a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arguments passed can be
    + *      all the points of the polygon e.g. `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the
    + *      arguments passed can be flat x,y values e.g. `new PIXI.Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are
    + *      Numbers.
    + */
     PIXI.Polygon = function(points)
     {
    -    //if this is a flat array of numbers, convert it to points
    +    //if points isn't an array, use arguments as the array
    +    if(!(points instanceof Array))
    +        points = Array.prototype.slice.call(arguments);
    +
    +    //if this is a flat array of numbers, convert it to points
         if(typeof points[0] === 'number') {
             var p = [];
             for(var i = 0, il = points.length; i < il; i+=2) {
    @@ -173,10 +204,12 @@ PIXI.Polygon = function(points)
     	this.points = points;
     }
     
    -/**
    +/**
    + * Creates a clone of this polygon
    + *
      * @method clone
    - * @return a copy of the polygon
    - */
    + * @return {Polygon} a copy of the polygon
    + */
     PIXI.Polygon.prototype.clone = function()
     {
     	var points = [];
    @@ -187,22 +220,24 @@ PIXI.Polygon.prototype.clone = function()
     	return new PIXI.Polygon(points);
     }
     
    -/**
    +/**
    + * Checks if the x, and y coords passed to this function are contained within this polygon
    + *
      * @method contains
      * @param x {Number} The X coord of the point to test
      * @param y {Number} The Y coord of the point to test
    - * @return if the x/y coords are within this polygon
    - */
    + * @return {Boolean} if the x/y coords are within this polygon
    + */
     PIXI.Polygon.prototype.contains = function(x, y)
     {
         var inside = false;
     
    -    // use some raycasting to test hits
    -    // https://github.com/substack/point-in-polygon/blob/master/index.js
    +    // use some raycasting to test hits
    +    // https://github.com/substack/point-in-polygon/blob/master/index.js
         for(var i = 0, j = this.points.length - 1; i < this.points.length; j = i++) {
             var xi = this.points[i].x, yi = this.points[i].y,
                 xj = this.points[j].x, yj = this.points[j].y,
    -            intersect = ((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
    +            intersect = ((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
     
             if(intersect) inside = !inside;
         }
    @@ -210,8 +245,8 @@ PIXI.Polygon.prototype.contains = function(x, y)
         return inside;
     }
     
    -PIXI.Polygon.constructor = PIXI.Polygon;
    -
    +// constructor
    +PIXI.Polygon.prototype.constructor = PIXI.Polygon;
     
         
    @@ -222,13 +257,13 @@ PIXI.Polygon.constructor = PIXI.Polygon;
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_core_Rectangle.js.html b/docs/files/src_pixi_core_Rectangle.js.html index de18763..ff73bde 100644 --- a/docs/files/src_pixi_core_Rectangle.js.html +++ b/docs/files/src_pixi_core_Rectangle.js.html @@ -2,12 +2,12 @@ - src/pixi/core/Rectangle.js - Pixi.JS - - - - - + src/pixi/core/Rectangle.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,80 +166,85 @@
    -

    File: src/pixi/core/Rectangle.js

    +

    File: src/pixi/core/Rectangle.js

    -/**
    - * @author Mat Groves http://matgroves.com/
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/
    + */
     
    -/**
    +/**
      * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height.
    + *
      * @class Rectangle
    - * @constructor 
    - * @param x {Number} position of the rectangle
    - * @param y {Number} position of the rectangle
    - * @param width {Number} of the rectangle
    - * @param height {Number} of the rectangle
    - */
    + * @constructor
    + * @param x {Number} The X coord of the upper-left corner of the rectangle
    + * @param y {Number} The Y coord of the upper-left corner of the rectangle
    + * @param width {Number} The overall width of this rectangle
    + * @param height {Number} The overall height of this rectangle
    + */
     PIXI.Rectangle = function(x, y, width, height)
     {
    -	/**
    +	/**
     	 * @property x
     	 * @type Number
     	 * @default 0
    -	 */
    +	 */
     	this.x = x || 0;
    -	
    -	/**
    +
    +	/**
     	 * @property y
     	 * @type Number
     	 * @default 0
    -	 */
    +	 */
     	this.y = y || 0;
    -	
    -	/**
    +
    +	/**
     	 * @property width
     	 * @type Number
     	 * @default 0
    -	 */
    +	 */
     	this.width = width || 0;
    -	
    -	/**
    +
    +	/**
     	 * @property height
     	 * @type Number
     	 * @default 0
    -	 */
    +	 */
     	this.height = height || 0;
     }
     
    -/** 
    +/**
    + * Creates a clone of this Rectangle
    + *
      * @method clone
    - * @return a copy of the rectangle
    - */
    + * @return {Rectangle} a copy of the rectangle
    + */
     PIXI.Rectangle.prototype.clone = function()
     {
     	return new PIXI.Rectangle(this.x, this.y, this.width, this.height);
     }
     
    -/**
    +/**
    + * Checks if the x, and y coords passed to this function are contained within this Rectangle
    + *
      * @method contains
      * @param x {Number} The X coord of the point to test
      * @param y {Number} The Y coord of the point to test
    - * @return if the x/y coords are within this polygon
    - */
    + * @return {Boolean} if the x/y coords are within this Rectangle
    + */
     PIXI.Rectangle.prototype.contains = function(x, y)
     {
         if(this.width <= 0 || this.height <= 0)
             return false;
     
     	var x1 = this.x;
    -	if(x > x1 && x < x1 + this.width)
    +	if(x >= x1 && x <= x1 + this.width)
     	{
     		var y1 = this.y;
    -		
    -		if(y > y1 && y < y1 + this.height)
    +
    +		if(y >= y1 && y <= y1 + this.height)
     		{
     			return true;
     		}
    @@ -224,8 +253,8 @@ PIXI.Rectangle.prototype.contains = function(x, y)
     	return false;
     }
     
    -// constructor
    -PIXI.Rectangle.constructor = PIXI.Rectangle;
    +// constructor
    +PIXI.Rectangle.prototype.constructor = PIXI.Rectangle;
     
     
         
    @@ -237,13 +266,13 @@ PIXI.Rectangle.constructor = PIXI.Rectangle;
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_display_DisplayObject.js.html b/docs/files/src_pixi_display_DisplayObject.js.html index f4c2f15..57725eb 100644 --- a/docs/files/src_pixi_display_DisplayObject.js.html +++ b/docs/files/src_pixi_display_DisplayObject.js.html @@ -2,12 +2,12 @@ - src/pixi/display/DisplayObject.js - Pixi.JS - - - - - + src/pixi/display/DisplayObject.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,218 +166,276 @@
    -

    File: src/pixi/display/DisplayObject.js

    +

    File: src/pixi/display/DisplayObject.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -/**
    - * this is the base class for all objects that are rendered on the screen.
    +/**
    + * The base class for all objects that are rendered on the screen.
    + *
      * @class DisplayObject
      * @constructor
    - */
    + */
     PIXI.DisplayObject = function()
     {
     	this.last = this;
     	this.first = this;
    -	
    -	/**
    +	/**
     	 * The coordinate of the object relative to the local coordinates of the parent.
    +	 *
     	 * @property position
     	 * @type Point
    -	 */
    +	 */
     	this.position = new PIXI.Point();
    -	
    -	/**
    +
    +	/**
     	 * The scale factor of the object.
    +	 *
     	 * @property scale
     	 * @type Point
    -	 */
    -	this.scale = new PIXI.Point(1,1);//{x:1, y:1};
    -	
    -	/**
    +	 */
    +	this.scale = new PIXI.Point(1,1);//{x:1, y:1};
    +
    +	/**
     	 * The pivot point of the displayObject that it rotates around
    +	 *
     	 * @property pivot
     	 * @type Point
    -	 */
    +	 */
     	this.pivot = new PIXI.Point(0,0);
    -	
    -	/**
    +
    +	/**
     	 * The rotation of the object in radians.
    +	 *
     	 * @property rotation
     	 * @type Number
    -	 */
    +	 */
     	this.rotation = 0;
    -	
    -	/**
    +
    +	/**
     	 * The opacity of the object.
    +	 *
     	 * @property alpha
     	 * @type Number
    -	 */	
    +	 */	
     	this.alpha = 1;
    -	
    -	/**
    +
    +	/**
     	 * The visibility of the object.
    +	 *
     	 * @property visible
     	 * @type Boolean
    -	 */	
    +	 */	
     	this.visible = true;
    -	this.worldVisible = false;
    -	
    -	/**
    -	 * [read-only] The display object container that contains this display object.
    -	 * @property parent
    -	 * @type DisplayObjectContainer
    -	 */	
    -	this.parent = null;
    -	
    -	/**
    -	 * [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.
    -	 * @property stage
    -	 * @type Stage
    -	 */	
    -	this.stage = null;
    -	
    -	/**
    -	 * This is the defined area that will pick up mouse / touch events. It is null by default.
    +
    +	/**
    +	 * This is the defined area that will pick up mouse / touch events. It is null by default.
     	 * Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)
    +	 *
     	 * @property hitArea
    -	 * @type Rectangle
    -	 */	
    +	 * @type Rectangle|Circle|Ellipse|Polygon
    +	 */	
     	this.hitArea = null;
    -	
    -	this.worldAlpha = 1;
    -	this.color = [];
    -	
    -	this.worldTransform = PIXI.mat3.create()//mat3.identity();
    -	this.localTransform = PIXI.mat3.create()//mat3.identity();
    -	
    -	this.dynamic = true;
    -	// chach that puppy!
    -	this._sr = 0;
    -	this._cr = 1;
    -	
    -	this.childIndex = 0;
    -	
    -	this.renderable = false;
    -	
    -	// [readonly] best not to toggle directly! use setInteractive()
    -	this._interactive = false;
    -	
    -	/**
    +
    +	/**
     	 * This is used to indicate if the displayObject should display a mouse hand cursor on rollover
    +	 *
     	 * @property buttonMode
     	 * @type Boolean
    -	 */
    +	 */
     	this.buttonMode = false;
    +
    +	/**
    +	 * Can this object be rendered
    +	 *
    +	 * @property renderable
    +	 * @type Boolean
    +	 */
    +	this.renderable = false;
    +
    +	/**
    +	 * [read-only] The display object container that contains this display object.
    +	 *
    +	 * @property parent
    +	 * @type DisplayObjectContainer
    +	 * @readOnly
    +	 */	
    +	this.parent = null;
    +
    +	/**
    +	 * [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.
    +	 *
    +	 * @property stage
    +	 * @type Stage
    +	 * @readOnly
    +	 */	
    +	this.stage = null;
    +
    +	/**
    +	 * [read-only] The multiplied alpha of the displayobject
    +	 *
    +	 * @property worldAlpha
    +	 * @type Number
    +	 * @readOnly
    +	 */
    +	this.worldAlpha = 1;
    +
    +	/**
    +	 * [read-only] Whether or not the object is interactive, do not toggle directly! use the `interactive` property
    +	 *
    +	 * @property _interactive
    +	 * @type Boolean
    +	 * @readOnly
    +	 * @private
    +	 */
    +	this._interactive = false;
    +
    +	/**
    +	 * [read-only] Current transform of the object based on world (parent) factors
    +	 *
    +	 * @property worldTransform
    +	 * @type Mat3
    +	 * @readOnly
    +	 * @private
    +	 */
    +	this.worldTransform = PIXI.mat3.create()//mat3.identity();
    +
    +	/**
    +	 * [read-only] Current transform of the object locally
    +	 *
    +	 * @property localTransform
    +	 * @type Mat3
    +	 * @readOnly
    +	 * @private
    +	 */
    +	this.localTransform = PIXI.mat3.create()//mat3.identity();
    +
    +	/**
    +	 * [NYI] Unkown
    +	 *
    +	 * @property color
    +	 * @type Array<>
    +	 * @private
    +	 */
    +	this.color = [];
    +
    +	/**
    +	 * [NYI] Holds whether or not this object is dynamic, for rendering optimization
    +	 *
    +	 * @property dynamic
    +	 * @type Boolean
    +	 * @private
    +	 */
    +	this.dynamic = true;
    +
    +	// chach that puppy!
    +	this._sr = 0;
    +	this._cr = 1;
    +
    +
    +	this.filterArea = new PIXI.Rectangle(0,0,1,1);
     	
    -	/*
    +	/*
     	 * MOUSE Callbacks
    -	 */
    -	
    -	/**
    +	 */
    +
    +	/**
     	 * A callback that is used when the users clicks on the displayObject with their mouse
     	 * @method click
     	 * @param interactionData {InteractionData}
    -	 */
    -	
    -	/**
    +	 */
    +
    +	/**
     	 * A callback that is used when the user clicks the mouse down over the sprite
     	 * @method mousedown
     	 * @param interactionData {InteractionData}
    -	 */
    -	 
    -	/**
    +	 */
    +
    +	/**
     	 * A callback that is used when the user releases the mouse that was over the displayObject
     	 * for this callback to be fired the mouse must have been pressed down over the displayObject
     	 * @method mouseup
     	 * @param interactionData {InteractionData}
    -	 */
    -	
    -	/**
    +	 */
    +
    +	/**
     	 * A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject
     	 * for this callback to be fired, The touch must have started over the displayObject
     	 * @method mouseupoutside
     	 * @param interactionData {InteractionData}
    -	 */
    -	
    -	/**
    +	 */
    +
    +	/**
     	 * A callback that is used when the users mouse rolls over the displayObject
     	 * @method mouseover
     	 * @param interactionData {InteractionData}
    -	 */
    -	
    -	/**
    +	 */
    +
    +	/**
     	 * A callback that is used when the users mouse leaves the displayObject
     	 * @method mouseout
     	 * @param interactionData {InteractionData}
    -	 */
    -	
    -	
    -	/*
    +	 */
    +
    +
    +	/*
     	 * TOUCH Callbacks
    -	 */
    -	
    -	/**
    +	 */
    +
    +	/**
     	 * A callback that is used when the users taps on the sprite with their finger
     	 * basically a touch version of click
     	 * @method tap
     	 * @param interactionData {InteractionData}
    -	 */
    -	
    -	/**
    +	 */
    +
    +	/**
     	 * A callback that is used when the user touch's over the displayObject
     	 * @method touchstart
     	 * @param interactionData {InteractionData}
    -	 */
    -	 
    -	/**
    +	 */
    +
    +	/**
     	 * A callback that is used when the user releases a touch over the displayObject
     	 * @method touchend
     	 * @param interactionData {InteractionData}
    -	 */
    -	
    -	/**
    +	 */
    +
    +	/**
     	 * A callback that is used when the user releases the touch that was over the displayObject
     	 * for this callback to be fired, The touch must have started over the sprite
     	 * @method touchendoutside
     	 * @param interactionData {InteractionData}
    -	 */
    +	 */
     }
     
    -// constructor
    -PIXI.DisplayObject.constructor = PIXI.DisplayObject;
    +// constructor
    +PIXI.DisplayObject.prototype.constructor = PIXI.DisplayObject;
     
    -//TODO make visible a getter setter
    -/*
    -Object.defineProperty(PIXI.DisplayObject.prototype, 'visible', {
    -    get: function() {
    -        return this._visible;
    -    },
    -    set: function(value) {
    -        this._visible = value;
    -    }
    -});*/
    -
    -/**
    +/**
      * [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default
      * Instead of using this function you can now simply set the interactive property to true or false
    + *
      * @method setInteractive
      * @param interactive {Boolean}
    - */
    + * @deprecated Simply set the `interactive` property directly
    + */
     PIXI.DisplayObject.prototype.setInteractive = function(interactive)
     {
     	this.interactive = interactive;
     }
     
    -/**
    +/**
      * Indicates if the sprite will have touch and mouse interactivity. It is false by default
    + *
      * @property interactive
      * @type Boolean
    - */
    + * @default false
    + */
     Object.defineProperty(PIXI.DisplayObject.prototype, 'interactive', {
         get: function() {
             return this._interactive;
    @@ -361,65 +443,129 @@ Object.defineProperty(PIXI.DisplayObject.prototype, 'interactive', {
         set: function(value) {
         	this._interactive = value;
         	
    -    	// TODO more to be done here..
    -		// need to sort out a re-crawl!
    +    	// TODO more to be done here..
    +		// need to sort out a re-crawl!
     		if(this.stage)this.stage.dirty = true;
         }
     });
     
    -/**
    +/**
      * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it.
      * In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping.
      * To remove a mask, set this property to null.
    + *
      * @property mask
    - * @type PIXI.Graphics
    - */
    + * @type Graphics
    + */
     Object.defineProperty(PIXI.DisplayObject.prototype, 'mask', {
         get: function() {
             return this._mask;
         },
         set: function(value) {
         	
    -        this._mask = value;
    -        
    +    	
             if(value)
             {
    -	        this.addFilter(value)
    +        	if(this._mask)
    +	    	{
    +	    		value.start = this._mask.start;
    +	    		value.end = this._mask.end;
    +	    	}
    +    		else
    +    		{
    +		        this.addFilter(value);
    +		        value.renderable = false;
    +    		}
             }
             else
             {
    -        	 this.removeFilter();
    +        	 this.removeFilter(this._mask);
    +			 this._mask.renderable = true;
             }
    +        
    +        this._mask = value;
         }
     });
     
    -/* 
    - * private
    - */
    -PIXI.DisplayObject.prototype.addFilter = function(mask)
    +/**
    + * Sets the filters for the displayObject. 
    + * * IMPORTANT: This is a webGL only feature and will be ignored by the canvas renderer.
    + * To remove filters simply set this property to 'null'
    + * @property filters
    + * @type Array An array of filters
    + */
    +Object.defineProperty(PIXI.DisplayObject.prototype, 'filters', {
    +    get: function() {
    +        return this._filters;
    +    },
    +    set: function(value) {
    +    	
    +        if(value)
    +        {
    +        	if(this._filters)this.removeFilter(this._filters);
    +	        this.addFilter(value);
    +
    +		    // now put all the passes in one place..
    +	        var passes = [];
    +	        for (var i = 0; i < value.length; i++) 
    +	        {
    +	        	var filterPasses = value[i].passes;
    +	        	for (var j = 0; j < filterPasses.length; j++) 
    +	        	{
    +	        		passes.push(filterPasses[j]);
    +	        	};
    +	        };
    +
    +	        value.start.filterPasses = passes;
    +        }
    +        else
    +        {
    +        	if(this._filters)this.removeFilter(this._filters);
    +        }
    +        
    +        this._filters = value;
    +
    +       
    +
    +        
    +    }
    +});
    +
    +/*
    + * Adds a filter to this displayObject
    + *
    + * @method addFilter
    + * @param mask {Graphics} the graphics object to use as a filter
    + * @private
    + */
    +PIXI.DisplayObject.prototype.addFilter = function(data)
     {
    -	if(this.filter)return;
    -	this.filter = true;
    +	//if(this.filter)return;
    +	//this.filter = true;
    +//	data[0].target = this;
     	
    -	
    -	// insert a filter block..
    +
    +	// insert a filter block..
    +	// TODO Onject pool thease bad boys..
     	var start = new PIXI.FilterBlock();
     	var end = new PIXI.FilterBlock();
     	
    +	data.start = start;
    +	data.end = end;
     	
    -	start.mask = mask;
    -	end.mask = mask;
    +	start.data = data;
    +	end.data = data;
     	
     	start.first = start.last =  this;
     	end.first = end.last = this;
     	
     	start.open = true;
     	
    -	/*
    -	 * 
    +	start.target = this;
    +	
    +	/*
     	 * insert start
    -	 * 
    -	 */
    +	 */
     	
     	var childFirst = start
     	var childLast = start
    @@ -446,13 +592,11 @@ PIXI.DisplayObject.prototype.addFilter = function(mask)
     	}
     	
     	
    -	// now insert the end filter block..
    +	// now insert the end filter block..
     	
    -	/*
    -	 * 
    +	/*
     	 * insert end filter
    -	 * 
    -	 */
    +	 */
     	var childFirst = end
     	var childLast = end
     	var nextObject = null;
    @@ -484,23 +628,28 @@ PIXI.DisplayObject.prototype.addFilter = function(mask)
     	
     	this.first = start;
     	
    -	// if webGL...
    +	// if webGL...
     	if(this.__renderGroup)
     	{
     		this.__renderGroup.addFilterBlocks(start, end);
     	}
     	
    -	mask.renderable = false;
    -	
     }
     
    -PIXI.DisplayObject.prototype.removeFilter = function()
    +/*
    + * Removes the filter to this displayObject
    + *
    + * @method removeFilter
    + * @private
    + */
    +PIXI.DisplayObject.prototype.removeFilter = function(data)
     {
    -	if(!this.filter)return;
    -	this.filter = false;
    +	//if(!this.filter)return;
    +	//this.filter = false;
    +	console.log("YUOIO")
    +	// modify the list..
    +	var startBlock = data.start;
     	
    -	// modify the list..
    -	var startBlock = this.first;
     	
     	var nextObject = startBlock._iNext;
     	var previousObject = startBlock._iPrev;
    @@ -510,9 +659,8 @@ PIXI.DisplayObject.prototype.removeFilter = function()
     	
     	this.first = startBlock._iNext;
     	
    -	
    -	// remove the end filter
    -	var lastBlock = this.last;
    +	// remove the end filter
    +	var lastBlock = data.end;
     	
     	var nextObject = lastBlock._iNext;
     	var previousObject = lastBlock._iPrev;
    @@ -520,11 +668,9 @@ PIXI.DisplayObject.prototype.removeFilter = function()
     	if(nextObject)nextObject._iPrev = previousObject;
     	previousObject._iNext = nextObject;		
     	
    -	// this is always true too!
    -//	if(this.last == lastBlock)
    -	//{
    +	// this is always true too!
     	var tempLast =  lastBlock._iPrev;	
    -	// need to make sure the parents last is updated too
    +	// need to make sure the parents last is updated too
     	var updateLast = this;
     	while(updateLast.last == lastBlock)
     	{
    @@ -533,24 +679,23 @@ PIXI.DisplayObject.prototype.removeFilter = function()
     		if(!updateLast)break;
     	}
     	
    -	var mask = startBlock.mask
    -	mask.renderable = true;
    -	
    -	// if webGL...
    +	// if webGL...
     	if(this.__renderGroup)
     	{
     		this.__renderGroup.removeFilterBlocks(startBlock, lastBlock);
     	}
    -	//}
     }
     
    -/**
    +/*
    + * Updates the object transform for rendering
    + *
    + * @method updateTransform
      * @private
    - */
    + */
     PIXI.DisplayObject.prototype.updateTransform = function()
     {
    -	// TODO OPTIMIZE THIS!! with dirty
    -	if(this.rotation != this.rotationCache)
    +	// TODO OPTIMIZE THIS!! with dirty
    +	if(this.rotation !== this.rotationCache)
     	{
     		this.rotationCache = this.rotation;
     		this._sr =  Math.sin(this.rotation);
    @@ -560,18 +705,18 @@ PIXI.DisplayObject.prototype.updateTransform = function()
     	var localTransform = this.localTransform;
     	var parentTransform = this.parent.worldTransform;
     	var worldTransform = this.worldTransform;
    -	//console.log(localTransform)
    +	//console.log(localTransform)
     	localTransform[0] = this._cr * this.scale.x;
     	localTransform[1] = -this._sr * this.scale.y
     	localTransform[3] = this._sr * this.scale.x;
     	localTransform[4] = this._cr * this.scale.y;
     	
    -	// TODO --> do we even need a local matrix???
    +	// TODO --> do we even need a local matrix???
     	
     	var px = this.pivot.x;
     	var py = this.pivot.y;
        	
    -    // Cache the matrix values (makes for huge speed increases!)
    +    // Cache the matrix values (makes for huge speed increases!)
         var a00 = localTransform[0], a01 = localTransform[1], a02 = this.position.x - localTransform[0] * px - py * localTransform[1],
             a10 = localTransform[3], a11 = localTransform[4], a12 = this.position.y - localTransform[4] * py - px * localTransform[3],
     
    @@ -589,12 +734,15 @@ PIXI.DisplayObject.prototype.updateTransform = function()
         worldTransform[4] = b10 * a01 + b11 * a11;
         worldTransform[5] = b10 * a02 + b11 * a12 + b12;
     
    -	// because we are using affine transformation, we can optimise the matrix concatenation process.. wooo!
    -	// mat3.multiply(this.localTransform, this.parent.worldTransform, this.worldTransform);
    +	// because we are using affine transformation, we can optimise the matrix concatenation process.. wooo!
    +	// mat3.multiply(this.localTransform, this.parent.worldTransform, this.worldTransform);
     	this.worldAlpha = this.alpha * this.parent.worldAlpha;
    +	
    +	this.vcount = PIXI.visibleCount;
     
     }
     
    +PIXI.visibleCount = 0;
         
    @@ -604,13 +752,13 @@ PIXI.DisplayObject.prototype.updateTransform = function()
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_display_DisplayObjectContainer.js.html b/docs/files/src_pixi_display_DisplayObjectContainer.js.html index 0875822..f44463c 100644 --- a/docs/files/src_pixi_display_DisplayObjectContainer.js.html +++ b/docs/files/src_pixi_display_DisplayObjectContainer.js.html @@ -2,12 +2,12 @@ - src/pixi/display/DisplayObjectContainer.js - Pixi.JS - - - - - + src/pixi/display/DisplayObjectContainer.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,76 +166,62 @@
    -

    File: src/pixi/display/DisplayObjectContainer.js

    +

    File: src/pixi/display/DisplayObjectContainer.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
     
    -/**
    - * A DisplayObjectContainer represents a collection of display objects. It is the base class of all display objects that act as a container for other objects.
    +/**
    + * A DisplayObjectContainer represents a collection of display objects.
    + * It is the base class of all display objects that act as a container for other objects.
    + *
      * @class DisplayObjectContainer 
      * @extends DisplayObject
      * @constructor
    - */
    + */
     PIXI.DisplayObjectContainer = function()
     {
     	PIXI.DisplayObject.call( this );
     	
    -	/**
    +	/**
     	 * [read-only] The of children of this container.
    -	 * @property children {Array}
    -	 */	
    +	 *
    +	 * @property children
    +	 * @type Array<DisplayObject>
    +	 * @readOnly
    +	 */	
     	this.children = [];
    -	//s
    -	this.renderable = false;
    -	
     }
     
    -// constructor
    -PIXI.DisplayObjectContainer.constructor = PIXI.DisplayObjectContainer;
    +// constructor
     PIXI.DisplayObjectContainer.prototype = Object.create( PIXI.DisplayObject.prototype );
    +PIXI.DisplayObjectContainer.prototype.constructor = PIXI.DisplayObjectContainer;
     
    -//TODO make visible a getter setter
    -/*
    -Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'visible', {
    -    get: function() {
    -        return this._visible;
    -    },
    -    set: function(value) {
    -        this._visible = value;
    -        
    -    }
    -});*/
    -
    -/**
    +/**
      * Adds a child to the container.
    + *
      * @method addChild
    - * @param  DisplayObject {DisplayObject}
    - */
    + * @param child {DisplayObject} The DisplayObject to add to the container
    + */
     PIXI.DisplayObjectContainer.prototype.addChild = function(child)
     {
    -	
    -	//this.addChildAt(child, this.children.length)
    -	//return;
    -	
     	if(child.parent != undefined)
     	{
     		
    -		//// COULD BE THIS???
    +		//// COULD BE THIS???
     		child.parent.removeChild(child);
    -	//	return;
    +	//	return;
     	}
    -	
    +
     	child.parent = this;
    -	//child.childIndex = this.children.length;
     	
     	this.children.push(child);	
     	
    -	// updae the stage refference..
    +	// update the stage refference..
     	
     	if(this.stage)
     	{
    @@ -225,17 +235,16 @@ PIXI.DisplayObjectContainer.prototype.addChild = function(child)
     		while(tmpChild)
     	}
     	
    -	// LINKED LIST //
    +	// LINKED LIST //
     	
    -	// modify the list..
    +	// modify the list..
     	var childFirst = child.first
     	var childLast = child.last;
    -//	console.log(childFirst)
     	var nextObject;
     	var previousObject;
     	
    -	// this could be wrong if there is a filter??
    -	if(this.filter)
    +	// this could be wrong if there is a filter??
    +	if(this._filters || this._mask)
     	{
     		previousObject =  this.last._iPrev;
     	}
    @@ -243,14 +252,11 @@ PIXI.DisplayObjectContainer.prototype.addChild = function(child)
     	{
     		previousObject = this.last;
     	}
    -//	if(this.last._iNext)
    -	
    -	//console.log( this.last._iNext);
    +
     	nextObject = previousObject._iNext;
     	
    -	// always true in this case
    -	//this.last = child.last;
    -	// need to make sure the parents last is updated too
    +	// always true in this case
    +	// need to make sure the parents last is updated too
     	var updateLast = this;
     	var prevLast = previousObject;
     	
    @@ -271,25 +277,25 @@ PIXI.DisplayObjectContainer.prototype.addChild = function(child)
     	
     	childFirst._iPrev = previousObject;
     	previousObject._iNext = childFirst;		
    -	
    -//	console.log(childFirst);
    -	// need to remove any render groups..
    +
    +	// need to remove any render groups..
     	if(this.__renderGroup)
     	{
    -		// being used by a renderTexture.. if it exists then it must be from a render texture;
    +		// being used by a renderTexture.. if it exists then it must be from a render texture;
     		if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child);
    -		// add them to the new render group..
    +		// add them to the new render group..
     		this.__renderGroup.addDisplayObjectAndChildren(child);
     	}
     	
     }
     
    -/**
    +/**
      * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown
    + *
      * @method addChildAt
    - * @param DisplayObject {DisplayObject}
    - * @param index {Number}
    - */
    + * @param child {DisplayObject} The child to add
    + * @param index {Number} The index to place the child in
    + */
     PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
     {
     	if(index >= 0 && index <= this.children.length)
    @@ -312,8 +318,8 @@ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
     			while(tmpChild)
     		}
     		
    -		// modify the list..
    -		var childFirst = child.first
    +		// modify the list..
    +		var childFirst = child.first;
     		var childLast = child.last;
     		var nextObject;
     		var previousObject;
    @@ -321,7 +327,7 @@ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
     		if(index == this.children.length)
     		{
     			previousObject =  this.last;
    -			var updateLast = this;//.parent;
    +			var updateLast = this;
     			var prevLast = this.last;
     			while(updateLast)
     			{
    @@ -343,7 +349,7 @@ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
     		
     		nextObject = previousObject._iNext;
     		
    -		// always true in this case
    +		// always true in this case
     		if(nextObject)
     		{
     			nextObject._iPrev = childLast;
    @@ -352,19 +358,17 @@ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
     		
     		childFirst._iPrev = previousObject;
     		previousObject._iNext = childFirst;		
    -		
    -		
    +
     		this.children.splice(index, 0, child);
    -		// need to remove any render groups..
    +		// need to remove any render groups..
     		if(this.__renderGroup)
     		{
    -			// being used by a renderTexture.. if it exists then it must be from a render texture;
    +			// being used by a renderTexture.. if it exists then it must be from a render texture;
     			if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child);
    -			// add them to the new render group..
    +			// add them to the new render group..
     			this.__renderGroup.addDisplayObjectAndChildren(child);
     		}
     		
    -		console.log(this.children)
     	}
     	else
     	{
    @@ -372,35 +376,37 @@ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
     	}
     }
     
    -/**
    - * Swaps the depth of 2 displayObjects
    +/**
    + * [NYI] Swaps the depth of 2 displayObjects
    + *
      * @method swapChildren
    - * @param  DisplayObject {DisplayObject}
    - * @param  DisplayObject2 {DisplayObject}
    - */
    + * @param child {DisplayObject}
    + * @param child2 {DisplayObject}
    + * @private
    + */
     PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2)
     {
    -	/*
    +	/*
     	 * this funtion needs to be recoded.. 
     	 * can be done a lot faster..
    -	 */
    +	 */
     	return;
     	
    -	// need to fix this function :/
    -	/*
    -	// TODO I already know this??
    +	// need to fix this function :/
    +	/*
    +	// TODO I already know this??
     	var index = this.children.indexOf( child );
     	var index2 = this.children.indexOf( child2 );
     	
     	if ( index !== -1 && index2 !== -1 ) 
     	{
    -		// cool
    +		// cool
     		
    -		/*
    +		/*
     		if(this.stage)
     		{
    -			// this is to satisfy the webGL batching..
    -			// TODO sure there is a nicer way to achieve this!
    +			// this is to satisfy the webGL batching..
    +			// TODO sure there is a nicer way to achieve this!
     			this.stage.__removeChild(child);
     			this.stage.__removeChild(child2);
     			
    @@ -408,7 +414,7 @@ PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2)
     			this.stage.__addChild(child2);
     		}
     		
    -		// swap the positions..
    +		// swap the positions..
     		this.children[index] = child2;
     		this.children[index2] = child;
     		
    @@ -416,14 +422,15 @@ PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2)
     	else
     	{
     		throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this);
    -	}*/
    +	}*/
     }
     
    -/**
    +/**
      * Returns the Child at the specified index
    + *
      * @method getChildAt
    - * @param  index {Number}
    - */
    + * @param index {Number} The index to get the child from
    + */
     PIXI.DisplayObjectContainer.prototype.getChildAt = function(index)
     {
     	if(index >= 0 && index < this.children.length)
    @@ -436,20 +443,20 @@ PIXI.DisplayObjectContainer.prototype.getChildAt = function(index)
     	}
     }
     
    -/**
    +/**
      * Removes a child from the container.
    + *
      * @method removeChild
    - * @param  DisplayObject {DisplayObject}
    - */
    + * @param child {DisplayObject} The DisplayObject to remove
    + */
     PIXI.DisplayObjectContainer.prototype.removeChild = function(child)
     {
     	var index = this.children.indexOf( child );
     	if ( index !== -1 ) 
     	{
    -		//console.log(">>")
    -		// unlink //
    -		// modify the list..
    -		var childFirst = child.first
    +		// unlink //
    +		// modify the list..
    +		var childFirst = child.first;
     		var childLast = child.last;
     		
     		var nextObject = childLast._iNext;
    @@ -461,7 +468,7 @@ PIXI.DisplayObjectContainer.prototype.removeChild = function(child)
     		if(this.last == childLast)
     		{
     			var tempLast =  childFirst._iPrev;	
    -			// need to make sure the parents last is updated too
    +			// need to make sure the parents last is updated too
     			var updateLast = this;
     			while(updateLast.last == childLast.last)
     			{
    @@ -474,7 +481,7 @@ PIXI.DisplayObjectContainer.prototype.removeChild = function(child)
     		childLast._iNext = null;
     		childFirst._iPrev = null;
     		 
    -		// update the stage reference..
    +		// update the stage reference..
     		if(this.stage)
     		{
     			var tmpChild = child;
    @@ -487,7 +494,7 @@ PIXI.DisplayObjectContainer.prototype.removeChild = function(child)
     			while(tmpChild)
     		}
     	
    -		// webGL trim
    +		// webGL trim
     		if(child.__renderGroup)
     		{
     			child.__renderGroup.removeDisplayObjectAndChildren(child);
    @@ -502,10 +509,12 @@ PIXI.DisplayObjectContainer.prototype.removeChild = function(child)
     	}
     }
     
    -
    -/**
    +/*
    + * Updates the container's children's transform for rendering
    + *
    + * @method updateTransform
      * @private
    - */
    + */
     PIXI.DisplayObjectContainer.prototype.updateTransform = function()
     {
     	if(!this.visible)return;
    @@ -517,7 +526,6 @@ PIXI.DisplayObjectContainer.prototype.updateTransform = function()
     		this.children[i].updateTransform();	
     	}
     }
    -
         
    @@ -527,13 +535,13 @@ PIXI.DisplayObjectContainer.prototype.updateTransform = function()
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_display_MovieClip.js.html b/docs/files/src_pixi_display_MovieClip.js.html index 87e0a59..600d7f1 100644 --- a/docs/files/src_pixi_display_MovieClip.js.html +++ b/docs/files/src_pixi_display_MovieClip.js.html @@ -2,12 +2,12 @@ - src/pixi/display/MovieClip.js - Pixi.JS - - - - - + src/pixi/display/MovieClip.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,95 +166,127 @@
    -

    File: src/pixi/display/MovieClip.js

    +

    File: src/pixi/display/MovieClip.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -/**
    +/**
      * A MovieClip is a simple way to display an animation depicted by a list of textures.
    + *
      * @class MovieClip
      * @extends Sprite
      * @constructor
    - * @param textures {Array} an array of {Texture} objects that make up the animation
    - */
    + * @param textures {Array<Texture>} an array of {Texture} objects that make up the animation
    + */
     PIXI.MovieClip = function(textures)
     {
    -	PIXI.Sprite.call( this, textures[0]);
    -	
    -	/**
    +	PIXI.Sprite.call(this, textures[0]);
    +
    +	/**
     	 * The array of textures that make up the animation
    +	 *
     	 * @property textures
     	 * @type Array
    -	 */
    +	 */
     	this.textures = textures;
    -	
    -	/**
    -	 * [read only] The index MovieClips current frame (this may not have to be a whole number)
    -	 * @property currentFrame
    -	 * @type Number
    -	 */
    -	this.currentFrame = 0; 
    -	
    -	/**
    +
    +	/**
     	 * The speed that the MovieClip will play at. Higher is faster, lower is slower
    +	 *
     	 * @property animationSpeed
     	 * @type Number
    -	 */
    +	 * @default 1
    +	 */
     	this.animationSpeed = 1;
     
    -	/**
    +	/**
     	 * Whether or not the movie clip repeats after playing.
    +	 *
     	 * @property loop
     	 * @type Boolean
    -	 */
    +	 * @default true
    +	 */
     	this.loop = true;
     
    -	/**
    +	/**
     	 * Function to call when a MovieClip finishes playing
    +	 *
     	 * @property onComplete
     	 * @type Function
    -	 */
    +	 */
     	this.onComplete = null;
    -	
    -	/**
    -	 * [read only] indicates if the MovieClip is currently playing
    +
    +	/**
    +	 * [read-only] The index MovieClips current frame (this may not have to be a whole number)
    +	 *
    +	 * @property currentFrame
    +	 * @type Number
    +	 * @default 0
    +	 * @readOnly
    +	 */
    +	this.currentFrame = 0;
    +
    +	/**
    +	 * [read-only] Indicates if the MovieClip is currently playing
    +	 *
     	 * @property playing
     	 * @type Boolean
    -	 */
    -	this.playing;
    +	 * @readOnly
    +	 */
    +	this.playing = false;
     }
     
    -// constructor
    -PIXI.MovieClip.constructor = PIXI.MovieClip;
    +// constructor
     PIXI.MovieClip.prototype = Object.create( PIXI.Sprite.prototype );
    +PIXI.MovieClip.prototype.constructor = PIXI.MovieClip;
     
    -/**
    +/**
    +* [read-only] totalFrames is the total number of frames in the MovieClip. This is the same as number of textures
    +* assigned to the MovieClip.
    +*
    +* @property totalFrames
    +* @type Number
    +* @default 0
    +* @readOnly
    +*/
    +Object.defineProperty( PIXI.MovieClip.prototype, 'totalFrames', {
    +	get: function() {
    +
    +		return this.textures.length;
    +	}
    +});
    +
    +
    +/**
      * Stops the MovieClip
    + *
      * @method stop
    - */
    + */
     PIXI.MovieClip.prototype.stop = function()
     {
     	this.playing = false;
     }
     
    -/**
    +/**
      * Plays the MovieClip
    + *
      * @method play
    - */
    + */
     PIXI.MovieClip.prototype.play = function()
     {
     	this.playing = true;
     }
     
    -/**
    +/**
      * Stops the MovieClip and goes to a specific frame
    + *
      * @method gotoAndStop
      * @param frameNumber {Number} frame index to stop at
    - */
    + */
     PIXI.MovieClip.prototype.gotoAndStop = function(frameNumber)
     {
     	this.playing = false;
    @@ -239,25 +295,34 @@ PIXI.MovieClip.prototype.gotoAndStop = function(frameNumber)
     	this.setTexture(this.textures[round % this.textures.length]);
     }
     
    -/**
    +/**
      * Goes to a specific frame and begins playing the MovieClip
    + *
      * @method gotoAndPlay
      * @param frameNumber {Number} frame index to start at
    - */
    + */
     PIXI.MovieClip.prototype.gotoAndPlay = function(frameNumber)
     {
     	this.currentFrame = frameNumber;
     	this.playing = true;
     }
     
    +/*
    + * Updates the object transform for rendering
    + *
    + * @method updateTransform
    + * @private
    + */
     PIXI.MovieClip.prototype.updateTransform = function()
     {
     	PIXI.Sprite.prototype.updateTransform.call(this);
    -	
    +
     	if(!this.playing)return;
    -	
    +
     	this.currentFrame += this.animationSpeed;
    +
     	var round = (this.currentFrame + 0.5) | 0;
    +
     	if(this.loop || round < this.textures.length)
     	{
     		this.setTexture(this.textures[round % this.textures.length]);
    @@ -280,13 +345,13 @@ PIXI.MovieClip.prototype.updateTransform = function()
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_display_Sprite.js.html b/docs/files/src_pixi_display_Sprite.js.html index 48e9042..84f1dce 100644 --- a/docs/files/src_pixi_display_Sprite.js.html +++ b/docs/files/src_pixi_display_Sprite.js.html @@ -2,12 +2,12 @@ - src/pixi/display/Sprite.js - Pixi.JS - - - - - + src/pixi/display/Sprite.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,69 +166,78 @@
    -

    File: src/pixi/display/Sprite.js

    +

    File: src/pixi/display/Sprite.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
     PIXI.blendModes = {};
     PIXI.blendModes.NORMAL = 0;
     PIXI.blendModes.SCREEN = 1;
     
     
    -/**
    -@class Sprite
    -@extends DisplayObjectContainer
    -@constructor
    -@param texture {Texture}
    -@type String
    -*/
    +/**
    + * The SPrite object is the base for all textured objects that are rendered to the screen
    + *
    + * @class Sprite
    + * @extends DisplayObjectContainer
    + * @constructor
    + * @param texture {Texture} The texture for this sprite
    + * @type String
    + */
     PIXI.Sprite = function(texture)
     {
     	PIXI.DisplayObjectContainer.call( this );
    -	
    -	 /**
    +
    +	/**
     	 * The anchor sets the origin point of the texture.
     	 * The default is 0,0 this means the textures origin is the top left 
     	 * Setting than anchor to 0.5,0.5 means the textures origin is centered
     	 * Setting the anchor to 1,1 would mean the textures origin points will be the bottom right
    +	 *
          * @property anchor
          * @type Point
    -     */
    +     */
     	this.anchor = new PIXI.Point();
    -	
    -	/**
    +
    +	/**
     	 * The texture that the sprite is using
    +	 *
     	 * @property texture
     	 * @type Texture
    -	 */
    +	 */
     	this.texture = texture;
    -	
    -	/**
    +
    +	/**
     	 * The blend mode of sprite.
     	 * currently supports PIXI.blendModes.NORMAL and PIXI.blendModes.SCREEN
    +	 *
     	 * @property blendMode
    -	 * @type uint
    -	 */
    +	 * @type Number
    +	 */
     	this.blendMode = PIXI.blendModes.NORMAL;
    -	
    -	/**
    +
    +	/**
     	 * The width of the sprite (this is initially set by the texture)
    -	 * @property width
    -	 * @type #Number
    -	 */
    +	 *
    +	 * @property _width
    +	 * @type Number
    +	 * @private
    +	 */
     	this._width = 0;
    -	
    -	/**
    +
    +	/**
     	 * The height of the sprite (this is initially set by the texture)
    -	 * @property height
    -	 * @type #Number
    -	 */
    +	 *
    +	 * @property _height
    +	 * @type Number
    +	 * @private
    +	 */
     	this._height = 0;
    -	
    +
     	if(texture.baseTexture.hasLoaded)
     	{
     		this.updateFrame = true;
    @@ -214,81 +247,103 @@ PIXI.Sprite = function(texture)
     		this.onTextureUpdateBind = this.onTextureUpdate.bind(this);
     		this.texture.addEventListener( 'update', this.onTextureUpdateBind );
     	}
    -	
    +
     	this.renderable = true;
    -	
    -	// thi next bit is here for the docs...
    -	
    -	
     }
     
    -// constructor
    -PIXI.Sprite.constructor = PIXI.Sprite;
    +// constructor
     PIXI.Sprite.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
    +PIXI.Sprite.prototype.constructor = PIXI.Sprite;
     
    -// OOH! shiney new getters and setters for width and height
    -// The width and height now modify the scale (this is what flash does, nice and tidy!)
    +/**
    + * The width of the sprite, setting this will actually modify the scale to acheive the value set
    + *
    + * @property width
    + * @type Number
    + */
     Object.defineProperty(PIXI.Sprite.prototype, 'width', {
         get: function() {
             return this.scale.x * this.texture.frame.width;
         },
         set: function(value) {
    -    	this.scale.x = value / this.texture.frame.width
    +    	this.scale.x = value / this.texture.frame.width
             this._width = value;
         }
     });
     
    +/**
    + * The height of the sprite, setting this will actually modify the scale to acheive the value set
    + *
    + * @property height
    + * @type Number
    + */
     Object.defineProperty(PIXI.Sprite.prototype, 'height', {
         get: function() {
             return  this.scale.y * this.texture.frame.height;
         },
         set: function(value) {
    -    	this.scale.y = value / this.texture.frame.height
    +    	this.scale.y = value / this.texture.frame.height
             this._height = value;
         }
     });
    - 
    -/**
    -@method setTexture
    -@param texture {Texture} The PIXI texture that is displayed by the sprite
    -*/
    +
    +/**
    + * Sets the texture of the sprite
    + *
    + * @method setTexture
    + * @param texture {Texture} The PIXI texture that is displayed by the sprite
    + */
     PIXI.Sprite.prototype.setTexture = function(texture)
     {
    -	// stop current texture;
    +	// stop current texture;
     	if(this.texture.baseTexture != texture.baseTexture)
     	{
     		this.textureChange = true;	
    +		this.texture = texture;
    +		
    +		if(this.__renderGroup)
    +		{
    +			this.__renderGroup.updateTexture(this);
    +		}
    +	}
    +	else
    +	{
    +		this.texture = texture;
     	}
     	
    -	this.texture = texture;
     	this.updateFrame = true;
     }
     
    -/**
    +/**
    + * When the texture is updated, this event will fire to update the scale and frame
    + *
    + * @method onTextureUpdate
    + * @param event
      * @private
    - */
    + */
     PIXI.Sprite.prototype.onTextureUpdate = function(event)
     {
    -	//this.texture.removeEventListener( 'update', this.onTextureUpdateBind );
    +	//this.texture.removeEventListener( 'update', this.onTextureUpdateBind );
     	
    -	// so if _width is 0 then width was not set..
    -	if(this._width)this.scale.x = this._width / this.texture.frame.width;
    -	if(this._height)this.scale.y = this._height / this.texture.frame.height;
    +	// so if _width is 0 then width was not set..
    +	if(this._width)this.scale.x = this._width / this.texture.frame.width;
    +	if(this._height)this.scale.y = this._height / this.texture.frame.height;
     	
     	this.updateFrame = true;
     }
     
    -// some helper functions..
    +// some helper functions..
     
    -/**
    +/**
      * 
      * Helper function that creates a sprite that will contain a texture from the TextureCache based on the frameId
      * The frame ids are created when a Texture packer file has been loaded
    + *
      * @method fromFrame
      * @static
      * @param frameId {String} The frame Id of the texture in the cache
      * @return {Sprite} A new Sprite using a texture from the texture cache matching the frameId
    - */
    + */
     PIXI.Sprite.fromFrame = function(frameId)
     {
     	var texture = PIXI.TextureCache[frameId];
    @@ -296,22 +351,22 @@ PIXI.Sprite.fromFrame = function(frameId)
     	return new PIXI.Sprite(texture);
     }
     
    -/**
    +/**
      * 
      * Helper function that creates a sprite that will contain a texture based on an image url
      * If the image is not in the texture cache it will be loaded
    + *
      * @method fromImage
      * @static
    - * @param The image url of the texture
    + * @param imageId {String} The image url of the texture
      * @return {Sprite} A new Sprite using a texture from the texture cache matching the image id
    - */
    + */
     PIXI.Sprite.fromImage = function(imageId)
     {
     	var texture = PIXI.Texture.fromImage(imageId);
     	return new PIXI.Sprite(texture);
     }
     
    -
         
    @@ -321,13 +376,13 @@ PIXI.Sprite.fromImage = function(imageId)
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_display_Stage.js.html b/docs/files/src_pixi_display_Stage.js.html index 6c0dc32..7c8bc2b 100644 --- a/docs/files/src_pixi_display_Stage.js.html +++ b/docs/files/src_pixi_display_Stage.js.html @@ -2,12 +2,12 @@ - src/pixi/display/Stage.js - Pixi.JS - - - - - + src/pixi/display/Stage.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,58 +166,101 @@
    -

    File: src/pixi/display/Stage.js

    +

    File: src/pixi/display/Stage.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -/**
    -A Stage represents the root of the display tree. Everything connected to the stage is rendered
    -@class Stage
    -@extends DisplayObjectContainer
    -@constructor
    -@param backgroundColor {Number} the background color of the stage
    -@param interactive {Boolean} enable / disable interaction (default is false)
    -*/
    -PIXI.Stage = function(backgroundColor, interactive)
    +/**
    + * A Stage represents the root of the display tree. Everything connected to the stage is rendered
    + *
    + * @class Stage
    + * @extends DisplayObjectContainer
    + * @constructor
    + * @param backgroundColor {Number} the background color of the stage, easiest way to pass this in is in hex format
    + *		like: 0xFFFFFF for white
    + */
    +PIXI.Stage = function(backgroundColor)
     {
    -	
     	PIXI.DisplayObjectContainer.call( this );
    -	
    -	this.worldTransform = PIXI.mat3.create()
    +
    +	/**
    +	 * [read-only] Current transform of the object based on world (parent) factors
    +	 *
    +	 * @property worldTransform
    +	 * @type Mat3
    +	 * @readOnly
    +	 * @private
    +	 */
    +	this.worldTransform = PIXI.mat3.create();
    +
    +	/**
    +	 * Whether or not the stage is interactive
    +	 *
    +	 * @property interactive
    +	 * @type Boolean
    +	 */
    +	this.interactive = true;
    +
    +	/**
    +	 * The interaction manage for this stage, manages all interactive activity on the stage
    +	 *
    +	 * @property interactive
    +	 * @type InteractionManager
    +	 */
    +	this.interactionManager = new PIXI.InteractionManager(this);
    +
    +	/**
    +	 * Whether the stage is dirty and needs to have interactions updated
    +	 *
    +	 * @property dirty
    +	 * @type Boolean
    +	 * @private
    +	 */
    +	this.dirty = true;
    +
     	this.__childrenAdded = [];
     	this.__childrenRemoved = [];
    -	
    -	//this.childIndex = 0;
    +
    +	//the stage is it's own stage
     	this.stage = this;
    -	this.interactive = interactive;
    -	
    +
    +	//optimize hit detection a bit
     	this.stage.hitArea = new PIXI.Rectangle(0,0,100000, 100000);
    -	
    -	// interaction!
    -	// this.interactive = !!interactive;
    -	this.interactionManager = new PIXI.InteractionManager(this);
    -	
    +
     	this.setBackgroundColor(backgroundColor);
     	this.worldVisible = true;
    -	this.stage.dirty = true;
     }
     
    -// constructor
    -PIXI.Stage.constructor = PIXI.Stage;
    -
    +// constructor
     PIXI.Stage.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
    +PIXI.Stage.prototype.constructor = PIXI.Stage;
     
    -/**
    -@method updateTransform
    -@internal
    -*/
    +/**
    + * Sets another DOM element which can receive mouse/touch interactions instead of the default Canvas element.
    + * This is useful for when you have other DOM elements ontop of the Canvas element.
    + *
    + * @method setInteractionDelegate
    + * @param domElement {DOMElement} This new domElement which will receive mouse/touch events
    + */
    +PIXI.Stage.prototype.setInteractionDelegate = function(domElement)
    +{
    +	this.interactionManager.setTargetDomElement( domElement );
    +}
    +
    +/*
    + * Updates the object transform for rendering
    + *
    + * @method updateTransform
    + * @private
    + */
     PIXI.Stage.prototype.updateTransform = function()
     {
     	this.worldAlpha = 1;		
    +	this.vcount = PIXI.visibleCount;
     	
     	for(var i=0,j=this.children.length; i<j; i++)
     	{
    @@ -203,17 +270,21 @@ PIXI.Stage.prototype.updateTransform = function()
     	if(this.dirty)
     	{
     		this.dirty = false;
    -		// update interactive!
    +		// update interactive!
     		this.interactionManager.dirty = true;
     	}
    -
    +	
    +	
     	if(this.interactive)this.interactionManager.update();
     }
     
    -/**
    +/**
    + * Sets the background color for the stage
    + *
      * @method setBackgroundColor
    - * @param backgroundColor {Number}
    - */
    + * @param backgroundColor {Number} the color of the background, easiest way to pass this in is in hex format
    + *		like: 0xFFFFFF for white
    + */
     PIXI.Stage.prototype.setBackgroundColor = function(backgroundColor)
     {
     	this.backgroundColor = backgroundColor || 0x000000;
    @@ -223,47 +294,16 @@ PIXI.Stage.prototype.setBackgroundColor = function(backgroundColor)
     	this.backgroundColorString = "#" + hex;
     }
     
    -/**
    +/**
      * This will return the point containing global coords of the mouse.
    + *
      * @method getMousePosition
      * @return {Point} The point containing the coords of the global InteractionData position.
    - */
    + */
     PIXI.Stage.prototype.getMousePosition = function()
     {
     	return this.interactionManager.mouse.global;
     }
    -/*
    -PIXI.Stage.prototype.__addChild = function(child)
    -{
    -	if(child.interactive)this.dirty = true;
    -	
    -	child.stage = this;
    -	
    -	if(child.children)
    -	{
    -		for (var i=0; i < child.children.length; i++) 
    -		{
    -		  	this.__addChild(child.children[i]);
    -		};
    -	}
    -	
    -}
    -
    -
    -PIXI.Stage.prototype.__removeChild = function(child)
    -{
    -	if(child.interactive)this.dirty = true;
    -	
    -	child.stage = undefined;
    -	
    -	if(child.children)
    -	{
    -		for(var i=0,j=child.children.length; i<j; i++)
    -		{
    -		  	this.__removeChild(child.children[i]);
    -		}
    -	}
    -}*/
     
         
    @@ -274,13 +314,13 @@ PIXI.Stage.prototype.__removeChild = function(child)
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_extras_CustomRenderable.js.html b/docs/files/src_pixi_extras_CustomRenderable.js.html index 83ef08c..8592913 100644 --- a/docs/files/src_pixi_extras_CustomRenderable.js.html +++ b/docs/files/src_pixi_extras_CustomRenderable.js.html @@ -2,12 +2,12 @@ - src/pixi/extras/CustomRenderable.js - Pixi.JS - - - - - + src/pixi/extras/CustomRenderable.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,47 +166,65 @@
    -

    File: src/pixi/extras/CustomRenderable.js

    +

    File: src/pixi/extras/CustomRenderable.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
     
    -/**
    - * Need to finalize this a bit more but works! Its in but will be working on this feature properly next..:)
    - * @class CustomRenderable 
    +/**
    + * This object is one that will allow you to specify custom rendering functions based on render type
    + *
    + * @class CustomRenderable
      * @extends DisplayObject
      * @constructor
    - */
    + */
     PIXI.CustomRenderable = function()
     {
     	PIXI.DisplayObject.call( this );
     	
    +	this.renderable = true;
     }
     
    -// constructor
    -PIXI.CustomRenderable.constructor = PIXI.CustomRenderable;
    +// constructor
     PIXI.CustomRenderable.prototype = Object.create( PIXI.DisplayObject.prototype );
    +PIXI.CustomRenderable.prototype.constructor = PIXI.CustomRenderable;
     
    +/**
    + * If this object is being rendered by a CanvasRenderer it will call this callback
    + *
    + * @method renderCanvas
    + * @param renderer {CanvasRenderer} The renderer instance
    + */
     PIXI.CustomRenderable.prototype.renderCanvas = function(renderer)
     {
    -	// override!
    +	// override!
     }
     
    -
    +/**
    + * If this object is being rendered by a WebGLRenderer it will call this callback to initialize
    + *
    + * @method initWebGL
    + * @param renderer {WebGLRenderer} The renderer instance
    + */
     PIXI.CustomRenderable.prototype.initWebGL = function(renderer)
     {
    -	// override!
    +	// override!
     }
     
    -
    +/**
    + * If this object is being rendered by a WebGLRenderer it will call this callback
    + *
    + * @method renderWebGL
    + * @param renderer {WebGLRenderer} The renderer instance
    + */
     PIXI.CustomRenderable.prototype.renderWebGL = function(renderGroup, projectionMatrix)
     {
    -	// not sure if both needed? but ya have for now!
    -	// override!
    +	// not sure if both needed? but ya have for now!
    +	// override!
     }
     
     
    @@ -195,13 +237,13 @@ PIXI.CustomRenderable.prototype.renderWebGL = function(renderGroup, projectionMa
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_extras_Rope.js.html b/docs/files/src_pixi_extras_Rope.js.html index 37a22e4..34c0cf3 100644 --- a/docs/files/src_pixi_extras_Rope.js.html +++ b/docs/files/src_pixi_extras_Rope.js.html @@ -2,12 +2,12 @@ - src/pixi/extras/Rope.js - Pixi.JS - - - - - + src/pixi/extras/Rope.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,20 +166,20 @@
    -

    File: src/pixi/extras/Rope.js

    +

    File: src/pixi/extras/Rope.js

    -/**
    - * @author Mat Groves http://matgroves.com/
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/
    + */
     
     
     PIXI.Rope = function(texture, points)
     {
     	PIXI.Strip.call( this, texture );
     	this.points = points;
    -	
    +
     	try
     	{
     		this.verticies = new Float32Array( points.length * 4);
    @@ -166,117 +190,117 @@ PIXI.Rope = function(texture, points)
     	catch(error)
     	{
     		this.verticies = verticies
    -		
    +
     		this.uvs = uvs
     		this.colors = colors
     		this.indices = indices
     	}
    -	
    +
     	this.refresh();
     }
     
     
    -// constructor
    -PIXI.Rope.constructor = PIXI.Rope;
    +// constructor
     PIXI.Rope.prototype = Object.create( PIXI.Strip.prototype );
    +PIXI.Rope.prototype.constructor = PIXI.Rope;
     
     PIXI.Rope.prototype.refresh = function()
     {
     	var points = this.points;
     	if(points.length < 1)return;
    -	
    +
     	var uvs = this.uvs
     	var indices = this.indices;
     	var colors = this.colors;
    -	
    +
     	var lastPoint = points[0];
     	var nextPoint;
     	var perp = {x:0, y:0};
     	var point = points[0];
    -	
    +
     	this.count-=0.2;
    -	
    -	
    +
    +
     	uvs[0] = 0
     	uvs[1] = 1
     	uvs[2] = 0
     	uvs[3] = 1
    -	
    +
     	colors[0] = 1;
     	colors[1] = 1;
    -	
    +
     	indices[0] = 0;
     	indices[1] = 1;
    -	
    +
     	var total = points.length;
    -		
    -	for (var i =  1; i < total; i++) 
    +
    +	for (var i =  1; i < total; i++)
     	{
    -		
    +
     		var point = points[i];
     		var index = i * 4;
    -		// time to do some smart drawing!
    -		var amount = i/(total-1)
    -		
    +		// time to do some smart drawing!
    +		var amount = i/(total-1)
    +
     		if(i%2)
     		{
     			uvs[index] = amount;
     			uvs[index+1] = 0;
    -			
    +
     			uvs[index+2] = amount
     			uvs[index+3] = 1
    -		
    +
     		}
     		else
     		{
     			uvs[index] = amount
     			uvs[index+1] = 0
    -			
    +
     			uvs[index+2] = amount
     			uvs[index+3] = 1
     		}
    -		
    +
     		index = i * 2;
     		colors[index] = 1;
     		colors[index+1] = 1;
    -		
    +
     		index = i * 2;
     		indices[index] = index;
     		indices[index + 1] = index + 1;
    -		
    +
     		lastPoint = point;
     	}
     }
     
     PIXI.Rope.prototype.updateTransform = function()
     {
    -	
    +
     	var points = this.points;
     	if(points.length < 1)return;
    -	
    -	var verticies = this.verticies 
    -	
    +
    +	var verticies = this.verticies
    +
     	var lastPoint = points[0];
     	var nextPoint;
     	var perp = {x:0, y:0};
     	var point = points[0];
    -	
    +
     	this.count-=0.2;
    -	
    -	verticies[0] = point.x + perp.x 
    -	verticies[1] = point.y + perp.y //+ 200
    -	verticies[2] = point.x - perp.x 
    -	verticies[3] = point.y - perp.y//+200
    -	// time to do some smart drawing!
    -	
    +
    +	verticies[0] = point.x + perp.x
    +	verticies[1] = point.y + perp.y //+ 200
    +	verticies[2] = point.x - perp.x
    +	verticies[3] = point.y - perp.y//+200
    +	// time to do some smart drawing!
    +
     	var total = points.length;
    -		
    -	for (var i =  1; i < total; i++) 
    +
    +	for (var i =  1; i < total; i++)
     	{
    -		
    +
     		var point = points[i];
     		var index = i * 4;
    -		
    +
     		if(i < points.length-1)
     		{
     			nextPoint = points[i+1];
    @@ -285,35 +309,35 @@ PIXI.Rope.prototype.updateTransform = function()
     		{
     			nextPoint = point
     		}
    -		
    +
     		perp.y = -(nextPoint.x - lastPoint.x);
     		perp.x = nextPoint.y - lastPoint.y;
    -		
    -		var ratio = (1 - (i / (total-1))) * 10;
    +
    +		var ratio = (1 - (i / (total-1))) * 10;
     				if(ratio > 1)ratio = 1;
    -				
    +
     		var perpLength = Math.sqrt(perp.x * perp.x + perp.y * perp.y);
    -		var num = this.texture.height/2//(20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio;
    -		perp.x /= perpLength;
    -		perp.y /= perpLength;
    -	
    +		var num = this.texture.height/2//(20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio;
    +		perp.x /= perpLength;
    +		perp.y /= perpLength;
    +
     		perp.x *= num;
     		perp.y *= num;
    -		
    -		verticies[index] = point.x + perp.x 
    +
    +		verticies[index] = point.x + perp.x
     		verticies[index+1] = point.y + perp.y
    -		verticies[index+2] = point.x - perp.x 
    +		verticies[index+2] = point.x - perp.x
     		verticies[index+3] = point.y - perp.y
     
     		lastPoint = point;
     	}
    -	
    +
     	PIXI.DisplayObjectContainer.prototype.updateTransform.call( this );
     }
     
     PIXI.Rope.prototype.setTexture = function(texture)
     {
    -	// stop current texture 
    +	// stop current texture
     	this.texture = texture;
     	this.updateFrame = true;
     }
    @@ -331,13 +355,13 @@ PIXI.Rope.prototype.setTexture = function(texture)
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_extras_Spine.js.html b/docs/files/src_pixi_extras_Spine.js.html index ba18005..b1df202 100644 --- a/docs/files/src_pixi_extras_Spine.js.html +++ b/docs/files/src_pixi_extras_Spine.js.html @@ -2,12 +2,12 @@ - src/pixi/extras/Spine.js - Pixi.JS - - - - - + src/pixi/extras/Spine.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,122 +166,141 @@
    -

    File: src/pixi/extras/Spine.js

    +

    File: src/pixi/extras/Spine.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi
    - * 
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi
    + *
      * Awesome JS run time provided by EsotericSoftware
    - * https://github.com/EsotericSoftware/spine-runtimes
    - * 
    - */
    + * https://github.com/EsotericSoftware/spine-runtimes
    + *
    + */
     
    -/**
    +/**
      * A class that enables the you to import and run your spine animations in pixi.
      * Spine animation data needs to be loaded using the PIXI.AssetLoader or PIXI.SpineLoader before it can be used by this class
    - * Also due to a clash of names  You will need to change the extension of the spine file from *.json to *.anim for it to load
    - * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source
    + * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source
    + *
      * @class Spine
    - * @constructor
      * @extends DisplayObjectContainer
    - * @param {String} url the url of the spine anim file to be used
    - */
    -PIXI.Spine = function(url)
    -{
    + * @constructor
    + * @param url {String} The url of the spine anim file to be used
    + */
    +PIXI.Spine = function (url) {
     	PIXI.DisplayObjectContainer.call(this);
    -	
    +
     	this.spineData = PIXI.AnimCache[url];
    -	
    -	if(!this.spineData)
    -	{
    +
    +	if (!this.spineData) {
     		throw new Error("Spine data must be preloaded using PIXI.SpineLoader or PIXI.AssetLoader: " + url);
    -		return;
     	}
    -	
    -	this.count = 0;
    -	
    -	this.sprites = [];
    -	
    +
     	this.skeleton = new spine.Skeleton(this.spineData);
     	this.skeleton.updateWorldTransform();
     
    -	this.stateData = new spine.AnimationStateData(this.spineData);	
    +	this.stateData = new spine.AnimationStateData(this.spineData);
     	this.state = new spine.AnimationState(this.stateData);
    -	
    -	// add the sprites..
    -	for (var i = 0; i < this.skeleton.drawOrder.length; i++) {
    -		
    -		var attachmentName = this.skeleton.drawOrder[i].data.attachmentName;
    -		
    -		// kind of an assumtion here. that its a png
    -		if(!PIXI.TextureCache[attachmentName])
    -		{
    -			attachmentName += ".png";
    -		}
    -		
    -		
    -		var sprite = new PIXI.Sprite(PIXI.Texture.fromFrame(attachmentName));
    -		sprite.anchor.x = sprite.anchor.y = 0.5;
    -		this.addChild(sprite);
    -		this.sprites.push(sprite);
    -	};
    -}
     
    -PIXI.Spine.constructor = PIXI.Spine;
    -PIXI.Spine.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
    -PIXI.Spine.prototype.updateTransform = function()
    -{
    -	// TODO should make this time based really..
    -	this.state.update(1/60);
    +	this.slotContainers = [];
    +
    +	for (var i = 0, n = this.skeleton.drawOrder.length; i < n; i++) {
    +		var slot = this.skeleton.drawOrder[i];
    +		var attachment = slot.attachment;
    +		var slotContainer = new PIXI.DisplayObjectContainer();
    +		this.slotContainers.push(slotContainer);
    +		this.addChild(slotContainer);
    +		if (!(attachment instanceof spine.RegionAttachment)) {
    +			continue;
    +		}
    +		var spriteName = attachment.rendererObject.name;
    +		var sprite = this.createSprite(slot, attachment.rendererObject);
    +		slot.currentSprite = sprite;
    +		slot.currentSpriteName = spriteName;
    +		slotContainer.addChild(sprite);
    +	}
    +};
    +
    +PIXI.Spine.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
    +PIXI.Spine.prototype.constructor = PIXI.Spine;
    +
    +/*
    + * Updates the object transform for rendering
    + *
    + * @method updateTransform
    + * @private
    + */
    +PIXI.Spine.prototype.updateTransform = function () {
    +	this.lastTime = this.lastTime || Date.now();
    +	var timeDelta = (Date.now() - this.lastTime) * 0.001;
    +	this.lastTime = Date.now();
    +	this.state.update(timeDelta);
     	this.state.apply(this.skeleton);
     	this.skeleton.updateWorldTransform();
     
    -	
    -	for (var i = 0; i < this.skeleton.drawOrder.length; i++) 
    -	{
    -		var slot = this.skeleton.drawOrder[i];
    +	var drawOrder = this.skeleton.drawOrder;
    +	for (var i = 0, n = drawOrder.length; i < n; i++) {
    +		var slot = drawOrder[i];
    +		var attachment = slot.attachment;
    +		var slotContainer = this.slotContainers[i];
    +		if (!(attachment instanceof spine.RegionAttachment)) {
    +			slotContainer.visible = false;
    +			continue;
    +		}
     
    -		var x = slot.bone.worldX + slot.attachment.x * slot.bone.m00 + slot.attachment.y * slot.bone.m01 + slot.attachment.width * 0.5;
    -		var y = slot.bone.worldY + slot.attachment.x * slot.bone.m10 + slot.attachment.y * slot.bone.m11 + slot.attachment.height * 0.5;
    -		//console.log(x + ' : ' + y);
    -		
    -		 
    -			//console.log(slot.attachment.name)
    -			if(slot.cacheName != slot.attachment.name)
    -			{
    -				var attachmentName = slot.attachment.name;
    -		
    -				if(!PIXI.TextureCache[attachmentName])
    -				{
    -					attachmentName += ".png";
    +		if (attachment.rendererObject) {
    +			if (!slot.currentSpriteName || slot.currentSpriteName != attachment.name) {
    +				var spriteName = attachment.rendererObject.name;
    +				if (slot.currentSprite !== undefined) {
    +					slot.currentSprite.visible = false;
     				}
    -				
    -				this.sprites[i].setTexture(PIXI.TextureCache[attachmentName]);
    -				
    -				slot.cacheName = slot.attachment.name;
    +				slot.sprites = slot.sprites || {};
    +				if (slot.sprites[spriteName] !== undefined) {
    +					slot.sprites[spriteName].visible = true;
    +				} else {
    +					var sprite = this.createSprite(slot, attachment.rendererObject);
    +					slotContainer.addChild(sprite);
    +				}
    +				slot.currentSprite = slot.sprites[spriteName];
    +				slot.currentSpriteName = spriteName;
     			}
    -		
    -		x += -((slot.attachment.width * (slot.bone.worldScaleX + slot.attachment.scaleX - 1))>>1);
    -		y += -((slot.attachment.height * (slot.bone.worldScaleY + slot.attachment.scaleY - 1))>>1);
    -		
    -		
    -		this.sprites[i].position.x = x;
    -		this.sprites[i].position.y = y;
    -		this.sprites[i].rotation = (-(slot.bone.worldRotation + slot.attachment.rotation)) * (Math.PI/180);
    -	}	
    -	
    -	PIXI.DisplayObjectContainer.prototype.updateTransform.call(this);
    -}
    +		}
    +		slotContainer.visible = true;
     
    -/*
    +		var bone = slot.bone;
    +
    +		slotContainer.position.x = bone.worldX + attachment.x * bone.m00 + attachment.y * bone.m01;
    +		slotContainer.position.y = bone.worldY + attachment.x * bone.m10 + attachment.y * bone.m11;
    +		slotContainer.scale.x = bone.worldScaleX;
    +		slotContainer.scale.y = bone.worldScaleY;
    +
    +		slotContainer.rotation = -(slot.bone.worldRotation * Math.PI / 180);
    +	}
    +
    +	PIXI.DisplayObjectContainer.prototype.updateTransform.call(this);
    +};
    +
    +
    +PIXI.Spine.prototype.createSprite = function (slot, descriptor) {
    +	var name = PIXI.TextureCache[descriptor.name] ? descriptor.name : descriptor.name + ".png";
    +	var sprite = new PIXI.Sprite(PIXI.Texture.fromFrame(name));
    +	sprite.scale = descriptor.scale;
    +	sprite.rotation = descriptor.rotation;
    +	sprite.anchor.x = sprite.anchor.y = 0.5;
    +
    +	slot.sprites = slot.sprites || {};
    +	slot.sprites[descriptor.name] = sprite;
    +	return sprite;
    +};
    +
    +/*
      * Awesome JS run time provided by EsotericSoftware
    - * 
    - * https://github.com/EsotericSoftware/spine-runtimes
    - * 
    - */
    + *
    + * https://github.com/EsotericSoftware/spine-runtimes
    + *
    + */
     
     var spine = {};
     
    @@ -291,8 +334,8 @@ spine.Bone.prototype = {
     	x: 0, y: 0,
     	rotation: 0,
     	scaleX: 1, scaleY: 1,
    -	m00: 0, m01: 0, worldX: 0, // a b x
    -	m10: 0, m11: 0, worldY: 0, // c d y
    +	m00: 0, m01: 0, worldX: 0, // a b x
    +	m10: 0, m11: 0, worldY: 0, // c d y
     	worldRotation: 0,
     	worldScaleX: 1, worldScaleY: 1,
     	updateWorldTransform: function (flipX, flipY) {
    @@ -310,7 +353,7 @@ spine.Bone.prototype = {
     			this.worldScaleY = this.scaleY;
     			this.worldRotation = this.rotation;
     		}
    -		var radians = this.worldRotation * Math.PI / 180;
    +		var radians = this.worldRotation * Math.PI / 180;
     		var cos = Math.cos(radians);
     		var sin = Math.sin(radians);
     		this.m00 = cos * this.worldScaleX;
    @@ -366,7 +409,7 @@ spine.Slot.prototype = {
     		this.g = data.g;
     		this.b = data.b;
     		this.a = data.a;
    -		
    +
     		var slotDatas = this.skeleton.data.slots;
     		for (var i = 0, n = slotDatas.length; i < n; i++) {
     			if (slotDatas[i] == data) {
    @@ -424,7 +467,7 @@ spine.Animation.prototype = {
     
     spine.binarySearch = function (values, target, step) {
     	var low = 0;
    -	var high = Math.floor(values.length / step) - 2;
    +	var high = Math.floor(values.length / step) - 2;
     	if (high == 0) return step;
     	var current = high >>> 1;
     	while (true) {
    @@ -443,21 +486,21 @@ spine.linearSearch = function (values, target, step) {
     };
     
     spine.Curves = function (frameCount) {
    -	this.curves = []; // dfx, dfy, ddfx, ddfy, dddfx, dddfy, ...
    +	this.curves = []; // dfx, dfy, ddfx, ddfy, dddfx, dddfy, ...
     	this.curves.length = (frameCount - 1) * 6;
     };
     spine.Curves.prototype = {
     	setLinear: function (frameIndex) {
    -		this.curves[frameIndex * 6] = 0/*LINEAR*/;
    +		this.curves[frameIndex * 6] = 0/*LINEAR*/;
     	},
     	setStepped: function (frameIndex) {
    -		this.curves[frameIndex * 6] = -1/*STEPPED*/;
    +		this.curves[frameIndex * 6] = -1/*STEPPED*/;
     	},
    -	/** Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next.
    +	/** Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next.
     	 * cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of
    -	 * the difference between the keyframe's values. */
    +	 * the difference between the keyframe's values. */
     	setCurve: function (frameIndex, cx1, cy1, cx2, cy2) {
    -		var subdiv_step = 1 / 10/*BEZIER_SEGMENTS*/;
    +		var subdiv_step = 1 / 10/*BEZIER_SEGMENTS*/;
     		var subdiv_step2 = subdiv_step * subdiv_step;
     		var subdiv_step3 = subdiv_step2 * subdiv_step;
     		var pre1 = 3 * subdiv_step;
    @@ -482,20 +525,20 @@ spine.Curves.prototype = {
     		var curveIndex = frameIndex * 6;
     		var curves = this.curves;
     		var dfx = curves[curveIndex];
    -		if (!dfx/*LINEAR*/) return percent;
    -		if (dfx == -1/*STEPPED*/) return 0;
    +		if (!dfx/*LINEAR*/) return percent;
    +		if (dfx == -1/*STEPPED*/) return 0;
     		var dfy = curves[curveIndex + 1];
     		var ddfx = curves[curveIndex + 2];
     		var ddfy = curves[curveIndex + 3];
     		var dddfx = curves[curveIndex + 4];
     		var dddfy = curves[curveIndex + 5];
     		var x = dfx, y = dfy;
    -		var i = 10/*BEZIER_SEGMENTS*/ - 2;
    +		var i = 10/*BEZIER_SEGMENTS*/ - 2;
     		while (true) {
     			if (x >= percent) {
     				var lastX = x - dfx;
     				var lastY = y - dfy;
    -				return lastY + (y - lastY) * (percent - lastX) / (x - lastX);
    +				return lastY + (y - lastY) * (percent - lastX) / (x - lastX);
     			}
     			if (i == 0) break;
     			i--;
    @@ -506,19 +549,19 @@ spine.Curves.prototype = {
     			x += dfx;
     			y += dfy;
     		}
    -		return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1.
    +		return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1.
     	}
     };
     
     spine.RotateTimeline = function (frameCount) {
     	this.curves = new spine.Curves(frameCount);
    -	this.frames = []; // time, angle, ...
    +	this.frames = []; // time, angle, ...
     	this.frames.length = frameCount * 2;
     };
     spine.RotateTimeline.prototype = {
     	boneIndex: 0,
     	getFrameCount: function () {
    -		return this.frames.length / 2;
    +		return this.frames.length / 2;
     	},
     	setFrame: function (frameIndex, time, angle) {
     		frameIndex *= 2;
    @@ -527,11 +570,11 @@ spine.RotateTimeline.prototype = {
     	},
     	apply: function (skeleton, time, alpha) {
     		var frames = this.frames;
    -		if (time < frames[0]) return; // Time is before first frame.
    +		if (time < frames[0]) return; // Time is before first frame.
     
     		var bone = skeleton.bones[this.boneIndex];
     
    -		if (time >= frames[frames.length - 2]) { // Time is after last frame.
    +		if (time >= frames[frames.length - 2]) { // Time is after last frame.
     			var amount = bone.data.rotation + frames[frames.length - 1] - bone.rotation;
     			while (amount > 180)
     				amount -= 360;
    @@ -541,14 +584,14 @@ spine.RotateTimeline.prototype = {
     			return;
     		}
     
    -		// Interpolate between the last frame and the current frame.
    +		// Interpolate between the last frame and the current frame.
     		var frameIndex = spine.binarySearch(frames, time, 2);
     		var lastFrameValue = frames[frameIndex - 1];
     		var frameTime = frames[frameIndex];
    -		var percent = 1 - (time - frameTime) / (frames[frameIndex - 2/*LAST_FRAME_TIME*/] - frameTime);
    -		percent = this.curves.getCurvePercent(frameIndex / 2 - 1, percent);
    +		var percent = 1 - (time - frameTime) / (frames[frameIndex - 2/*LAST_FRAME_TIME*/] - frameTime);
    +		percent = this.curves.getCurvePercent(frameIndex / 2 - 1, percent);
     
    -		var amount = frames[frameIndex + 1/*FRAME_VALUE*/] - lastFrameValue;
    +		var amount = frames[frameIndex + 1/*FRAME_VALUE*/] - lastFrameValue;
     		while (amount > 180)
     			amount -= 360;
     		while (amount < -180)
    @@ -564,13 +607,13 @@ spine.RotateTimeline.prototype = {
     
     spine.TranslateTimeline = function (frameCount) {
     	this.curves = new spine.Curves(frameCount);
    -	this.frames = []; // time, x, y, ...
    +	this.frames = []; // time, x, y, ...
     	this.frames.length = frameCount * 3;
     };
     spine.TranslateTimeline.prototype = {
     	boneIndex: 0,
     	getFrameCount: function () {
    -		return this.frames.length / 3;
    +		return this.frames.length / 3;
     	},
     	setFrame: function (frameIndex, time, x, y) {
     		frameIndex *= 3;
    @@ -580,37 +623,38 @@ spine.TranslateTimeline.prototype = {
     	},
     	apply: function (skeleton, time, alpha) {
     		var frames = this.frames;
    -		if (time < frames[0]) return; // Time is before first frame.
    +		if (time < frames[0]) return; // Time is before first frame.
     
     		var bone = skeleton.bones[this.boneIndex];
     
    -		if (time >= frames[frames.length - 3]) { // Time is after last frame.
    +		if (time >= frames[frames.length - 3]) { // Time is after last frame.
     			bone.x += (bone.data.x + frames[frames.length - 2] - bone.x) * alpha;
     			bone.y += (bone.data.y + frames[frames.length - 1] - bone.y) * alpha;
     			return;
     		}
     
    -		// Interpolate between the last frame and the current frame.
    +		// Interpolate between the last frame and the current frame.
     		var frameIndex = spine.binarySearch(frames, time, 3);
     		var lastFrameX = frames[frameIndex - 2];
     		var lastFrameY = frames[frameIndex - 1];
     		var frameTime = frames[frameIndex];
    -		var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime);
    -		percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent);
    -		bone.x += (bone.data.x + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.x) * alpha;
    -		bone.y += (bone.data.y + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.y) * alpha;
    +		var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime);
    +		percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent);
    +
    +		bone.x += (bone.data.x + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.x) * alpha;
    +		bone.y += (bone.data.y + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.y) * alpha;
     	}
     };
     
     spine.ScaleTimeline = function (frameCount) {
     	this.curves = new spine.Curves(frameCount);
    -	this.frames = []; // time, x, y, ...
    +	this.frames = []; // time, x, y, ...
     	this.frames.length = frameCount * 3;
     };
     spine.ScaleTimeline.prototype = {
     	boneIndex: 0,
     	getFrameCount: function () {
    -		return this.frames.length / 3;
    +		return this.frames.length / 3;
     	},
     	setFrame: function (frameIndex, time, x, y) {
     		frameIndex *= 3;
    @@ -620,40 +664,38 @@ spine.ScaleTimeline.prototype = {
     	},
     	apply: function (skeleton, time, alpha) {
     		var frames = this.frames;
    -		if (time < frames[0]) return; // Time is before first frame.
    -		
    +		if (time < frames[0]) return; // Time is before first frame.
    +
     		var bone = skeleton.bones[this.boneIndex];
     
    -		if (time >= frames[frames.length - 3]) { // Time is after last frame.
    +		if (time >= frames[frames.length - 3]) { // Time is after last frame.
     			bone.scaleX += (bone.data.scaleX - 1 + frames[frames.length - 2] - bone.scaleX) * alpha;
     			bone.scaleY += (bone.data.scaleY - 1 + frames[frames.length - 1] - bone.scaleY) * alpha;
    -			
    -			
     			return;
     		}
     
    -		// Interpolate between the last frame and the current frame.
    +		// Interpolate between the last frame and the current frame.
     		var frameIndex = spine.binarySearch(frames, time, 3);
     		var lastFrameX = frames[frameIndex - 2];
     		var lastFrameY = frames[frameIndex - 1];
     		var frameTime = frames[frameIndex];
    -		var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime);
    -		percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent);
    +		var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime);
    +		percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent);
     
    -		bone.scaleX += (bone.data.scaleX - 1 + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.scaleX) * alpha;
    -		bone.scaleY += (bone.data.scaleY - 1 + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.scaleY) * alpha;
    +		bone.scaleX += (bone.data.scaleX - 1 + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.scaleX) * alpha;
    +		bone.scaleY += (bone.data.scaleY - 1 + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.scaleY) * alpha;
     	}
     };
     
     spine.ColorTimeline = function (frameCount) {
     	this.curves = new spine.Curves(frameCount);
    -	this.frames = []; // time, r, g, b, a, ...
    +	this.frames = []; // time, r, g, b, a, ...
     	this.frames.length = frameCount * 5;
     };
     spine.ColorTimeline.prototype = {
     	slotIndex: 0,
     	getFrameCount: function () {
    -		return this.frames.length / 2;
    +		return this.frames.length / 2;
     	},
     	setFrame: function (frameIndex, time, x, y) {
     		frameIndex *= 5;
    @@ -665,10 +707,11 @@ spine.ColorTimeline.prototype = {
     	},
     	apply: function (skeleton, time, alpha) {
     		var frames = this.frames;
    -		if (time < frames[0]) return; // Time is before first frame.
    +		if (time < frames[0]) return; // Time is before first frame.
    +
     		var slot = skeleton.slots[this.slotIndex];
     
    -		if (time >= frames[frames.length - 5]) { // Time is after last frame.
    +		if (time >= frames[frames.length - 5]) { // Time is after last frame.
     			var i = frames.length - 1;
     			slot.r = frames[i - 3];
     			slot.g = frames[i - 2];
    @@ -677,20 +720,20 @@ spine.ColorTimeline.prototype = {
     			return;
     		}
     
    -		// Interpolate between the last frame and the current frame.
    +		// Interpolate between the last frame and the current frame.
     		var frameIndex = spine.binarySearch(frames, time, 5);
     		var lastFrameR = frames[frameIndex - 4];
     		var lastFrameG = frames[frameIndex - 3];
     		var lastFrameB = frames[frameIndex - 2];
     		var lastFrameA = frames[frameIndex - 1];
     		var frameTime = frames[frameIndex];
    -		var percent = 1 - (time - frameTime) / (frames[frameIndex - 5/*LAST_FRAME_TIME*/] - frameTime);
    -		percent = this.curves.getCurvePercent(frameIndex / 5 - 1, percent);
    +		var percent = 1 - (time - frameTime) / (frames[frameIndex - 5/*LAST_FRAME_TIME*/] - frameTime);
    +		percent = this.curves.getCurvePercent(frameIndex / 5 - 1, percent);
     
    -		var r = lastFrameR + (frames[frameIndex + 1/*FRAME_R*/] - lastFrameR) * percent;
    -		var g = lastFrameG + (frames[frameIndex + 2/*FRAME_G*/] - lastFrameG) * percent;
    -		var b = lastFrameB + (frames[frameIndex + 3/*FRAME_B*/] - lastFrameB) * percent;
    -		var a = lastFrameA + (frames[frameIndex + 4/*FRAME_A*/] - lastFrameA) * percent;
    +		var r = lastFrameR + (frames[frameIndex + 1/*FRAME_R*/] - lastFrameR) * percent;
    +		var g = lastFrameG + (frames[frameIndex + 2/*FRAME_G*/] - lastFrameG) * percent;
    +		var b = lastFrameB + (frames[frameIndex + 3/*FRAME_B*/] - lastFrameB) * percent;
    +		var a = lastFrameA + (frames[frameIndex + 4/*FRAME_A*/] - lastFrameA) * percent;
     		if (alpha < 1) {
     			slot.r += (r - slot.r) * alpha;
     			slot.g += (g - slot.g) * alpha;
    @@ -707,15 +750,15 @@ spine.ColorTimeline.prototype = {
     
     spine.AttachmentTimeline = function (frameCount) {
     	this.curves = new spine.Curves(frameCount);
    -	this.frames = []; // time, ...
    +	this.frames = []; // time, ...
     	this.frames.length = frameCount;
    -	this.attachmentNames = []; // time, ...
    +	this.attachmentNames = []; // time, ...
     	this.attachmentNames.length = frameCount;
     };
     spine.AttachmentTimeline.prototype = {
     	slotIndex: 0,
     	getFrameCount: function () {
    -		return this.frames.length / 2;
    +            return this.frames.length;
     	},
     	setFrame: function (frameIndex, time, attachmentName) {
     		this.frames[frameIndex] = time;
    @@ -723,20 +766,15 @@ spine.AttachmentTimeline.prototype = {
     	},
     	apply: function (skeleton, time, alpha) {
     		var frames = this.frames;
    -		if (time < frames[0]) return; // Time is before first frame.
    +		if (time < frames[0]) return; // Time is before first frame.
     
     		var frameIndex;
    -		if (time >= frames[frames.length - 1]) // Time is after last frame.
    +		if (time >= frames[frames.length - 1]) // Time is after last frame.
     			frameIndex = frames.length - 1;
     		else
     			frameIndex = spine.binarySearch(frames, time, 1) - 1;
     
     		var attachmentName = this.attachmentNames[frameIndex];
    -		//console.log(skeleton.slots[this.slotIndex])
    -		
    -		// change the name!
    -	//	skeleton.slots[this.slotIndex].attachmentName = attachmentName;
    -		
     		skeleton.slots[this.slotIndex].setAttachment(!attachmentName ? null : skeleton.getAttachmentBySlotIndex(this.slotIndex, attachmentName));
     	}
     };
    @@ -749,21 +787,21 @@ spine.SkeletonData = function () {
     };
     spine.SkeletonData.prototype = {
     	defaultSkin: null,
    -	/** @return May be null. */
    +	/** @return May be null. */
     	findBone: function (boneName) {
     		var bones = this.bones;
     		for (var i = 0, n = bones.length; i < n; i++)
     			if (bones[i].name == boneName) return bones[i];
     		return null;
     	},
    -	/** @return -1 if the bone was not found. */
    +	/** @return -1 if the bone was not found. */
     	findBoneIndex: function (boneName) {
     		var bones = this.bones;
     		for (var i = 0, n = bones.length; i < n; i++)
     			if (bones[i].name == boneName) return i;
     		return -1;
     	},
    -	/** @return May be null. */
    +	/** @return May be null. */
     	findSlot: function (slotName) {
     		var slots = this.slots;
     		for (var i = 0, n = slots.length; i < n; i++) {
    @@ -771,21 +809,21 @@ spine.SkeletonData.prototype = {
     		}
     		return null;
     	},
    -	/** @return -1 if the bone was not found. */
    +	/** @return -1 if the bone was not found. */
     	findSlotIndex: function (slotName) {
     		var slots = this.slots;
     		for (var i = 0, n = slots.length; i < n; i++)
     			if (slots[i].name == slotName) return i;
     		return -1;
     	},
    -	/** @return May be null. */
    +	/** @return May be null. */
     	findSkin: function (skinName) {
     		var skins = this.skins;
     		for (var i = 0, n = skins.length; i < n; i++)
     			if (skins[i].name == skinName) return skins[i];
     		return null;
     	},
    -	/** @return May be null. */
    +	/** @return May be null. */
     	findAnimation: function (animationName) {
     		var animations = this.animations;
     		for (var i = 0, n = animations.length; i < n; i++)
    @@ -820,7 +858,7 @@ spine.Skeleton.prototype = {
     	r: 1, g: 1, b: 1, a: 1,
     	time: 0,
     	flipX: false, flipY: false,
    -	/** Updates the world transform for each bone. */
    +	/** Updates the world transform for each bone. */
     	updateWorldTransform: function () {
     		var flipX = this.flipX;
     		var flipY = this.flipY;
    @@ -828,7 +866,7 @@ spine.Skeleton.prototype = {
     		for (var i = 0, n = bones.length; i < n; i++)
     			bones[i].updateWorldTransform(flipX, flipY);
     	},
    -	/** Sets the bones and slots to their setup pose values. */
    +	/** Sets the bones and slots to their setup pose values. */
     	setToSetupPose: function () {
     		this.setBonesToSetupPose();
     		this.setSlotsToSetupPose();
    @@ -843,32 +881,32 @@ spine.Skeleton.prototype = {
     		for (var i = 0, n = slots.length; i < n; i++)
     			slots[i].setToSetupPose(i);
     	},
    -	/** @return May return null. */
    +	/** @return May return null. */
     	getRootBone: function () {
     		return this.bones.length == 0 ? null : this.bones[0];
     	},
    -	/** @return May be null. */
    +	/** @return May be null. */
     	findBone: function (boneName) {
     		var bones = this.bones;
     		for (var i = 0, n = bones.length; i < n; i++)
     			if (bones[i].data.name == boneName) return bones[i];
     		return null;
     	},
    -	/** @return -1 if the bone was not found. */
    +	/** @return -1 if the bone was not found. */
     	findBoneIndex: function (boneName) {
     		var bones = this.bones;
     		for (var i = 0, n = bones.length; i < n; i++)
     			if (bones[i].data.name == boneName) return i;
     		return -1;
     	},
    -	/** @return May be null. */
    +	/** @return May be null. */
     	findSlot: function (slotName) {
     		var slots = this.slots;
     		for (var i = 0, n = slots.length; i < n; i++)
     			if (slots[i].data.name == slotName) return slots[i];
     		return null;
     	},
    -	/** @return -1 if the bone was not found. */
    +	/** @return -1 if the bone was not found. */
     	findSlotIndex: function (slotName) {
     		var slots = this.slots;
     		for (var i = 0, n = slots.length; i < n; i++)
    @@ -880,18 +918,18 @@ spine.Skeleton.prototype = {
     		if (!skin) throw "Skin not found: " + skinName;
     		this.setSkin(skin);
     	},
    -	/** Sets the skin used to look up attachments not found in the {@link SkeletonData#getDefaultSkin() default skin}. Attachments
    +	/** Sets the skin used to look up attachments not found in the {@link SkeletonData#getDefaultSkin() default skin}. Attachments
     	 * from the new skin are attached if the corresponding attachment from the old skin was attached.
    -	 * @param newSkin May be null. */
    +	 * @param newSkin May be null. */
     	setSkin: function (newSkin) {
     		if (this.skin && newSkin) newSkin._attachAll(this, this.skin);
     		this.skin = newSkin;
     	},
    -	/** @return May be null. */
    +	/** @return May be null. */
     	getAttachmentBySlotName: function (slotName, attachmentName) {
     		return this.getAttachmentBySlotIndex(this.data.findSlotIndex(slotName), attachmentName);
     	},
    -	/** @return May be null. */
    +	/** @return May be null. */
     	getAttachmentBySlotIndex: function (slotIndex, attachmentName) {
     		if (this.skin) {
     			var attachment = this.skin.getAttachment(slotIndex, attachmentName);
    @@ -900,7 +938,7 @@ spine.Skeleton.prototype = {
     		if (this.data.defaultSkin) return this.data.defaultSkin.getAttachment(slotIndex, attachmentName);
     		return null;
     	},
    -	/** @param attachmentName May be null. */
    +	/** @param attachmentName May be null. */
     	setAttachment: function (slotName, attachmentName) {
     		var slots = this.slots;
     		for (var i = 0, n = slots.size; i < n; i++) {
    @@ -908,11 +946,9 @@ spine.Skeleton.prototype = {
     			if (slot.data.name == slotName) {
     				var attachment = null;
     				if (attachmentName) {
    -					
     					attachment = this.getAttachment(i, attachmentName);
     					if (attachment == null) throw "Attachment not found: " + attachmentName + ", for slot: " + slotName;
     				}
    -				
     				slot.setAttachment(attachment);
     				return;
     			}
    @@ -946,33 +982,33 @@ spine.RegionAttachment.prototype = {
     	setUVs: function (u, v, u2, v2, rotate) {
     		var uvs = this.uvs;
     		if (rotate) {
    -			uvs[2/*X2*/] = u;
    -			uvs[3/*Y2*/] = v2;
    -			uvs[4/*X3*/] = u;
    -			uvs[5/*Y3*/] = v;
    -			uvs[6/*X4*/] = u2;
    -			uvs[7/*Y4*/] = v;
    -			uvs[0/*X1*/] = u2;
    -			uvs[1/*Y1*/] = v2;
    +			uvs[2/*X2*/] = u;
    +			uvs[3/*Y2*/] = v2;
    +			uvs[4/*X3*/] = u;
    +			uvs[5/*Y3*/] = v;
    +			uvs[6/*X4*/] = u2;
    +			uvs[7/*Y4*/] = v;
    +			uvs[0/*X1*/] = u2;
    +			uvs[1/*Y1*/] = v2;
     		} else {
    -			uvs[0/*X1*/] = u;
    -			uvs[1/*Y1*/] = v2;
    -			uvs[2/*X2*/] = u;
    -			uvs[3/*Y2*/] = v;
    -			uvs[4/*X3*/] = u2;
    -			uvs[5/*Y3*/] = v;
    -			uvs[6/*X4*/] = u2;
    -			uvs[7/*Y4*/] = v2;
    +			uvs[0/*X1*/] = u;
    +			uvs[1/*Y1*/] = v2;
    +			uvs[2/*X2*/] = u;
    +			uvs[3/*Y2*/] = v;
    +			uvs[4/*X3*/] = u2;
    +			uvs[5/*Y3*/] = v;
    +			uvs[6/*X4*/] = u2;
    +			uvs[7/*Y4*/] = v2;
     		}
     	},
     	updateOffset: function () {
    -		var regionScaleX = this.width / this.regionOriginalWidth * this.scaleX;
    -		var regionScaleY = this.height / this.regionOriginalHeight * this.scaleY;
    -		var localX = -this.width / 2 * this.scaleX + this.regionOffsetX * regionScaleX;
    -		var localY = -this.height / 2 * this.scaleY + this.regionOffsetY * regionScaleY;
    +		var regionScaleX = this.width / this.regionOriginalWidth * this.scaleX;
    +		var regionScaleY = this.height / this.regionOriginalHeight * this.scaleY;
    +		var localX = -this.width / 2 * this.scaleX + this.regionOffsetX * regionScaleX;
    +		var localY = -this.height / 2 * this.scaleY + this.regionOffsetY * regionScaleY;
     		var localX2 = localX + this.regionWidth * regionScaleX;
     		var localY2 = localY + this.regionHeight * regionScaleY;
    -		var radians = this.rotation * Math.PI / 180;
    +		var radians = this.rotation * Math.PI / 180;
     		var cos = Math.cos(radians);
     		var sin = Math.sin(radians);
     		var localXCos = localX * cos + this.x;
    @@ -984,17 +1020,16 @@ spine.RegionAttachment.prototype = {
     		var localY2Cos = localY2 * cos + this.y;
     		var localY2Sin = localY2 * sin;
     		var offset = this.offset;
    -		offset[0/*X1*/] = localXCos - localYSin;
    -		offset[1/*Y1*/] = localYCos + localXSin;
    -		offset[2/*X2*/] = localXCos - localY2Sin;
    -		offset[3/*Y2*/] = localY2Cos + localXSin;
    -		offset[4/*X3*/] = localX2Cos - localY2Sin;
    -		offset[5/*Y3*/] = localY2Cos + localX2Sin;
    -		offset[6/*X4*/] = localX2Cos - localYSin;
    -		offset[7/*Y4*/] = localYCos + localX2Sin;
    +		offset[0/*X1*/] = localXCos - localYSin;
    +		offset[1/*Y1*/] = localYCos + localXSin;
    +		offset[2/*X2*/] = localXCos - localY2Sin;
    +		offset[3/*Y2*/] = localY2Cos + localXSin;
    +		offset[4/*X3*/] = localX2Cos - localY2Sin;
    +		offset[5/*Y3*/] = localY2Cos + localX2Sin;
    +		offset[6/*X4*/] = localX2Cos - localYSin;
    +		offset[7/*Y4*/] = localYCos + localX2Sin;
     	},
     	computeVertices: function (x, y, bone, vertices) {
    -		
     		x += bone.worldX;
     		y += bone.worldY;
     		var m00 = bone.m00;
    @@ -1002,14 +1037,14 @@ spine.RegionAttachment.prototype = {
     		var m10 = bone.m10;
     		var m11 = bone.m11;
     		var offset = this.offset;
    -		vertices[0/*X1*/] = offset[0/*X1*/] * m00 + offset[1/*Y1*/] * m01 + x;
    -		vertices[1/*Y1*/] = offset[0/*X1*/] * m10 + offset[1/*Y1*/] * m11 + y;
    -		vertices[2/*X2*/] = offset[2/*X2*/] * m00 + offset[3/*Y2*/] * m01 + x;
    -		vertices[3/*Y2*/] = offset[2/*X2*/] * m10 + offset[3/*Y2*/] * m11 + y;
    -		vertices[4/*X3*/] = offset[4/*X3*/] * m00 + offset[5/*X3*/] * m01 + x;
    -		vertices[5/*X3*/] = offset[4/*X3*/] * m10 + offset[5/*X3*/] * m11 + y;
    -		vertices[6/*X4*/] = offset[6/*X4*/] * m00 + offset[7/*Y4*/] * m01 + x;
    -		vertices[7/*Y4*/] = offset[6/*X4*/] * m10 + offset[7/*Y4*/] * m11 + y;
    +		vertices[0/*X1*/] = offset[0/*X1*/] * m00 + offset[1/*Y1*/] * m01 + x;
    +		vertices[1/*Y1*/] = offset[0/*X1*/] * m10 + offset[1/*Y1*/] * m11 + y;
    +		vertices[2/*X2*/] = offset[2/*X2*/] * m00 + offset[3/*Y2*/] * m01 + x;
    +		vertices[3/*Y2*/] = offset[2/*X2*/] * m10 + offset[3/*Y2*/] * m11 + y;
    +		vertices[4/*X3*/] = offset[4/*X3*/] * m00 + offset[5/*X3*/] * m01 + x;
    +		vertices[5/*X3*/] = offset[4/*X3*/] * m10 + offset[5/*X3*/] * m11 + y;
    +		vertices[6/*X4*/] = offset[6/*X4*/] * m00 + offset[7/*Y4*/] * m01 + x;
    +		vertices[7/*Y4*/] = offset[6/*X4*/] * m10 + offset[7/*Y4*/] * m11 + y;
     	}
     }
     
    @@ -1018,6 +1053,7 @@ spine.AnimationStateData = function (skeletonData) {
     	this.animationToMixTime = {};
     };
     spine.AnimationStateData.prototype = {
    +        defaultMix: 0,
     	setMixByName: function (fromName, toName, duration) {
     		var from = this.skeletonData.findAnimation(fromName);
     		if (!from) throw "Animation not found: " + fromName;
    @@ -1030,7 +1066,7 @@ spine.AnimationStateData.prototype = {
     	},
     	getMix: function (from, to) {
     		var time = this.animationToMixTime[from.name + ":" + to.name];
    -		return time ? time : 0;
    +            return time ? time : this.defaultMix;
     	}
     };
     
    @@ -1064,13 +1100,13 @@ spine.AnimationState.prototype = {
     		if (!this.current) return;
     		if (this.previous) {
     			this.previous.apply(skeleton, this.previousTime, this.previousLoop);
    -			var alpha = this.mixTime / this.mixDuration;
    +			var alpha = this.mixTime / this.mixDuration;
     			if (alpha >= 1) {
     				alpha = 1;
     				this.previous = null;
     			}
     			this.current.mix(skeleton, this.currentTime, this.currentLoop, alpha);
    -		} else 
    +		} else
     			this.current.apply(skeleton, this.currentTime, this.currentLoop);
     	},
     	clearAnimation: function () {
    @@ -1093,26 +1129,26 @@ spine.AnimationState.prototype = {
     		this.currentLoop = loop;
     		this.currentTime = 0;
     	},
    -	/** @see #setAnimation(Animation, Boolean) */
    +	/** @see #setAnimation(Animation, Boolean) */
     	setAnimationByName: function (animationName, loop) {
     		var animation = this.data.skeletonData.findAnimation(animationName);
     		if (!animation) throw "Animation not found: " + animationName;
     		this.setAnimation(animation, loop);
     	},
    -	/** Set the current animation. Any queued animations are cleared and the current animation time is set to 0.
    -	 * @param animation May be null. */
    +	/** Set the current animation. Any queued animations are cleared and the current animation time is set to 0.
    +	 * @param animation May be null. */
     	setAnimation: function (animation, loop) {
     		this.queue.length = 0;
     		this._setAnimation(animation, loop);
     	},
    -	/** @see #addAnimation(Animation, Boolean, Number) */
    +	/** @see #addAnimation(Animation, Boolean, Number) */
     	addAnimationByName: function (animationName, loop, delay) {
     		var animation = this.data.skeletonData.findAnimation(animationName);
     		if (!animation) throw "Animation not found: " + animationName;
     		this.addAnimation(animation, loop, delay);
     	},
    -	/** Adds an animation to be played delay seconds after the current or last queued animation.
    -	 * @param delay May be <= 0 to use duration of previous animation minus any mix duration plus the negative delay. */
    +	/** Adds an animation to be played delay seconds after the current or last queued animation.
    +	 * @param delay May be <= 0 to use duration of previous animation minus any mix duration plus the negative delay. */
     	addAnimation: function (animation, loop, delay) {
     		var entry = {};
     		entry.animation = animation;
    @@ -1129,7 +1165,7 @@ spine.AnimationState.prototype = {
     
     		this.queue.push(entry);
     	},
    -	/** Returns true if no animation is set or if the current time is greater than the animation duration, regardless of looping. */
    +	/** Returns true if no animation is set or if the current time is greater than the animation duration, regardless of looping. */
     	isComplete: function () {
     		return !this.current || this.currentTime >= this.current.duration;
     	}
    @@ -1143,7 +1179,7 @@ spine.SkeletonJson.prototype = {
     	readSkeletonData: function (root) {
     		var skeletonData = new spine.SkeletonData();
     
    -		// Bones.
    +		// Bones.
     		var bones = root["bones"];
     		for (var i = 0, n = bones.length; i < n; i++) {
     			var boneMap = bones[i];
    @@ -1162,7 +1198,7 @@ spine.SkeletonJson.prototype = {
     			skeletonData.bones.push(boneData);
     		}
     
    -		// Slots.
    +		// Slots.
     		var slots = root["slots"];
     		for (var i = 0, n = slots.length; i < n; i++) {
     			var slotMap = slots[i];
    @@ -1183,7 +1219,7 @@ spine.SkeletonJson.prototype = {
     			skeletonData.slots.push(slotData);
     		}
     
    -		// Skins.
    +		// Skins.
     		var skins = root["skins"];
     		for (var skinName in skins) {
     			if (!skins.hasOwnProperty(skinName)) continue;
    @@ -1203,7 +1239,7 @@ spine.SkeletonJson.prototype = {
     			if (skin.name == "default") skeletonData.defaultSkin = skin;
     		}
     
    -		// Animations.
    +		// Animations.
     		var animations = root["animations"];
     		for (var animationName in animations) {
     			if (!animations.hasOwnProperty(animationName)) continue;
    @@ -1216,16 +1252,9 @@ spine.SkeletonJson.prototype = {
     		name = map["name"] || name;
     
     		var type = spine.AttachmentType[map["type"] || "region"];
    -		
    -		// @ekelokorpi
    -		// var attachment = this.attachmentLoader.newAttachment(skin, type, name);
    -		var attachment = new spine.RegionAttachment();
    -		
    -		// @Doormat23
    -		// add the name of the attachment
    -		attachment.name = name;
    -		
    +
     		if (type == spine.AttachmentType.region) {
    +			var attachment = new spine.RegionAttachment();
     			attachment.x = (map["x"] || 0) * this.scale;
     			attachment.y = (map["y"] || 0) * this.scale;
     			attachment.scaleX = map["scaleX"] || 1;
    @@ -1234,10 +1263,19 @@ spine.SkeletonJson.prototype = {
     			attachment.width = (map["width"] || 32) * this.scale;
     			attachment.height = (map["height"] || 32) * this.scale;
     			attachment.updateOffset();
    +
    +			attachment.rendererObject = {};
    +			attachment.rendererObject.name = name;
    +			attachment.rendererObject.scale = {};
    +			attachment.rendererObject.scale.x = attachment.scaleX;
    +			attachment.rendererObject.scale.y = attachment.scaleY;
    +			attachment.rendererObject.rotation = -attachment.rotation * Math.PI / 180;
    +			return attachment;
     		}
     
    -		return attachment;
    +            throw "Unknown attachment type: " + type;
     	},
    +
     	readAnimation: function (name, map, skeletonData) {
     		var timelines = [];
     		var duration = 0;
    @@ -1288,7 +1326,7 @@ spine.SkeletonJson.prototype = {
     					}
     					timelines.push(timeline);
     					duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 3 - 3]);
    -					
    +
     				} else
     					throw "Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")";
     			}
    @@ -1331,8 +1369,8 @@ spine.SkeletonJson.prototype = {
     						timeline.setFrame(frameIndex++, valueMap["time"], valueMap["name"]);
     					}
     					timelines.push(timeline);
    -					// PIXI FIX
    -					duration = Math.max(duration, timeline.frames[Math.floor(timeline.getFrameCount()) - 1]);
    +                        duration = Math.max(duration, timeline.frames[timeline.getFrameCount() - 1]);
    +
     				} else
     					throw "Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")";
     			}
    @@ -1350,7 +1388,7 @@ spine.SkeletonJson.readCurve = function (timeline, frameIndex, valueMap) {
     };
     spine.SkeletonJson.toColor = function (hexString, colorIndex) {
     	if (hexString.length != 8) throw "Color hexidecimal length must be 8, recieved: " + hexString;
    -	return parseInt(hexString.substring(colorIndex * 2, 2), 16) / 255;
    +	return parseInt(hexString.substring(colorIndex * 2, 2), 16) / 255;
     };
     
     spine.Atlas = function (atlasText, textureLoader) {
    @@ -1407,24 +1445,24 @@ spine.Atlas = function (atlasText, textureLoader) {
     			var width = parseInt(tuple[0]);
     			var height = parseInt(tuple[1]);
     
    -			region.u = x / page.width;
    -			region.v = y / page.height;
    +			region.u = x / page.width;
    +			region.v = y / page.height;
     			if (region.rotate) {
    -				region.u2 = (x + height) / page.width;
    -				region.v2 = (y + width) / page.height;
    +				region.u2 = (x + height) / page.width;
    +				region.v2 = (y + width) / page.height;
     			} else {
    -				region.u2 = (x + width) / page.width;
    -				region.v2 = (y + height) / page.height;
    +				region.u2 = (x + width) / page.width;
    +				region.v2 = (y + height) / page.height;
     			}
     			region.x = x;
     			region.y = y;
     			region.width = Math.abs(width);
     			region.height = Math.abs(height);
     
    -			if (reader.readTuple(tuple) == 4) { // split is optional
    +			if (reader.readTuple(tuple) == 4) { // split is optional
     				region.splits = [parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])];
     
    -				if (reader.readTuple(tuple) == 4) { // pad is optional, but only present with splits
    +				if (reader.readTuple(tuple) == 4) { // pad is optional, but only present with splits
     					region.pads = [parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])];
     
     					reader.readTuple(tuple);
    @@ -1461,14 +1499,14 @@ spine.Atlas.prototype = {
     		for (var i = 0, n = regions.length; i < n; i++) {
     			var region = regions[i];
     			if (region.page != page) continue;
    -			region.u = region.x / page.width;
    -			region.v = region.y / page.height;
    +			region.u = region.x / page.width;
    +			region.v = region.y / page.height;
     			if (region.rotate) {
    -				region.u2 = (region.x + region.height) / page.width;
    -				region.v2 = (region.y + region.width) / page.height;
    +				region.u2 = (region.x + region.height) / page.width;
    +				region.v2 = (region.y + region.width) / page.height;
     			} else {
    -				region.u2 = (region.x + region.width) / page.width;
    -				region.v2 = (region.y + region.height) / page.height;
    +				region.u2 = (region.x + region.width) / page.width;
    +				region.v2 = (region.y + region.height) / page.height;
     			}
     		}
     	}
    @@ -1529,12 +1567,12 @@ spine.AtlasRegion.prototype = {
     };
     
     spine.AtlasReader = function (text) {
    -	this.lines = text.split(/\r\n|\r|\n/);
    +	this.lines = text.split(/\r\n|\r|\n/);
     };
     spine.AtlasReader.prototype = {
     	index: 0,
     	trim: function (value) {
    -		return value.replace(/^\s+|\s+$/g, "");
    +		return value.replace(/^\s+|\s+$/g, "");
     	},
     	readLine: function () {
     		if (this.index >= this.lines.length) return null;
    @@ -1546,7 +1584,7 @@ spine.AtlasReader.prototype = {
     		if (colon == -1) throw "Invalid line: " + line;
     		return this.trim(line.substring(colon + 1));
     	},
    -	/** Returns the number of tuple values read (2 or 4). */
    +	/** Returns the number of tuple values read (2 or 4). */
     	readTuple: function (tuple) {
     		var line = this.readLine();
     		var colon = line.indexOf(":");
    @@ -1602,13 +1640,13 @@ spine.Bone.yDown = true;
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_extras_Strip.js.html b/docs/files/src_pixi_extras_Strip.js.html index 1d6a08d..797626b 100644 --- a/docs/files/src_pixi_extras_Strip.js.html +++ b/docs/files/src_pixi_extras_Strip.js.html @@ -2,12 +2,12 @@ - src/pixi/extras/Strip.js - Pixi.JS - - - - - + src/pixi/extras/Strip.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,33 +166,33 @@
    -

    File: src/pixi/extras/Strip.js

    +

    File: src/pixi/extras/Strip.js

    -/**
    - * @author Mat Groves http://matgroves.com/
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/
    + */
     
     PIXI.Strip = function(texture, width, height)
     {
     	PIXI.DisplayObjectContainer.call( this );
     	this.texture = texture;
     	this.blendMode = PIXI.blendModes.NORMAL;
    -	
    +
     	try
     	{
     		this.uvs = new Float32Array([0, 1,
     				1, 1,
     				1, 0, 0,1]);
    -	
    +
     		this.verticies = new Float32Array([0, 0,
     						  0,0,
     						  0,0, 0,
     						  0, 0]);
    -						  
    +
     		this.colors = new Float32Array([1, 1, 1, 1]);
    -		
    +
     		this.indices = new Uint16Array([0, 1, 2, 3]);
     	}
     	catch(error)
    @@ -176,28 +200,28 @@ PIXI.Strip = function(texture, width, height)
     		this.uvs = [0, 1,
     				1, 1,
     				1, 0, 0,1];
    -	
    +
     		this.verticies = [0, 0,
     						  0,0,
     						  0,0, 0,
     						  0, 0];
    -						  
    +
     		this.colors = [1, 1, 1, 1];
    -		
    +
     		this.indices = [0, 1, 2, 3];
     	}
    -	
    -	
    -	/*
    +
    +
    +	/*
     	this.uvs = new Float32Array()
     	this.verticies = new Float32Array()
     	this.colors = new Float32Array()
     	this.indices = new Uint16Array()
    -*/
    +*/
     	this.width = width;
     	this.height = height;
    -	
    -	// load the texture!
    +
    +	// load the texture!
     	if(texture.baseTexture.hasLoaded)
     	{
     		this.width   = this.texture.frame.width;
    @@ -209,20 +233,20 @@ PIXI.Strip = function(texture, width, height)
     		this.onTextureUpdateBind = this.onTextureUpdate.bind(this);
     		this.texture.addEventListener( 'update', this.onTextureUpdateBind );
     	}
    -	
    +
     	this.renderable = true;
     }
     
    -// constructor
    -PIXI.Strip.constructor = PIXI.Strip;
    +// constructor
     PIXI.Strip.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
    +PIXI.Strip.prototype.constructor = PIXI.Strip;
     
     PIXI.Strip.prototype.setTexture = function(texture)
     {
    -	//TODO SET THE TEXTURES
    -	//TODO VISIBILITY
    -	
    -	// stop current texture 
    +	//TODO SET THE TEXTURES
    +	//TODO VISIBILITY
    +
    +	// stop current texture
     	this.texture = texture;
     	this.width   = texture.frame.width;
     	this.height  = texture.frame.height;
    @@ -233,7 +257,7 @@ PIXI.Strip.prototype.onTextureUpdate = function(event)
     {
     	this.updateFrame = true;
     }
    -// some helper functions..
    +// some helper functions..
     
     
         
    @@ -245,13 +269,13 @@ PIXI.Strip.prototype.onTextureUpdate = function(event)
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_extras_TilingSprite.js.html b/docs/files/src_pixi_extras_TilingSprite.js.html index e840d1d..29d6e4c 100644 --- a/docs/files/src_pixi_extras_TilingSprite.js.html +++ b/docs/files/src_pixi_extras_TilingSprite.js.html @@ -2,12 +2,12 @@ - src/pixi/extras/TilingSprite.js - Pixi.JS - - - - - + src/pixi/extras/TilingSprite.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,61 +166,100 @@
    -

    File: src/pixi/extras/TilingSprite.js

    +

    File: src/pixi/extras/TilingSprite.js

    -/**
    - * @author Mat Groves http://matgroves.com/
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/
    + */
     
    -/**
    +/**
      * A tiling sprite is a fast way of rendering a tiling image
    + *
      * @class TilingSprite
      * @extends DisplayObjectContainer
      * @constructor
      * @param texture {Texture} the texture of the tiling sprite
      * @param width {Number}  the width of the tiling sprite
      * @param height {Number} the height of the tiling sprite
    - */
    + */
     PIXI.TilingSprite = function(texture, width, height)
     {
     	PIXI.DisplayObjectContainer.call( this );
    -	
    +
    +	/**
    +	 * The texture that the sprite is using
    +	 *
    +	 * @property texture
    +	 * @type Texture
    +	 */
     	this.texture = texture;
    +
    +	/**
    +	 * The width of the tiling sprite
    +	 *
    +	 * @property width
    +	 * @type Number
    +	 */
     	this.width = width;
    +
    +	/**
    +	 * The height of the tiling sprite
    +	 *
    +	 * @property height
    +	 * @type Number
    +	 */
     	this.height = height;
    -	this.renderable = true;
    -	/**
    +
    +	/**
     	 * The scaling of the image that is being tiled
    +	 *
     	 * @property tileScale
     	 * @type Point
    -	 */	
    +	 */
     	this.tileScale = new PIXI.Point(1,1);
    -	/**
    +
    +	/**
     	 * The offset position of the image that is being tiled
    +	 *
     	 * @property tilePosition
     	 * @type Point
    -	 */	
    +	 */
     	this.tilePosition = new PIXI.Point(0,0);
    -	
    +
    +	this.renderable = true;
    +
     	this.blendMode = PIXI.blendModes.NORMAL
     }
     
    -// constructor
    -PIXI.TilingSprite.constructor = PIXI.TilingSprite;
    +// constructor
     PIXI.TilingSprite.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
    +PIXI.TilingSprite.prototype.constructor = PIXI.TilingSprite;
     
    +/**
    + * Sets the texture of the tiling sprite
    + *
    + * @method setTexture
    + * @param texture {Texture} The PIXI texture that is displayed by the sprite
    + */
     PIXI.TilingSprite.prototype.setTexture = function(texture)
     {
    -	//TODO SET THE TEXTURES
    -	//TODO VISIBILITY
    -	
    -	// stop current texture 
    +	//TODO SET THE TEXTURES
    +	//TODO VISIBILITY
    +
    +	// stop current texture
     	this.texture = texture;
     	this.updateFrame = true;
     }
     
    +/**
    + * When the texture is updated, this event will fire to update the frame
    + *
    + * @method onTextureUpdate
    + * @param event
    + * @private
    + */
     PIXI.TilingSprite.prototype.onTextureUpdate = function(event)
     {
     	this.updateFrame = true;
    @@ -212,13 +275,13 @@ PIXI.TilingSprite.prototype.onTextureUpdate = function(event)
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_filters_AbstractFilter.js.html b/docs/files/src_pixi_filters_AbstractFilter.js.html new file mode 100644 index 0000000..df61c41 --- /dev/null +++ b/docs/files/src_pixi_filters_AbstractFilter.js.html @@ -0,0 +1,229 @@ + + + + + src/pixi/filters/AbstractFilter.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/filters/AbstractFilter.js

    + +
    +
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +
    +/**
    + * This is the base class for  creating a pixi.js filter. Currently only webGL supports filters.
    + * If you want to make a custom filter this should be your base class.
    + * @class AbstractFilter
    + * @constructor
    + * @param fragmentSrc
    + * @param unifroms  
    + */
    +PIXI.AbstractFilter = function(fragmentSrc, unifroms)
    +{
    +	/**
    +	* An array of passes - some filters contain a few steps this array simply stores the steps in a liniear fashion.
    +	* For example the blur filter has two passes blurX and blurY.
    +	* @property passes
    +	* @type Array an array of filter objects
    +	* @private
    +	*/
    +	this.passes = [this];
    +
    +
    +	this.dirty = true;
    +	this.padding = 0;
    +
    +	/**
    +	@property uniforms
    +	@private
    +	*/
    +	this.uniforms = unifroms || {};
    +	
    +	this.fragmentSrc = fragmentSrc || [];
    +}
    +
    +
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_filters_BlurFilter.js.html b/docs/files/src_pixi_filters_BlurFilter.js.html new file mode 100644 index 0000000..d0ce50e --- /dev/null +++ b/docs/files/src_pixi_filters_BlurFilter.js.html @@ -0,0 +1,262 @@ + + + + + src/pixi/filters/BlurFilter.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/filters/BlurFilter.js

    + +
    +
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +
    +/**
    + * 
    + * The BlurFilter applies a Gaussian blur to an object. 
    + * The strength of the blur can be set for x- and y-axis separately (always relative to the stage).
    + *
    + * @class BlurFilter
    + * @contructor
    + */
    +PIXI.BlurFilter = function()
    +{
    +    
    +	this.blurXFilter = new PIXI.BlurXFilter();
    +	this.blurYFilter = new PIXI.BlurYFilter();
    +
    +	this.passes =[this.blurXFilter, this.blurYFilter];
    +	
    +}
    +
    +/**
    + * Sets the strength of both the blurX and blurY properties simultaneously
    + *
    + * @property blur
    + * @type Number the strength of the blur
    + * @default 2
    + */
    +Object.defineProperty(PIXI.BlurFilter.prototype, 'blur', {
    +    get: function() {
    +        return this.blurX.blur;
    +    },
    +    set: function(value) {
    +  		this.blurXFilter.blur = this.blurYFilter.blur = value;
    +    }
    +});
    +
    +/**
    + * Sets the strength of the blurX property simultaneously
    + *
    + * @property blurX
    + * @type Number the strength of the blurX
    + * @default 2
    + */
    +Object.defineProperty(PIXI.BlurFilter.prototype, 'blurX', {
    +    get: function() {
    +        return this.blurXFilter.blur;
    +    },
    +    set: function(value) {
    +    	this.blurXFilter.blur = value;
    +    }
    +});
    +
    +/**
    + * Sets the strength of the blurX property simultaneously
    + *
    + * @property blurY
    + * @type Number the strength of the blurY
    + * @default 2
    + */
    +Object.defineProperty(PIXI.BlurFilter.prototype, 'blurY', {
    +    get: function() {
    +        return this.blurYFilter.blur;
    +    },
    +    set: function(value) {
    +    	this.blurYFilter.blur = value;
    +    }
    +});
    +
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_filters_BlurXFilter.js.html b/docs/files/src_pixi_filters_BlurXFilter.js.html new file mode 100644 index 0000000..52ea9a5 --- /dev/null +++ b/docs/files/src_pixi_filters_BlurXFilter.js.html @@ -0,0 +1,248 @@ + + + + + src/pixi/filters/BlurXFilter.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/filters/BlurXFilter.js

    + +
    +
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +
    +
    +PIXI.BlurXFilter = function()
    +{
    +	PIXI.AbstractFilter.call( this );
    +	
    +	this.passes = [this];
    +	
    +	// set the uniforms
    +	this.uniforms = {
    +		blur: {type: 'f', value: 1/512},
    +	};
    +	
    +	this.fragmentSrc = [
    +	  "precision mediump float;",
    +	  "varying vec2 vTextureCoord;",
    +	  "varying float vColor;",
    +	  "uniform float blur;",
    +	  "uniform sampler2D uSampler;",
    +	    "void main(void) {",
    +	  	"vec4 sum = vec4(0.0);",
    +
    +	  	"sum += texture2D(uSampler, vec2(vTextureCoord.x - 4.0*blur, vTextureCoord.y)) * 0.05;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x - 3.0*blur, vTextureCoord.y)) * 0.09;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x - 2.0*blur, vTextureCoord.y)) * 0.12;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x - blur, vTextureCoord.y)) * 0.15;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y)) * 0.16;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x + blur, vTextureCoord.y)) * 0.15;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x + 2.0*blur, vTextureCoord.y)) * 0.12;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x + 3.0*blur, vTextureCoord.y)) * 0.09;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x + 4.0*blur, vTextureCoord.y)) * 0.05;",
    +	 
    +		"gl_FragColor = sum;",
    +
    +	  "}"
    +	];
    +}
    +
    +PIXI.BlurXFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
    +PIXI.BlurXFilter.prototype.constructor = PIXI.BlurXFilter;
    +
    +
    +Object.defineProperty(PIXI.BlurXFilter.prototype, 'blur', {
    +    get: function() {
    +        return this.uniforms.blur.value / (1/7000);
    +    },
    +    set: function(value) {
    +    
    +    	this.dirty = true;
    +    	this.uniforms.blur.value = (1/7000) * value;
    +    }
    +});
    +
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_filters_BlurYFilter.js.html b/docs/files/src_pixi_filters_BlurYFilter.js.html new file mode 100644 index 0000000..3d09e8c --- /dev/null +++ b/docs/files/src_pixi_filters_BlurYFilter.js.html @@ -0,0 +1,246 @@ + + + + + src/pixi/filters/BlurYFilter.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/filters/BlurYFilter.js

    + +
    +
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +
    +
    +PIXI.BlurYFilter = function()
    +{
    +	PIXI.AbstractFilter.call( this );
    +	
    +	this.passes = [this];
    +	
    +	// set the uniforms
    +	this.uniforms = {
    +		blur: {type: 'f', value: 1/512},
    +	};
    +	
    +	this.fragmentSrc = [
    +	  "precision mediump float;",
    +	  "varying vec2 vTextureCoord;",
    +	  "varying float vColor;",
    +	  "uniform float blur;",
    +	  "uniform sampler2D uSampler;",
    +	    "void main(void) {",
    +	  	"vec4 sum = vec4(0.0);",
    +
    +	  	"sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y - 4.0*blur)) * 0.05;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y - 3.0*blur)) * 0.09;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y - 2.0*blur)) * 0.12;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y - blur)) * 0.15;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y)) * 0.16;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y + blur)) * 0.15;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y + 2.0*blur)) * 0.12;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y + 3.0*blur)) * 0.09;",
    +	    "sum += texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y + 4.0*blur)) * 0.05;",
    +	 
    +		"gl_FragColor = sum;",
    +
    +	  "}"
    +	];
    +}
    +
    +PIXI.BlurYFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
    +PIXI.BlurYFilter.prototype.constructor = PIXI.BlurYFilter;
    +
    +Object.defineProperty(PIXI.BlurYFilter.prototype, 'blur', {
    +    get: function() {
    +        return this.uniforms.blur.value / (1/7000);
    +    },
    +    set: function(value) {
    +    	//this.padding = value;
    +    	this.uniforms.blur.value = (1/7000) * value;
    +    }
    +});
    +
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_filters_ColorMatrixFilter.js.html b/docs/files/src_pixi_filters_ColorMatrixFilter.js.html new file mode 100644 index 0000000..8156285 --- /dev/null +++ b/docs/files/src_pixi_filters_ColorMatrixFilter.js.html @@ -0,0 +1,250 @@ + + + + + src/pixi/filters/ColorMatrixFilter.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/filters/ColorMatrixFilter.js

    + +
    +
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +/**
    + * 
    + * The ColorMatrixFilter class lets you apply a 4x4 matrix transformation on the RGBA 
    + * color and alpha values of every pixel on your displayObject to produce a result 
    + * with a new set of RGBA color and alpha values. Its pretty powerful!
    + * @class ColorMatrixFilter
    + * @contructor
    + */
    +PIXI.ColorMatrixFilter = function()
    +{
    +	PIXI.AbstractFilter.call( this );
    +	
    +	this.passes = [this];
    +	
    +	// set the uniforms
    +	this.uniforms = {
    +		matrix: {type: 'mat4', value: [1,0,0,0,
    +									   0,1,0,0,
    +									   0,0,1,0,
    +									   0,0,0,1]},
    +	};
    +	
    +	this.fragmentSrc = [
    +	  "precision mediump float;",
    +	  "varying vec2 vTextureCoord;",
    +	  "varying float vColor;",
    +	  "uniform float invert;",
    +	  "uniform mat4 matrix;",
    +	  "uniform sampler2D uSampler;",
    +	  "void main(void) {",
    +	    "gl_FragColor = texture2D(uSampler, vTextureCoord) * matrix;",
    +	    "gl_FragColor = gl_FragColor * vColor;",
    +	  "}"
    +	];
    +	
    +}
    +
    +PIXI.ColorMatrixFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
    +PIXI.ColorMatrixFilter.prototype.constructor = PIXI.ColorMatrixFilter;
    +
    +/**
    + * Sets the matrix of the color matrix filter
    + *
    + * @property matrix
    + * @type Array and array of 26 numbers
    + * @default [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]
    + */
    +Object.defineProperty(PIXI.ColorMatrixFilter.prototype, 'matrix', {
    +    get: function() {
    +        return this.uniforms.matrix.value;
    +    },
    +    set: function(value) {
    +    	this.uniforms.matrix.value = value;
    +    }
    +});
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_filters_DisplacementFilter.js.html b/docs/files/src_pixi_filters_DisplacementFilter.js.html new file mode 100644 index 0000000..91d269c --- /dev/null +++ b/docs/files/src_pixi_filters_DisplacementFilter.js.html @@ -0,0 +1,326 @@ + + + + + src/pixi/filters/DisplacementFilter.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/filters/DisplacementFilter.js

    + +
    +
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +
    +/**
    + * 
    + * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. 
    + * You can use this filter to apply all manor of crazy warping effects
    + * Currently the r property of the texture is used offset the x and the g propery of the texture is used to offset the y.
    + * @class DisplacementFilter
    + * @contructor
    + * @param texture {Texture} The texture used for the displacemtent map * must be power of 2 texture at the moment
    + */
    +PIXI.DisplacementFilter = function(texture)
    +{
    +	PIXI.AbstractFilter.call( this );
    +	
    +	this.passes = [this];
    +	texture.baseTexture._powerOf2 = true;
    +
    +	// set the uniforms
    +	//console.log()
    +	this.uniforms = {
    +		displacementMap: {type: 'sampler2D', value:texture},
    +		scale:			 {type: 'f2', value:{x:30, y:30}},
    +		offset:			 {type: 'f2', value:{x:0, y:0}},
    +		mapDimensions:   {type: 'f2', value:{x:1, y:5112}},
    +		dimensions:   {type: 'f4', value:[0,0,0,0]}
    +	};
    +	
    +
    +	if(texture.baseTexture.hasLoaded)
    +	{
    +		this.uniforms.mapDimensions.value.x = texture.width;
    +		this.uniforms.mapDimensions.value.y = texture.height;
    +	}
    +	else
    +	{
    +		this.boundLoadedFunction = this.onTextureLoaded.bind(this);
    +
    +		texture.baseTexture.on("loaded", this.boundLoadedFunction);
    +	}
    +
    +	this.fragmentSrc = [
    +	  "precision mediump float;",
    +	  "varying vec2 vTextureCoord;",
    +	  "varying float vColor;",
    +	  "uniform sampler2D displacementMap;",
    +	  "uniform sampler2D uSampler;",
    +	  "uniform vec2 scale;",
    +	  "uniform vec2 offset;",
    +	  "uniform vec4 dimensions;",
    +	  "uniform vec2 mapDimensions;",// = vec2(256.0, 256.0);",
    +	 // "const vec2 textureDimensions = vec2(750.0, 750.0);",
    +	  
    +	  "void main(void) {",
    +	  	"vec2 mapCords = vTextureCoord.xy;",
    +//	  	"mapCords -= ;",
    +	 	"mapCords += (dimensions.zw + offset)/ dimensions.xy ;",
    +	 	"mapCords.y *= -1.0;",
    +	 	"mapCords.y += 1.0;",
    +	  	"vec2 matSample = texture2D(displacementMap, mapCords).xy;",
    +		"matSample -= 0.5;",	  
    +	 	"matSample *= scale;",
    +	 	"matSample /= mapDimensions;",
    +	    "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x + matSample.x, vTextureCoord.y + matSample.y));",
    +		"gl_FragColor.rgb = mix( gl_FragColor.rgb, gl_FragColor.rgb, 1.0);",
    +		"vec2 cord = vTextureCoord;",
    +		
    +		//"gl_FragColor =  texture2D(displacementMap, cord);",
    +	    "gl_FragColor = gl_FragColor * vColor;",
    +	    
    +	  "}"
    +	];
    +	
    +}
    +
    +PIXI.DisplacementFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
    +PIXI.DisplacementFilter.prototype.constructor = PIXI.DisplacementFilter;
    +
    +PIXI.DisplacementFilter.prototype.onTextureLoaded = function()
    +{
    +	
    +	this.uniforms.mapDimensions.value.x = this.uniforms.displacementMap.value.width;
    +	this.uniforms.mapDimensions.value.y = this.uniforms.displacementMap.value.height;
    +
    +	this.uniforms.displacementMap.value.baseTexture.off("loaded", this.boundLoadedFunction)
    +
    +}
    +
    +/**
    + * The texture used for the displacemtent map * must be power of 2 texture at the moment
    + *
    + * @property map
    + * @type Texture
    + */
    +Object.defineProperty(PIXI.DisplacementFilter.prototype, 'map', {
    +    get: function() {
    +        return this.uniforms.displacementMap.value;
    +    },
    +    set: function(value) {
    +    	this.uniforms.displacementMap.value = value;
    +    }
    +});
    +
    +/**
    + * The multiplier used to scale the displacement result from the map calculation.
    + *
    + * @property scale
    + * @type Point
    + */
    +Object.defineProperty(PIXI.DisplacementFilter.prototype, 'scale', {
    +    get: function() {
    +        return this.uniforms.scale.value;
    +    },
    +    set: function(value) {
    +    	this.uniforms.scale.value = value;
    +    }
    +});
    +
    +/**
    + * The offset used to move the displacement map.
    + *
    + * @property offset
    + * @type Point
    + */
    +Object.defineProperty(PIXI.DisplacementFilter.prototype, 'offset', {
    +    get: function() {
    +        return this.uniforms.offset.value;
    +    },
    +    set: function(value) {
    +    	this.uniforms.offset.value = value;
    +    }
    +});
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_filters_FilterBlock.js.html b/docs/files/src_pixi_filters_FilterBlock.js.html index 080a44f..3491921 100644 --- a/docs/files/src_pixi_filters_FilterBlock.js.html +++ b/docs/files/src_pixi_filters_FilterBlock.js.html @@ -2,12 +2,12 @@ - src/pixi/filters/FilterBlock.js - Pixi.JS - - - - - + src/pixi/filters/FilterBlock.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,24 +166,21 @@
    -

    File: src/pixi/filters/FilterBlock.js

    +

    File: src/pixi/filters/FilterBlock.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
     
     
    -PIXI.FilterBlock = function(mask)
    +PIXI.FilterBlock = function()
     {
    -	this.graphics = mask
     	this.visible = true;
     	this.renderable = true;
     }
    -
    -
         
    @@ -169,13 +190,13 @@ PIXI.FilterBlock = function(mask)
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_filters_GreyFilter.js.html b/docs/files/src_pixi_filters_GreyFilter.js.html new file mode 100644 index 0000000..45eae1e --- /dev/null +++ b/docs/files/src_pixi_filters_GreyFilter.js.html @@ -0,0 +1,243 @@ + + + + + src/pixi/filters/GreyFilter.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/filters/GreyFilter.js

    + +
    +
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +
    +/**
    + * 
    + * This turns your displayObjects to black and white.
    + * @class GreyFilter
    + * @contructor
    + */
    +PIXI.GreyFilter = function()
    +{
    +	PIXI.AbstractFilter.call( this );
    +	
    +	this.passes = [this];
    +	
    +	// set the uniforms
    +	this.uniforms = {
    +		grey: {type: 'f', value: 1},
    +	};
    +	
    +	this.fragmentSrc = [
    +	  "precision mediump float;",
    +	  "varying vec2 vTextureCoord;",
    +	  "varying float vColor;",
    +	  "uniform sampler2D uSampler;",
    +	  "uniform float grey;",
    +	  "void main(void) {",
    +	    "gl_FragColor = texture2D(uSampler, vTextureCoord);",
    +		"gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(0.2126*gl_FragColor.r + 0.7152*gl_FragColor.g + 0.0722*gl_FragColor.b), grey);",
    +	    "gl_FragColor = gl_FragColor * vColor;",
    +	  "}"
    +	];
    +}
    +
    +PIXI.GreyFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
    +PIXI.GreyFilter.prototype.constructor = PIXI.GreyFilter;
    +
    +/**
    +The strength of the grey. 1 will make the object black and white, 0 will make the object its normal color
    +@property grey
    +*/
    +Object.defineProperty(PIXI.GreyFilter.prototype, 'grey', {
    +    get: function() {
    +        return this.uniforms.grey.value;
    +    },
    +    set: function(value) {
    +    	this.uniforms.grey.value = value;
    +    }
    +});
    +
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_filters_InvertFilter.js.html b/docs/files/src_pixi_filters_InvertFilter.js.html new file mode 100644 index 0000000..a9b6382 --- /dev/null +++ b/docs/files/src_pixi_filters_InvertFilter.js.html @@ -0,0 +1,243 @@ + + + + + src/pixi/filters/InvertFilter.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/filters/InvertFilter.js

    + +
    +
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +/**
    + * 
    + * This inverts your displayObjects colors.
    + * @class InvertFilter
    + * @contructor
    + */
    +PIXI.InvertFilter = function()
    +{
    +	PIXI.AbstractFilter.call( this );
    +	
    +	this.passes = [this];
    +	
    +	// set the uniforms
    +	this.uniforms = {
    +		invert: {type: 'f', value: 0},
    +	};
    +	
    +	this.fragmentSrc = [
    +	  "precision mediump float;",
    +	  "varying vec2 vTextureCoord;",
    +	  "varying float vColor;",
    +	  "uniform float invert;",
    +	  "uniform sampler2D uSampler;",
    +	  "void main(void) {",
    +	    "gl_FragColor = texture2D(uSampler, vTextureCoord);",
    +		"gl_FragColor.rgb = mix( (vec3(1)-gl_FragColor.rgb) * gl_FragColor.a, gl_FragColor.rgb, invert);",
    +		//"gl_FragColor.rgb = gl_FragColor.rgb  * gl_FragColor.a;",
    +	    "gl_FragColor = gl_FragColor * vColor;",
    +	  "}"
    +	];
    +	
    +}
    +
    +PIXI.InvertFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
    +PIXI.InvertFilter.prototype.constructor = PIXI.InvertFilter;
    +
    +/**
    +The strength of the invert. 1 will fully invert the colors, 0 will make the object its normal color
    +@property invert
    +*/
    +Object.defineProperty(PIXI.InvertFilter.prototype, 'invert', {
    +    get: function() {
    +        return this.uniforms.invert.value;
    +    },
    +    set: function(value) {
    +    	this.uniforms.invert.value = value;
    +    }
    +});
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_filters_MaskFilter.js.html b/docs/files/src_pixi_filters_MaskFilter.js.html deleted file mode 100644 index 0df8008..0000000 --- a/docs/files/src_pixi_filters_MaskFilter.js.html +++ /dev/null @@ -1,180 +0,0 @@ - - - - - src/pixi/filters/MaskFilter.js - Pixi.JS - - - - - - - - -
    -
    -
    - -

    - -
    -
    - API Docs for: 1.3.0 -
    -
    -
    - - -
    -
    - Show: - - - - - - - -
    - - -
    -
    -
    -

    File: src/pixi/filters/MaskFilter.js

    - -
    -
    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    -
    -
    -
    -PIXI.MaskFilter = function(graphics)
    -{
    -	// the graphics data that will be used for filtering
    -	this.graphics;
    -}
    -
    -
    -    
    -
    - -
    -
    -
    -
    -
    -
    - - - - - - - - - - diff --git a/docs/files/src_pixi_filters_PixelateFilter.js.html b/docs/files/src_pixi_filters_PixelateFilter.js.html new file mode 100644 index 0000000..84a51c4 --- /dev/null +++ b/docs/files/src_pixi_filters_PixelateFilter.js.html @@ -0,0 +1,255 @@ + + + + + src/pixi/filters/PixelateFilter.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/filters/PixelateFilter.js

    + +
    +
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +/**
    + * 
    + * This filter applies a pixlate effect making display objects appear "blocky"
    + * @class PixelateFilter
    + * @contructor
    + */
    +PIXI.PixelateFilter = function()
    +{
    +	PIXI.AbstractFilter.call( this );
    +
    +	this.passes = [this];
    +	
    +	// set the uniforms
    +	this.uniforms = {
    +		invert: {type: 'f', value: 0},
    +		dimensions: {type: 'f4', value:new Float32Array([10000, 100, 10, 10])},
    +		pixelSize: {type: 'f2', value:{x:10, y:10}},
    +	};
    +
    +	this.fragmentSrc = [
    +	  "precision mediump float;",
    +	  "varying vec2 vTextureCoord;",
    +	  "varying float vColor;",
    +	  "uniform vec2 testDim;",
    +	  "uniform vec4 dimensions;",
    +	  "uniform vec2 pixelSize;",
    +	  "uniform sampler2D uSampler;",
    +	  "void main(void) {",
    +	 	"vec2 coord = vTextureCoord;",
    +
    +	 //	"vec2 dim = testDim;",
    +	 	"vec2 size = dimensions.xy/pixelSize;",
    +
    +	 	"vec2 color = floor( ( vTextureCoord * size ) ) / size + pixelSize/dimensions.xy * 0.5;",
    +	// 	"color += (mod(dimensions.xy, size)/dimensions.zw;",
    +	    "gl_FragColor = texture2D(uSampler, color);",
    +	  "}"
    +	];
    +	
    +
    +}
    +
    +PIXI.PixelateFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
    +PIXI.PixelateFilter.prototype.constructor = PIXI.PixelateFilter;
    +
    +/**
    + * 
    + * This a point that describes the size of the blocs. x is the width of the block and y is the the height
    + * @property size
    + * @type Point
    + */
    +Object.defineProperty(PIXI.PixelateFilter.prototype, 'size', {
    +    get: function() {
    +        return this.uniforms.pixelSize.value;
    +    },
    +    set: function(value) {
    +    	this.dirty = true;
    +    	this.uniforms.pixelSize.value = value;
    +    }
    +});
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_filters_SepiaFilter.js.html b/docs/files/src_pixi_filters_SepiaFilter.js.html new file mode 100644 index 0000000..3571a8c --- /dev/null +++ b/docs/files/src_pixi_filters_SepiaFilter.js.html @@ -0,0 +1,247 @@ + + + + + src/pixi/filters/SepiaFilter.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/filters/SepiaFilter.js

    + +
    +
    +/**
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +
    +/**
    + * 
    + * This applies a sepia effect to your displayObjects.
    + * @class SepiaFilter
    + * @contructor
    + */
    +PIXI.SepiaFilter = function()
    +{
    +	PIXI.AbstractFilter.call( this );
    +	
    +	this.passes = [this];
    +	
    +	// set the uniforms
    +	this.uniforms = {
    +		sepia: {type: 'f', value: 1},
    +	};
    +	
    +	this.fragmentSrc = [
    +	  "precision mediump float;",
    +	  "varying vec2 vTextureCoord;",
    +	  "varying float vColor;",
    +	  "uniform float sepia;",
    +	  "uniform sampler2D uSampler;",
    +	 	   
    +	  "const mat3 sepiaMatrix = mat3(0.3588, 0.7044, 0.1368, 0.2990, 0.5870, 0.1140, 0.2392, 0.4696, 0.0912);",
    +	  "void main(void) {",
    +	    "gl_FragColor = texture2D(uSampler, vTextureCoord);",
    +		"gl_FragColor.rgb = mix( gl_FragColor.rgb, gl_FragColor.rgb * sepiaMatrix, sepia);",
    +	    "gl_FragColor = gl_FragColor * vColor;",
    +	  "}"
    +	];
    +	
    +}
    +
    +PIXI.SepiaFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
    +PIXI.SepiaFilter.prototype.constructor = PIXI.SepiaFilter;
    +
    +/**
    +The strength of the sepia. 1 will apply the full sepia effect, 0 will make the object its normal color
    +@property sepia
    +*/
    +Object.defineProperty(PIXI.SepiaFilter.prototype, 'sepia', {
    +    get: function() {
    +        return this.uniforms.sepia.value;
    +    },
    +    set: function(value) {
    +    	this.uniforms.sepia.value = value;
    +    }
    +});
    +
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_filters_SmartBlurFilter.js.html b/docs/files/src_pixi_filters_SmartBlurFilter.js.html new file mode 100644 index 0000000..80af498 --- /dev/null +++ b/docs/files/src_pixi_filters_SmartBlurFilter.js.html @@ -0,0 +1,256 @@ + + + + + src/pixi/filters/SmartBlurFilter.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/filters/SmartBlurFilter.js

    + +
    +
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +
    +
    +PIXI.SmartBlurFilter = function()
    +{
    +	PIXI.AbstractFilter.call( this );
    +	
    +	this.passes = [this];
    +	
    +	// set the uniforms
    +	this.uniforms = {
    +		blur: {type: 'f', value: 1/512},
    +	};
    +	
    +	this.fragmentSrc = [
    +	  "precision mediump float;",
    + 	  "varying vec2 vTextureCoord;",
    +  	  "uniform sampler2D uSampler;",
    +    //  "uniform vec2 delta;",
    +      "const vec2 delta = vec2(1.0/10.0, 0.0);",
    +     // "uniform float darkness;",
    +	  
    +	  "float random(vec3 scale, float seed) {",
    +	        "return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);",
    +	   "}",
    +	   
    +	   
    +	  "void main(void) {",
    +	 
    +	  "vec4 color = vec4(0.0);",
    +	  "float total = 0.0;",
    +	  
    +	  "float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);",
    +	            
    +	  "for (float t = -30.0; t <= 30.0; t++) {",
    +	           "float percent = (t + offset - 0.5) / 30.0;",
    +	                "float weight = 1.0 - abs(percent);",
    +	                "vec4 sample = texture2D(uSampler, vTextureCoord + delta * percent);",
    +	                "sample.rgb *= sample.a;",
    +	                "color += sample * weight;",
    +	                "total += weight;",
    +	            "}",
    +	            
    +	            "gl_FragColor = color / total;",
    +	            "gl_FragColor.rgb /= gl_FragColor.a + 0.00001;",
    +	          //  "gl_FragColor.rgb *= darkness;",
    +	  "}"
    +	];
    +}
    +
    +PIXI.SmartBlurFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
    +PIXI.SmartBlurFilter.prototype.constructor = PIXI.SmartBlurFilter;
    +
    +Object.defineProperty(PIXI.SmartBlurFilter.prototype, 'blur', {
    +    get: function() {
    +        return this.uniforms.blur.value;
    +    },
    +    set: function(value) {
    +    	this.uniforms.blur.value = value;
    +    }
    +});
    +
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_loaders_AssetLoader.js.html b/docs/files/src_pixi_loaders_AssetLoader.js.html index a752143..c7cbe8c 100644 --- a/docs/files/src_pixi_loaders_AssetLoader.js.html +++ b/docs/files/src_pixi_loaders_AssetLoader.js.html @@ -2,12 +2,12 @@ - src/pixi/loaders/AssetLoader.js - Pixi.JS - - - - - + src/pixi/loaders/AssetLoader.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,36 +166,56 @@
    -

    File: src/pixi/loaders/AssetLoader.js

    +

    File: src/pixi/loaders/AssetLoader.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -/**
    - * A Class that loads a bunch of images / sprite sheet / bitmap font files. Once the assets have been loaded they are added to the PIXI Texture cache and can be accessed easily through PIXI.Texture.fromImage() and PIXI.Sprite.fromImage()
    +/**
    + * A Class that loads a bunch of images / sprite sheet / bitmap font files. Once the
    + * assets have been loaded they are added to the PIXI Texture cache and can be accessed
    + * easily through PIXI.Texture.fromImage() and PIXI.Sprite.fromImage()
      * When all items have been loaded this class will dispatch a "onLoaded" event
      * As each individual item is loaded this class will dispatch a "onProgress" event
    + *
      * @class AssetLoader
      * @constructor
    - * @extends EventTarget
    - * @param {Array} assetURLs an array of image/sprite sheet urls that you would like loaded supported. Supported image formats include "jpeg", "jpg", "png", "gif". Supported sprite sheet data formats only include "JSON" at this time. Supported bitmap font data formats include "xml" and "fnt".
    - */
    -PIXI.AssetLoader = function(assetURLs)
    + * @uses EventTarget
    + * @param {Array<String>} assetURLs an array of image/sprite sheet urls that you would like loaded
    + *      supported. Supported image formats include "jpeg", "jpg", "png", "gif". Supported
    + *      sprite sheet data formats only include "JSON" at this time. Supported bitmap font
    + *      data formats include "xml" and "fnt".
    + * @param crossorigin {Boolean} Whether requests should be treated as crossorigin
    + */
    +PIXI.AssetLoader = function(assetURLs, crossorigin)
     {
     	PIXI.EventTarget.call(this);
    -	
    -	/**
    +
    +	/**
     	 * The array of asset URLs that are going to be loaded
    +     *
     	 * @property assetURLs
    -	 * @type Array
    -	 */
    +	 * @type Array<String>
    +	 */
     	this.assetURLs = assetURLs;
     
    -	this.crossorigin = false;
    +    /**
    +     * Whether the requests should be treated as cross origin
    +     *
    +     * @property crossorigin
    +     * @type Boolean
    +     */
    +	this.crossorigin = crossorigin;
     
    +    /**
    +     * Maps file extension to loader types
    +     *
    +     * @property loadersByType
    +     * @type Object
    +     */
         this.loadersByType = {
             "jpg":  PIXI.ImageLoader,
             "jpeg": PIXI.ImageLoader,
    @@ -182,26 +226,28 @@ PIXI.AssetLoader = function(assetURLs)
             "xml":  PIXI.BitmapFontLoader,
             "fnt":  PIXI.BitmapFontLoader
         };
    -    
    -    
    +
    +
     };
     
    -/**
    -Fired when an item has loaded
    -@event onProgress
    -**/
    +/**
    + * Fired when an item has loaded
    + * @event onProgress
    + */
     
    -/**
    -Fired when all the assets have loaded
    -@event onComplete 
    -**/
    +/**
    + * Fired when all the assets have loaded
    + * @event onComplete
    + */
     
    -// constructor
    -PIXI.AssetLoader.constructor = PIXI.AssetLoader;
    +// constructor
    +PIXI.AssetLoader.prototype.constructor = PIXI.AssetLoader;
     
    -/**
    - * This will begin loading the assets sequentially
    - */
    +/**
    + * Starts loading the assets sequentially
    + *
    + * @method load
    + */
     PIXI.AssetLoader.prototype.load = function()
     {
         var scope = this;
    @@ -227,16 +273,18 @@ PIXI.AssetLoader.prototype.load = function()
     	}
     };
     
    -/**
    +/**
      * Invoked after each file is loaded
    + *
    + * @method onAssetLoaded
      * @private
    - */
    + */
     PIXI.AssetLoader.prototype.onAssetLoaded = function()
     {
         this.loadCount--;
     	this.dispatchEvent({type: "onProgress", content: this});
     	if(this.onProgress) this.onProgress();
    -	
    +
     	if(this.loadCount == 0)
     	{
     		this.dispatchEvent({type: "onComplete", content: this});
    @@ -254,13 +302,13 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_loaders_BitmapFontLoader.js.html b/docs/files/src_pixi_loaders_BitmapFontLoader.js.html index 0bc6eef..5e9e825 100644 --- a/docs/files/src_pixi_loaders_BitmapFontLoader.js.html +++ b/docs/files/src_pixi_loaders_BitmapFontLoader.js.html @@ -2,12 +2,12 @@ - src/pixi/loaders/BitmapFontLoader.js - Pixi.JS - - - - - + src/pixi/loaders/BitmapFontLoader.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,46 +166,77 @@
    -

    File: src/pixi/loaders/BitmapFontLoader.js

    +

    File: src/pixi/loaders/BitmapFontLoader.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -/**
    +/**
      * The xml loader is used to load in XML bitmap font data ("xml" or "fnt")
    - * To generate the data you can use http://www.angelcode.com/products/bmfont/
    + * To generate the data you can use http://www.angelcode.com/products/bmfont/
      * This loader will also load the image file as the data.
      * When loaded this class will dispatch a "loaded" event
    + *
      * @class BitmapFontLoader
    - * @extends EventTarget
    + * @uses EventTarget
      * @constructor
    - * @param {String} url the url of the sprite sheet JSON file
    - * @param {Boolean} crossorigin
    - */
    -
    + * @param url {String} The url of the sprite sheet JSON file
    + * @param crossorigin {Boolean} Whether requests should be treated as crossorigin
    + */
     PIXI.BitmapFontLoader = function(url, crossorigin)
     {
    -    /*
    +    /*
          * i use texture packer to load the assets..
    -     * http://www.codeandweb.com/texturepacker
    +     * http://www.codeandweb.com/texturepacker
          * make sure to set the format as "JSON"
    -     */
    +     */
         PIXI.EventTarget.call(this);
    +
    +    /**
    +     * The url of the bitmap font data
    +     *
    +     * @property url
    +     * @type String
    +     */
         this.url = url;
    -    this.baseUrl = url.replace(/[^\/]*$/, "");
    -    this.texture = null;
    +
    +    /**
    +     * Whether the requests should be treated as cross origin
    +     *
    +     * @property crossorigin
    +     * @type Boolean
    +     */
         this.crossorigin = crossorigin;
    +
    +    /**
    +     * [read-only] The base url of the bitmap font data
    +     *
    +     * @property baseUrl
    +     * @type String
    +     * @readOnly
    +     */
    +    this.baseUrl = url.replace(/[^\/]*$/, "");
    +
    +    /**
    +     * [read-only] The texture of the bitmap font
    +     *
    +     * @property baseUrl
    +     * @type String
    +     */
    +    this.texture = null;
     };
     
    -// constructor
    -PIXI.BitmapFontLoader.constructor = PIXI.BitmapFontLoader;
    +// constructor
    +PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader;
     
    -/**
    - * This will begin loading the JSON file
    - */
    +/**
    + * Loads the XML font data
    + *
    + * @method load
    + */
     PIXI.BitmapFontLoader.prototype.load = function()
     {
         this.ajaxRequest = new XMLHttpRequest();
    @@ -192,14 +247,16 @@ PIXI.BitmapFontLoader.prototype.load = function()
         };
     
         this.ajaxRequest.open("GET", this.url, true);
    -    if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/xml");
    +    if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/xml");
         this.ajaxRequest.send(null)
     };
     
    -/**
    - * Invoked when XML file is loaded
    +/**
    + * Invoked when XML file is loaded, parses the data
    + *
    + * @method onXMLLoaded
      * @private
    - */
    + */
     PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
     {
         if (this.ajaxRequest.readyState == 4)
    @@ -218,32 +275,31 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
                 data.lineHeight = parseInt(common.attributes.getNamedItem("lineHeight").nodeValue, 10);
                 data.chars = {};
     
    -            //parse letters
    +            //parse letters
                 var letters = this.ajaxRequest.responseXML.getElementsByTagName("char");
     
                 for (var i = 0; i < letters.length; i++)
                 {
                     var charCode = parseInt(letters[i].attributes.getNamedItem("id").nodeValue, 10);
     
    -                var textureRect = {
    -                    x: parseInt(letters[i].attributes.getNamedItem("x").nodeValue, 10),
    -                    y: parseInt(letters[i].attributes.getNamedItem("y").nodeValue, 10),
    -                    width: parseInt(letters[i].attributes.getNamedItem("width").nodeValue, 10),
    -                    height: parseInt(letters[i].attributes.getNamedItem("height").nodeValue, 10)
    -                };
    -                PIXI.TextureCache[charCode] = new PIXI.Texture(this.texture, textureRect);
    +                var textureRect = new PIXI.Rectangle(
    +                    parseInt(letters[i].attributes.getNamedItem("x").nodeValue, 10),
    +                    parseInt(letters[i].attributes.getNamedItem("y").nodeValue, 10),
    +                    parseInt(letters[i].attributes.getNamedItem("width").nodeValue, 10),
    +                    parseInt(letters[i].attributes.getNamedItem("height").nodeValue, 10)
    +                );
     
                     data.chars[charCode] = {
                         xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
                         yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
                         xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
                         kerning: {},
    -                    texture:new PIXI.Texture(this.texture, textureRect)
    +                    texture: PIXI.TextureCache[charCode] = new PIXI.Texture(this.texture, textureRect)
     
                     };
                 }
     
    -            //parse kernings
    +            //parse kernings
                 var kernings = this.ajaxRequest.responseXML.getElementsByTagName("kerning");
                 for (i = 0; i < kernings.length; i++)
                 {
    @@ -266,10 +322,12 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
         }
     };
     
    -/**
    - * Invoked when all files are loaded (xml/fnt and texture)
    +/**
    + * Invoked when all files are loaded (xml/fnt and texture)
    + *
    + * @method onLoaded
      * @private
    - */
    + */
     PIXI.BitmapFontLoader.prototype.onLoaded = function()
     {
         this.dispatchEvent({type: "loaded", content: this});
    @@ -284,13 +342,13 @@ PIXI.BitmapFontLoader.prototype.onLoaded = function()
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_loaders_ImageLoader.js.html b/docs/files/src_pixi_loaders_ImageLoader.js.html index 5a0c7d4..d7744fc 100644 --- a/docs/files/src_pixi_loaders_ImageLoader.js.html +++ b/docs/files/src_pixi_loaders_ImageLoader.js.html @@ -2,12 +2,12 @@ - src/pixi/loaders/ImageLoader.js - Pixi.JS - - - - - + src/pixi/loaders/ImageLoader.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,36 +166,53 @@
    -

    File: src/pixi/loaders/ImageLoader.js

    +

    File: src/pixi/loaders/ImageLoader.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -/**
    +/**
      * The image loader class is responsible for loading images file formats ("jpeg", "jpg", "png" and "gif")
      * Once the image has been loaded it is stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId()
      * When loaded this class will dispatch a 'loaded' event
    + *
      * @class ImageLoader
    - * @extends EventTarget
    + * @uses EventTarget
      * @constructor
    - * @param {String} url The url of the image
    - * @param {Boolean} crossorigin
    - */
    + * @param url {String} The url of the image
    + * @param crossorigin {Boolean} Whether requests should be treated as crossorigin
    + */
     PIXI.ImageLoader = function(url, crossorigin)
     {
         PIXI.EventTarget.call(this);
    +
    +    /**
    +     * The texture being loaded
    +     *
    +     * @property texture
    +     * @type Texture
    +     */
         this.texture = PIXI.Texture.fromImage(url, crossorigin);
    +
    +    /**
    +     * if the image is loaded with loadFramedSpriteSheet
    +     * frames will contain the sprite sheet frames
    +     *
    +     */
    +    this.frames = [];
     };
     
    -// constructor
    -PIXI.ImageLoader.constructor = PIXI.ImageLoader;
    +// constructor
    +PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader;
     
    -/**
    +/**
      * Loads image or takes it from cache
    - */
    + *
    + * @method load
    + */
     PIXI.ImageLoader.prototype.load = function()
     {
         if(!this.texture.baseTexture.hasLoaded)
    @@ -188,15 +229,61 @@ PIXI.ImageLoader.prototype.load = function()
         }
     };
     
    -/**
    +/**
      * Invoked when image file is loaded or it is already cached and ready to use
    + *
    + * @method onLoaded
      * @private
    - */
    + */
     PIXI.ImageLoader.prototype.onLoaded = function()
     {
         this.dispatchEvent({type: "loaded", content: this});
     };
     
    +/**
    + * Loads image and split it to uniform sized frames
    + *
    + *
    + * @method loadFramedSpriteSheet
    + * @param frameWidth {Number} with of each frame
    + * @param frameHeight {Number} height of each frame
    + * @param textureName {String} if given, the frames will be cached in <textureName>-<ord> format 
    + */
    +PIXI.ImageLoader.prototype.loadFramedSpriteSheet = function(frameWidth, frameHeight, textureName)
    +{
    +    this.frames = [];
    +    var cols = Math.floor(this.texture.width / frameWidth);
    +    var rows = Math.floor(this.texture.height / frameHeight);
    +
    +    var i=0;
    +    for (var y=0; y<rows; y++)
    +    {
    +        for (var x=0; x<cols; x++,i++)
    +        {
    +            var texture = new PIXI.Texture(this.texture, {
    +                x: x*frameWidth,
    +                y: y*frameHeight,
    +                width: frameWidth,
    +                height: frameHeight
    +            });
    +
    +            this.frames.push(texture);
    +            if (textureName) PIXI.TextureCache[textureName+'-'+i] = texture;
    +        }
    +    }
    +
    +    if(!this.texture.baseTexture.hasLoaded)
    +    {
    +        var scope = this;
    +        this.texture.baseTexture.addEventListener("loaded", function() {
    +            scope.onLoaded();
    +        });
    +    }
    +    else
    +    {
    +        this.onLoaded();
    +    }
    +};
         
    @@ -206,13 +293,13 @@ PIXI.ImageLoader.prototype.onLoaded = function()
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_loaders_JsonLoader.js.html b/docs/files/src_pixi_loaders_JsonLoader.js.html index 8e91182..292eab2 100644 --- a/docs/files/src_pixi_loaders_JsonLoader.js.html +++ b/docs/files/src_pixi_loaders_JsonLoader.js.html @@ -2,12 +2,12 @@ - src/pixi/loaders/JsonLoader.js - Pixi.JS - - - - - + src/pixi/loaders/JsonLoader.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,40 +166,72 @@
    -

    File: src/pixi/loaders/JsonLoader.js

    +

    File: src/pixi/loaders/JsonLoader.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -/**
    +/**
      * The json file loader is used to load in JSON data and parsing it
      * When loaded this class will dispatch a "loaded" event
      * If load failed this class will dispatch a "error" event
    + *
      * @class JsonLoader
    - * @extends EventTarget
    + * @uses EventTarget
      * @constructor
    - * @param {String} url the url of the JSON file
    - * @param {Boolean} crossorigin
    - */
    -
    + * @param url {String} The url of the JSON file
    + * @param crossorigin {Boolean} Whether requests should be treated as crossorigin
    + */
     PIXI.JsonLoader = function (url, crossorigin) {
     	PIXI.EventTarget.call(this);
    +
    +	/**
    +	 * The url of the bitmap font data
    +	 *
    +	 * @property url
    +	 * @type String
    +	 */
     	this.url = url;
    -	this.baseUrl = url.replace(/[^\/]*$/, "");
    +
    +	/**
    +	 * Whether the requests should be treated as cross origin
    +	 *
    +	 * @property crossorigin
    +	 * @type Boolean
    +	 */
     	this.crossorigin = crossorigin;
    +
    +	/**
    +	 * [read-only] The base url of the bitmap font data
    +	 *
    +	 * @property baseUrl
    +	 * @type String
    +	 * @readOnly
    +	 */
    +	this.baseUrl = url.replace(/[^\/]*$/, "");
    +
    +	/**
    +	 * [read-only] Whether the data has loaded yet
    +	 *
    +	 * @property loaded
    +	 * @type Boolean
    +	 * @readOnly
    +	 */
     	this.loaded = false;
    -	
    +
     };
     
    -// constructor
    -PIXI.JsonLoader.constructor = PIXI.JsonLoader;
    +// constructor
    +PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader;
     
    -/**
    - * This will begin loading the JSON file
    - */
    +/**
    + * Loads the JSON data
    + *
    + * @method load
    + */
     PIXI.JsonLoader.prototype.load = function () {
     	this.ajaxRequest = new AjaxRequest();
     	var scope = this;
    @@ -184,32 +240,34 @@ PIXI.JsonLoader.prototype.load = function () {
     	};
     
     	this.ajaxRequest.open("GET", this.url, true);
    -	if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
    +	if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
     	this.ajaxRequest.send(null);
     };
     
    -/**
    +/**
      * Invoke when JSON file is loaded
    + *
    + * @method onJSONLoaded
      * @private
    - */
    + */
     PIXI.JsonLoader.prototype.onJSONLoaded = function () {
     	if (this.ajaxRequest.readyState == 4) {
     		if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) {
     			this.json = JSON.parse(this.ajaxRequest.responseText);
    -			
    +
     			if(this.json.frames)
     			{
    -				// sprite sheet
    +				// sprite sheet
     				var scope = this;
     				var textureUrl = this.baseUrl + this.json.meta.image;
     				var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
     				var frameData = this.json.frames;
    -			
    +
     				this.texture = image.texture.baseTexture;
     				image.addEventListener("loaded", function (event) {
     					scope.onLoaded();
     				});
    -			
    +
     				for (var i in frameData) {
     					var rect = frameData[i].frame;
     					if (rect) {
    @@ -220,20 +278,20 @@ PIXI.JsonLoader.prototype.onJSONLoaded = function () {
     							height: rect.h
     						});
     						if (frameData[i].trimmed) {
    -							//var realSize = frameData[i].spriteSourceSize;
    +							//var realSize = frameData[i].spriteSourceSize;
     							PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
    -							PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
    -							// calculate the offset!
    +							PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
    +							// calculate the offset!
     						}
     					}
     				}
    -			
    +
     				image.load();
    -				
    +
     			}
     			else if(this.json.bones)
     			{
    -				// spine animation
    +				// spine animation
     				var spineJsonParser = new spine.SkeletonJson();
     				var skeletonData = spineJsonParser.readSkeletonData(this.json);
     				PIXI.AnimCache[this.url] = skeletonData;
    @@ -243,20 +301,20 @@ PIXI.JsonLoader.prototype.onJSONLoaded = function () {
     			{
     				this.onLoaded();
     			}
    -			
    -			
    -			
    -			
    -		} else {
    +		}
    +		else
    +		{
     			this.onError();
     		}
     	}
     };
     
    -/**
    +/**
      * Invoke when json file loaded
    + *
    + * @method onLoaded
      * @private
    - */
    + */
     PIXI.JsonLoader.prototype.onLoaded = function () {
     	this.loaded = true;
     	this.dispatchEvent({
    @@ -265,10 +323,12 @@ PIXI.JsonLoader.prototype.onLoaded = function () {
     	});
     };
     
    -/**
    +/**
      * Invoke when error occured
    + *
    + * @method onError
      * @private
    - */
    + */
     PIXI.JsonLoader.prototype.onError = function () {
     	this.dispatchEvent({
     		type: "error",
    @@ -284,13 +344,13 @@ PIXI.JsonLoader.prototype.onError = function () {
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_loaders_SpineLoader.js.html b/docs/files/src_pixi_loaders_SpineLoader.js.html index a5d91bf..0590ea8 100644 --- a/docs/files/src_pixi_loaders_SpineLoader.js.html +++ b/docs/files/src_pixi_loaders_SpineLoader.js.html @@ -2,12 +2,12 @@ - src/pixi/loaders/SpineLoader.js - Pixi.JS - - - - - + src/pixi/loaders/SpineLoader.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,54 +166,72 @@
    -

    File: src/pixi/loaders/SpineLoader.js

    +

    File: src/pixi/loaders/SpineLoader.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi
    - * 
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi
    + *
      * Awesome JS run time provided by EsotericSoftware
    - * https://github.com/EsotericSoftware/spine-runtimes
    - * 
    - */
    + * https://github.com/EsotericSoftware/spine-runtimes
    + *
    + */
     
    -/**
    +/**
      * The Spine loader is used to load in JSON spine data
    - * To generate the data you need to use http://esotericsoftware.com/ and export the "JSON" format
    + * To generate the data you need to use http://esotericsoftware.com/ and export the "JSON" format
      * Due to a clash of names  You will need to change the extension of the spine file from *.json to *.anim for it to load
    - * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source
    - * You will need to generate a sprite sheet to accompany the spine data 
    + * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source
    + * You will need to generate a sprite sheet to accompany the spine data
      * When loaded this class will dispatch a "loaded" event
    + *
      * @class Spine
    + * @uses EventTarget
      * @constructor
    - * @extends EventTarget
    - * @param {String} url the url of the sprite sheet JSON file
    - * @param {Boolean} crossorigin
    - */
    -PIXI.SpineLoader = function(url, crossorigin) 
    + * @param url {String} The url of the JSON file
    + * @param crossorigin {Boolean} Whether requests should be treated as crossorigin
    + */
    +PIXI.SpineLoader = function(url, crossorigin)
     {
     	PIXI.EventTarget.call(this);
    +
    +	/**
    +	 * The url of the bitmap font data
    +	 *
    +	 * @property url
    +	 * @type String
    +	 */
     	this.url = url;
    +
    +	/**
    +	 * Whether the requests should be treated as cross origin
    +	 *
    +	 * @property crossorigin
    +	 * @type Boolean
    +	 */
     	this.crossorigin = crossorigin;
    +
    +	/**
    +	 * [read-only] Whether the data has loaded yet
    +	 *
    +	 * @property loaded
    +	 * @type Boolean
    +	 * @readOnly
    +	 */
     	this.loaded = false;
     }
     
    -PIXI.SpineLoader.constructor = PIXI.SpineLoader;
    -
    -PIXI.SpineLoader.prototype.load = function()
    -{
    -	new PIXI.JsonLoader(this.url, this.crossorigin);
    -		jsonLoader.addEventListener("loaded", function (event) {
    -			scope.json = event.content.json;
    -			scope.onJSONLoaded();
    -		});
    -		jsonLoader.load();
    -};
    +PIXI.SpineLoader.prototype.constructor = PIXI.SpineLoader;
     
    +/**
    + * Loads the JSON data
    + *
    + * @method load
    + */
     PIXI.SpineLoader.prototype.load = function () {
    -	
    +
     	var scope = this;
     	var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
     	jsonLoader.addEventListener("loaded", function (event) {
    @@ -199,25 +241,28 @@ PIXI.SpineLoader.prototype.load = function () {
     	jsonLoader.load();
     };
     
    -/**
    +/**
      * Invoke when JSON file is loaded
    + *
    + * @method onJSONLoaded
      * @private
    - */
    + */
     PIXI.SpineLoader.prototype.onJSONLoaded = function (event) {
    -	
     	var spineJsonParser = new spine.SkeletonJson();
    -	
     	var skeletonData = spineJsonParser.readSkeletonData(this.json);
    -	
    +
     	PIXI.AnimCache[this.url] = skeletonData;
     
     	this.onLoaded();
     };
     
    -
    -			
    -PIXI.SpineLoader.prototype.onLoaded = function()
    -{
    +/**
    + * Invoke when JSON file is loaded
    + *
    + * @method onLoaded
    + * @private
    + */
    +PIXI.SpineLoader.prototype.onLoaded = function () {
     	this.loaded = true;
         this.dispatchEvent({type: "loaded", content: this});
     };
    @@ -232,13 +277,13 @@ PIXI.SpineLoader.prototype.onLoaded = function()
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_loaders_SpriteSheetLoader.js.html b/docs/files/src_pixi_loaders_SpriteSheetLoader.js.html index 7f4f05f..7ec53e4 100644 --- a/docs/files/src_pixi_loaders_SpriteSheetLoader.js.html +++ b/docs/files/src_pixi_loaders_SpriteSheetLoader.js.html @@ -2,12 +2,12 @@ - src/pixi/loaders/SpriteSheetLoader.js - Pixi.JS - - - - - + src/pixi/loaders/SpriteSheetLoader.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,49 +166,88 @@
    -

    File: src/pixi/loaders/SpriteSheetLoader.js

    +

    File: src/pixi/loaders/SpriteSheetLoader.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -/**
    +/**
      * The sprite sheet loader is used to load in JSON sprite sheet data
    - * To generate the data you can use http://www.codeandweb.com/texturepacker and publish the "JSON" format
    + * To generate the data you can use http://www.codeandweb.com/texturepacker and publish the "JSON" format
      * There is a free version so thats nice, although the paid version is great value for money.
      * It is highly recommended to use Sprite sheets (also know as texture atlas") as it means sprite"s can be batched and drawn together for highly increased rendering speed.
      * Once the data has been loaded the frames are stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId()
      * This loader will also load the image file that the Spritesheet points to as well as the data.
      * When loaded this class will dispatch a "loaded" event
    + *
      * @class SpriteSheetLoader
    - * @extends EventTarget
    + * @uses EventTarget
      * @constructor
    - * @param {String} url the url of the sprite sheet JSON file
    - * @param {Boolean} crossorigin
    - */
    + * @param url {String} The url of the sprite sheet JSON file
    + * @param crossorigin {Boolean} Whether requests should be treated as crossorigin
    + */
     
     PIXI.SpriteSheetLoader = function (url, crossorigin) {
    -	/*
    +	/*
     	 * i use texture packer to load the assets..
    -	 * http://www.codeandweb.com/texturepacker
    +	 * http://www.codeandweb.com/texturepacker
     	 * make sure to set the format as "JSON"
    -	 */
    +	 */
     	PIXI.EventTarget.call(this);
    +
    +	/**
    +	 * The url of the bitmap font data
    +	 *
    +	 * @property url
    +	 * @type String
    +	 */
     	this.url = url;
    -	this.baseUrl = url.replace(/[^\/]*$/, "");
    -	this.texture = null;
    -	this.frames = {};
    +
    +	/**
    +	 * Whether the requests should be treated as cross origin
    +	 *
    +	 * @property crossorigin
    +	 * @type Boolean
    +	 */
     	this.crossorigin = crossorigin;
    +
    +	/**
    +	 * [read-only] The base url of the bitmap font data
    +	 *
    +	 * @property baseUrl
    +	 * @type String
    +	 * @readOnly
    +	 */
    +	this.baseUrl = url.replace(/[^\/]*$/, "");
    +
    +    /**
    +     * The texture being loaded
    +     *
    +     * @property texture
    +     * @type Texture
    +     */
    +    this.texture = null;
    +
    +    /**
    +     * The frames of the sprite sheet
    +     *
    +     * @property frames
    +     * @type Object
    +     */
    +	this.frames = {};
     };
     
    -// constructor
    -PIXI.SpriteSheetLoader.constructor = PIXI.SpriteSheetLoader;
    +// constructor
    +PIXI.SpriteSheetLoader.prototype.constructor = PIXI.SpriteSheetLoader;
     
    -/**
    +/**
      * This will begin loading the JSON file
    - */
    + *
    + * @method load
    + */
     PIXI.SpriteSheetLoader.prototype.load = function () {
     	var scope = this;
     	var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
    @@ -195,10 +258,12 @@ PIXI.SpriteSheetLoader.prototype.load = function () {
     	jsonLoader.load();
     };
     
    -/**
    +/**
      * Invoke when JSON file is loaded
    + *
    + * @method onJSONLoaded
      * @private
    - */
    + */
     PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
     	var scope = this;
     	var textureUrl = this.baseUrl + this.json.meta.image;
    @@ -220,20 +285,22 @@ PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
     				height: rect.h
     			});
     			if (frameData[i].trimmed) {
    -				//var realSize = frameData[i].spriteSourceSize;
    +				//var realSize = frameData[i].spriteSourceSize;
     				PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
    -				PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
    -				// calculate the offset!
    +				PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
    +				// calculate the offset!
     			}
     		}
     	}
     
     	image.load();
     };
    -/**
    +/**
      * Invoke when all files are loaded (json and texture)
    + *
    + * @method onLoaded
      * @private
    - */
    + */
     PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
     	this.dispatchEvent({
     		type: "loaded",
    @@ -250,13 +317,13 @@ PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_primitives_Graphics.js.html b/docs/files/src_pixi_primitives_Graphics.js.html index 56e8996..9041f75 100644 --- a/docs/files/src_pixi_primitives_Graphics.js.html +++ b/docs/files/src_pixi_primitives_Graphics.js.html @@ -2,12 +2,12 @@ - src/pixi/primitives/Graphics.js - Pixi.JS - - - - - + src/pixi/primitives/Graphics.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,111 +166,152 @@
    -

    File: src/pixi/primitives/Graphics.js

    +

    File: src/pixi/primitives/Graphics.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
     
    -/**
    - * The Graphics class contains a set of methods that you can use to create primitive shapes and lines. 
    +/**
    + * The Graphics class contains a set of methods that you can use to create primitive shapes and lines.
      * It is important to know that with the webGL renderer only simple polys can be filled at this stage
    - * Complex polys will not be filled. Heres an example of a complex poly: http://www.goodboydigital.com/wp-content/uploads/2013/06/complexPolygon.png
    - * @class Graphics 
    + * Complex polys will not be filled. Heres an example of a complex poly: http://www.goodboydigital.com/wp-content/uploads/2013/06/complexPolygon.png
    + *
    + * @class Graphics
      * @extends DisplayObjectContainer
      * @constructor
    - */
    + */
     PIXI.Graphics = function()
     {
     	PIXI.DisplayObjectContainer.call( this );
    -	
    +
     	this.renderable = true;
    -	
    +
    +    /**
    +     * The alpha of the fill of this graphics object
    +     *
    +     * @property fillAlpha
    +     * @type Number
    +     */
     	this.fillAlpha = 1;
    -	
    +
    +    /**
    +     * The width of any lines drawn
    +     *
    +     * @property lineWidth
    +     * @type Number
    +     */
     	this.lineWidth = 0;
    +
    +    /**
    +     * The color of any lines drawn
    +     *
    +     * @property lineColor
    +     * @type String
    +     */
     	this.lineColor = "black";
    -	
    +
    +    /**
    +     * Graphics data
    +     *
    +     * @property graphicsData
    +     * @type Array
    +     * @private
    +     */
     	this.graphicsData = [];
    -	
    +
    +    /**
    +     * Current path
    +     *
    +     * @property currentPath
    +     * @type Object
    +     * @private
    +     */
     	this.currentPath = {points:[]};
     }
     
    -// constructor
    -PIXI.Graphics.constructor = PIXI.Graphics;
    +// constructor
     PIXI.Graphics.prototype = Object.create( PIXI.DisplayObjectContainer.prototype );
    +PIXI.Graphics.prototype.constructor = PIXI.Graphics;
     
    -/**
    +/**
      * Specifies a line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method.
    + *
      * @method lineStyle
    - * @param lineWidth {Number}
    - * @param color {Number}
    - * @param alpha {Number}
    - */
    + * @param lineWidth {Number} width of the line to draw, will update the object's stored style
    + * @param color {Number} color of the line to draw, will update the object's stored style
    + * @param alpha {Number} alpha of the line to draw, will update the object's stored style
    + */
     PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha)
     {
     	if(this.currentPath.points.length == 0)this.graphicsData.pop();
    -	
    +
     	this.lineWidth = lineWidth || 0;
     	this.lineColor = color || 0;
     	this.lineAlpha = (alpha == undefined) ? 1 : alpha;
    -	
    -	this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, 
    +
    +	this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
     						fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY};
    -	
    +
     	this.graphicsData.push(this.currentPath);
     }
     
    -/**
    +/**
      * Moves the current drawing position to (x, y).
    + *
      * @method moveTo
    - * @param x {Number}
    - * @param y {Number}
    - */
    + * @param x {Number} the X coord to move to
    + * @param y {Number} the Y coord to move to
    + */
     PIXI.Graphics.prototype.moveTo = function(x, y)
     {
     	if(this.currentPath.points.length == 0)this.graphicsData.pop();
    -	
    -	this.currentPath = this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, 
    +
    +	this.currentPath = this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
     						fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY};
    -	
    +
     	this.currentPath.points.push(x, y);
    -	
    +
     	this.graphicsData.push(this.currentPath);
     }
     
    -/**
    - * Draws a line using the current line style from the current drawing position to (x, y); the current drawing position is then set to (x, y).
    +/**
    + * Draws a line using the current line style from the current drawing position to (x, y);
    + * the current drawing position is then set to (x, y).
    + *
      * @method lineTo
    - * @param x {Number}
    - * @param y {Number}
    - */
    + * @param x {Number} the X coord to draw to
    + * @param y {Number} the Y coord to draw to
    + */
     PIXI.Graphics.prototype.lineTo = function(x, y)
     {
     	this.currentPath.points.push(x, y);
     	this.dirty = true;
     }
     
    -/**
    - * Specifies a simple one-color fill that subsequent calls to other Graphics methods (such as lineTo() or drawCircle()) use when drawing.
    +/**
    + * Specifies a simple one-color fill that subsequent calls to other Graphics methods
    + * (such as lineTo() or drawCircle()) use when drawing.
    + *
      * @method beginFill
      * @param color {uint} the color of the fill
      * @param alpha {Number} the alpha
    - */
    + */
     PIXI.Graphics.prototype.beginFill = function(color, alpha)
     {
     	this.filling = true;
     	this.fillColor = color || 0;
    -	this.fillAlpha = alpha || 1;
    +	this.fillAlpha = (alpha == undefined) ? 1 : alpha;
     }
     
    -/**
    +/**
      * Applies a fill to the lines and shapes that were added since the last call to the beginFill() method.
    + *
      * @method endFill
    - */
    + */
     PIXI.Graphics.prototype.endFill = function()
     {
     	this.filling = false;
    @@ -254,79 +319,158 @@ PIXI.Graphics.prototype.endFill = function()
     	this.fillAlpha = 1;
     }
     
    -/**
    +/**
      * @method drawRect
    - * @param x {Number}
    - * @param y {Number}
    - * @param width {Number}
    - * @param height {Number}
    - */
    + *
    + * @param x {Number} The X coord of the top-left of the rectangle
    + * @param y {Number} The Y coord of the top-left of the rectangle
    + * @param width {Number} The width of the rectangle
    + * @param height {Number} The height of the rectangle
    + */
     PIXI.Graphics.prototype.drawRect = function( x, y, width, height )
     {
     	if(this.currentPath.points.length == 0)this.graphicsData.pop();
    -	
    -	this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, 
    -						fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, 
    +
    +	this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
    +						fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling,
     						points:[x, y, width, height], type:PIXI.Graphics.RECT};
    -						
    +
     	this.graphicsData.push(this.currentPath);
     	this.dirty = true;
     }
     
    -/**
    +/**
      * Draws a circle.
    + *
      * @method drawCircle
    - * @param x {Number}
    - * @param y {Number}
    - * @param radius {Number}
    - */
    + * @param x {Number} The X coord of the center of the circle
    + * @param y {Number} The Y coord of the center of the circle
    + * @param radius {Number} The radius of the circle
    + */
     PIXI.Graphics.prototype.drawCircle = function( x, y, radius)
     {
     	if(this.currentPath.points.length == 0)this.graphicsData.pop();
    -	
    -	this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, 
    -						fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, 
    +
    +	this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
    +						fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling,
     						points:[x, y, radius, radius], type:PIXI.Graphics.CIRC};
    -						
    +
     	this.graphicsData.push(this.currentPath);
     	this.dirty = true;
     }
     
    -/**
    +/**
      * Draws an elipse.
    + *
      * @method drawElipse
      * @param x {Number}
      * @param y {Number}
      * @param width {Number}
      * @param height {Number}
    - */
    + */
     PIXI.Graphics.prototype.drawElipse = function( x, y, width, height)
     {
     	if(this.currentPath.points.length == 0)this.graphicsData.pop();
    -	
    -	this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, 
    -						fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, 
    +
    +	this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
    +						fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling,
     						points:[x, y, width, height], type:PIXI.Graphics.ELIP};
    -						
    +
     	this.graphicsData.push(this.currentPath);
     	this.dirty = true;
     }
     
    -/**
    +/**
      * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings.
    + *
      * @method clear
    - */
    + */
     PIXI.Graphics.prototype.clear = function()
     {
     	this.lineWidth = 0;
     	this.filling = false;
    -	
    +
     	this.dirty = true;
     	this.clearDirty = true;
     	this.graphicsData = [];
    +
    +	this.bounds = null//new PIXI.Rectangle();
     }
     
    -// SOME TYPES:
    +
    +PIXI.Graphics.prototype.updateFilterBounds = function()
    +{
    +	if(!this.bounds)
    +	{
    +		var minX = Infinity;
    +		var maxX = -Infinity;
    +
    +		var minY = Infinity;
    +		var maxY = -Infinity;
    +
    +		var points, x, y;
    +
    +		for (var i = 0; i < this.graphicsData.length; i++) {
    +			
    +
    +			var data = this.graphicsData[i];
    +			var type = data.type;
    +			var lineWidth = data.lineWidth;
    +
    +			points = data.points;
    +
    +			if(type === PIXI.Graphics.RECT)
    +			{
    +				x = points.x - lineWidth/2;
    +				y = points.y - lineWidth/2;
    +				var width = points.width + lineWidth;
    +				var height = points.height + lineWidth;
    +
    +				minX = x < minX ? x : minX;
    +				maxX = x + width > maxX ? x + width : maxX;
    +
    +				minY = y < minY ? x : minY;
    +				maxY = y + height > maxY ? y + height : maxY;
    +			}
    +			else if(type === PIXI.Graphics.CIRC || type === PIXI.Graphics.ELIP)
    +			{
    +				x = points.x;
    +				y = points.y;
    +				var radius = points.radius + lineWidth/2;
    +				
    +				minX = x - radius < minX ? x - radius : minX;
    +				maxX = x + radius > maxX ? x + radius : maxX;
    +
    +				minY = y - radius < minY ? y - radius : minY;
    +				maxY = y + radius > maxY ? y + radius : maxY;
    +			}
    +			else
    +			{
    +				// POLY
    +				for (var j = 0; j < points.length; j+=2) 
    +				{
    +					
    +					x = points[j];
    +					y = points[j+1];
    +
    +					minX = x-lineWidth < minX ? x-lineWidth : minX;
    +					maxX = x+lineWidth > maxX ? x+lineWidth : maxX;
    +
    +					minY = y-lineWidth < minY ? y-lineWidth : minY;
    +					maxY = y+lineWidth > maxY ? y+lineWidth : maxY;
    +				};
    +			}
    +
    +		};
    +
    +		this.bounds = new PIXI.Rectangle(minX, minY, maxX - minX, maxY - minY);
    +
    +	}
    +
    +//	console.log(this.bounds);
    +}
    +
    +// SOME TYPES:
     PIXI.Graphics.POLY = 0;
     PIXI.Graphics.RECT = 1;
     PIXI.Graphics.CIRC = 2;
    @@ -341,13 +485,13 @@ PIXI.Graphics.ELIP = 3;
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_renderers_canvas_CanvasGraphics.js.html b/docs/files/src_pixi_renderers_canvas_CanvasGraphics.js.html index d09a4be..a0ec34a 100644 --- a/docs/files/src_pixi_renderers_canvas_CanvasGraphics.js.html +++ b/docs/files/src_pixi_renderers_canvas_CanvasGraphics.js.html @@ -2,12 +2,12 @@ - src/pixi/renderers/canvas/CanvasGraphics.js - Pixi.JS - - - - - + src/pixi/renderers/canvas/CanvasGraphics.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,64 +166,65 @@
    -

    File: src/pixi/renderers/canvas/CanvasGraphics.js

    +

    File: src/pixi/renderers/canvas/CanvasGraphics.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
     
    -/**
    +/**
      * A set of functions used by the canvas renderer to draw the primitive graphics data
    - * @class CanvasGraphics 
    - */
    + *
    + * @class CanvasGraphics
    + */
     PIXI.CanvasGraphics = function()
     {
    -	
    +
     }
     
     
    -/*
    - * @private
    +/*
    + * Renders the graphics object
    + *
      * @static
    + * @private
      * @method renderGraphics
      * @param graphics {Graphics}
      * @param context {Context2D}
    - */
    + */
     PIXI.CanvasGraphics.renderGraphics = function(graphics, context)
     {
     	var worldAlpha = graphics.worldAlpha;
    -	
    -	for (var i=0; i < graphics.graphicsData.length; i++) 
    +
    +	for (var i=0; i < graphics.graphicsData.length; i++)
     	{
     		var data = graphics.graphicsData[i];
     		var points = data.points;
    -		
    +
     		context.strokeStyle = color = '#' + ('00000' + ( data.lineColor | 0).toString(16)).substr(-6);
     
     		context.lineWidth = data.lineWidth;
    -		
    +
     		if(data.type == PIXI.Graphics.POLY)
     		{
    -			//if(data.lineWidth <= 0)continue;
    -			
     			context.beginPath();
    -			
    +
     			context.moveTo(points[0], points[1]);
    -			
    -			for (var j=1; j < points.length/2; j++)
    +
    +			for (var j=1; j < points.length/2; j++)
     			{
     				context.lineTo(points[j * 2], points[j * 2 + 1]);
    -			} 
    -	      	
    -	      	// if the first and last point are the same close the path - much neater :)
    +			}
    +
    +	      	// if the first and last point are the same close the path - much neater :)
     	      	if(points[0] == points[points.length-2] && points[1] == points[points.length-1])
     	      	{
     	      		context.closePath();
     	      	}
    -			
    +
     			if(data.fill)
     			{
     				context.globalAlpha = data.fillAlpha * worldAlpha;
    @@ -214,29 +239,28 @@ PIXI.CanvasGraphics.renderGraphics = function(graphics, context)
     		}
     		else if(data.type == PIXI.Graphics.RECT)
     		{
    -				
    -			// TODO - need to be Undefined!
    -			if(data.fillColor)
    +
    +			if(data.fillColor || data.fillColor === 0)
     			{
     				context.globalAlpha = data.fillAlpha * worldAlpha;
     				context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6);
    -				context.rect(points[0], points[1], points[2], points[3]);
    -				
    +				context.fillRect(points[0], points[1], points[2], points[3]);
    +
     			}
     			if(data.lineWidth)
     			{
     				context.globalAlpha = data.lineAlpha * worldAlpha;
     				context.strokeRect(points[0], points[1], points[2], points[3]);
     			}
    -			
    +
     		}
     		else if(data.type == PIXI.Graphics.CIRC)
     		{
    -			// TODO - need to be Undefined!
    +			// TODO - need to be Undefined!
           		context.beginPath();
     			context.arc(points[0], points[1], points[2],0,2*Math.PI);
     			context.closePath();
    -			
    +
     			if(data.fill)
     			{
     				context.globalAlpha = data.fillAlpha * worldAlpha;
    @@ -251,35 +275,35 @@ PIXI.CanvasGraphics.renderGraphics = function(graphics, context)
     		}
     		else if(data.type == PIXI.Graphics.ELIP)
     		{
    -			
    -			// elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
    -			
    +
    +			// elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
    +
     			var elipseData =  data.points;
    -			
    +
     			var w = elipseData[2] * 2;
     			var h = elipseData[3] * 2;
    -	
    -			var x = elipseData[0] - w/2;
    -			var y = elipseData[1] - h/2;
    -			
    +
    +			var x = elipseData[0] - w/2;
    +			var y = elipseData[1] - h/2;
    +
           		context.beginPath();
    -			
    +
     			var kappa = .5522848,
    -			ox = (w / 2) * kappa, // control point offset horizontal
    -			oy = (h / 2) * kappa, // control point offset vertical
    -			xe = x + w,           // x-end
    -			ye = y + h,           // y-end
    -			xm = x + w / 2,       // x-middle
    -			ym = y + h / 2;       // y-middle
    -			
    +			ox = (w / 2) * kappa, // control point offset horizontal
    +			oy = (h / 2) * kappa, // control point offset vertical
    +			xe = x + w,           // x-end
    +			ye = y + h,           // y-end
    +			xm = x + w / 2,       // x-middle
    +			ym = y + h / 2;       // y-middle
    +
     			context.moveTo(x, ym);
     			context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
     			context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
     			context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
     			context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
    -  
    +
     			context.closePath();
    -			
    +
     			if(data.fill)
     			{
     				context.globalAlpha = data.fillAlpha * worldAlpha;
    @@ -292,51 +316,51 @@ PIXI.CanvasGraphics.renderGraphics = function(graphics, context)
           			context.stroke();
     			}
     		}
    -      	
    +
     	};
     }
     
    -/*
    - * @private
    +/*
    + * Renders a graphics mask
    + *
      * @static
    + * @private
      * @method renderGraphicsMask
      * @param graphics {Graphics}
      * @param context {Context2D}
    - */
    + */
     PIXI.CanvasGraphics.renderGraphicsMask = function(graphics, context)
     {
     	var worldAlpha = graphics.worldAlpha;
    -	
    +
     	var len = graphics.graphicsData.length;
     	if(len > 1)
     	{
     		len = 1;
     		console.log("Pixi.js warning: masks in canvas can only mask using the first path in the graphics object")
     	}
    -	
    -	for (var i=0; i < 1; i++) 
    +
    +	for (var i=0; i < 1; i++)
     	{
     		var data = graphics.graphicsData[i];
     		var points = data.points;
    -		
    +
     		if(data.type == PIXI.Graphics.POLY)
     		{
    -			//if(data.lineWidth <= 0)continue;
    -			
     			context.beginPath();
     			context.moveTo(points[0], points[1]);
    -			
    -			for (var j=1; j < points.length/2; j++)
    +
    +			for (var j=1; j < points.length/2; j++)
     			{
     				context.lineTo(points[j * 2], points[j * 2 + 1]);
    -			} 
    -	      	
    -	      	// if the first and last point are the same close the path - much neater :)
    +			}
    +
    +	      	// if the first and last point are the same close the path - much neater :)
     	      	if(points[0] == points[points.length-2] && points[1] == points[points.length-1])
     	      	{
     	      		context.closePath();
     	      	}
    -			
    +
     		}
     		else if(data.type == PIXI.Graphics.RECT)
     		{
    @@ -346,33 +370,33 @@ PIXI.CanvasGraphics.renderGraphicsMask = function(graphics, context)
     		}
     		else if(data.type == PIXI.Graphics.CIRC)
     		{
    -			// TODO - need to be Undefined!
    +			// TODO - need to be Undefined!
           		context.beginPath();
     			context.arc(points[0], points[1], points[2],0,2*Math.PI);
     			context.closePath();
     		}
     		else if(data.type == PIXI.Graphics.ELIP)
     		{
    -			
    -			// elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
    +
    +			// elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
     			var elipseData =  data.points;
    -			
    +
     			var w = elipseData[2] * 2;
     			var h = elipseData[3] * 2;
    -	
    -			var x = elipseData[0] - w/2;
    -			var y = elipseData[1] - h/2;
    -			
    +
    +			var x = elipseData[0] - w/2;
    +			var y = elipseData[1] - h/2;
    +
           		context.beginPath();
    -			
    +
     			var kappa = .5522848,
    -			ox = (w / 2) * kappa, // control point offset horizontal
    -			oy = (h / 2) * kappa, // control point offset vertical
    -			xe = x + w,           // x-end
    -			ye = y + h,           // y-end
    -			xm = x + w / 2,       // x-middle
    -			ym = y + h / 2;       // y-middle
    -			
    +			ox = (w / 2) * kappa, // control point offset horizontal
    +			oy = (h / 2) * kappa, // control point offset vertical
    +			xe = x + w,           // x-end
    +			ye = y + h,           // y-end
    +			xm = x + w / 2,       // x-middle
    +			ym = y + h / 2;       // y-middle
    +
     			context.moveTo(x, ym);
     			context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
     			context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
    @@ -380,8 +404,8 @@ PIXI.CanvasGraphics.renderGraphicsMask = function(graphics, context)
     			context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
     			context.closePath();
     		}
    -      	
    -	   
    +
    +
     	};
     }
     
    @@ -394,13 +418,13 @@ PIXI.CanvasGraphics.renderGraphicsMask = function(graphics, context)
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_renderers_canvas_CanvasRenderer.js.html b/docs/files/src_pixi_renderers_canvas_CanvasRenderer.js.html index b4a1e3c..9f17324 100644 --- a/docs/files/src_pixi_renderers_canvas_CanvasRenderer.js.html +++ b/docs/files/src_pixi_renderers_canvas_CanvasRenderer.js.html @@ -2,12 +2,12 @@ - src/pixi/renderers/canvas/CanvasRenderer.js - Pixi.JS - - - - - + src/pixi/renderers/canvas/CanvasRenderer.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,105 +166,106 @@
    -

    File: src/pixi/renderers/canvas/CanvasRenderer.js

    +

    File: src/pixi/renderers/canvas/CanvasRenderer.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
     
    -/**
    +/**
      * the CanvasRenderer draws the stage and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL.
      * Dont forget to add the view to your DOM or you will not see anything :)
    + *
      * @class CanvasRenderer
      * @constructor
    - * @param width {Number} the width of the canvas view
    - * @default 0
    - * @param height {Number} the height of the canvas view
    - * @default 0
    + * @param width=0 {Number} the width of the canvas view
    + * @param height=0 {Number} the height of the canvas view
      * @param view {Canvas} the canvas to use as a view, optional
    - * @param transparent {Boolean} the transparency of the render view, default false
    - * @default false
    - * 
    - */
    + * @param transparent=false {Boolean} the transparency of the render view, default false
    + */
     PIXI.CanvasRenderer = function(width, height, view, transparent)
     {
     	this.transparent = transparent;
    -	
    -	/**
    +
    +	/**
     	 * The width of the canvas view
    +	 *
     	 * @property width
     	 * @type Number
     	 * @default 800
    -	 */
    +	 */
     	this.width = width || 800;
    -	/**
    +
    +	/**
     	 * The height of the canvas view
    +	 *
     	 * @property height
     	 * @type Number
     	 * @default 600
    -	 */
    +	 */
     	this.height = height || 600;
    -	
    -	this.refresh = true;
    -	
    -	/**
    +
    +	/**
     	 * The canvas element that the everything is drawn to
    +	 *
     	 * @property view
     	 * @type Canvas
    -	 */
    -	this.view = view || document.createElement( 'canvas' ); 
    -	
    -	// hack to enable some hardware acceleration!
    -	//this.view.style["transform"] = "translatez(0)";
    +	 */
    +	this.view = view || document.createElement( 'canvas' );
    +
    +	/**
    +	 * The canvas context that the everything is drawn to
    +	 * @property context
    +	 * @type Canvas 2d Context
    +	 */
    +	this.context = this.view.getContext("2d");
    +
    +	this.refresh = true;
    +	// hack to enable some hardware acceleration!
    +	//this.view.style["transform"] = "translatez(0)";
     	
         this.view.width = this.width;
     	this.view.height = this.height;  
     	this.count = 0;
    -	
    -	/**
    -	 * The canvas context that the everything is drawn to
    -	 * @property context
    -	 * @type Canvas 2d Context
    -	 */
    -	this.context = this.view.getContext("2d");
     }
     
    -// constructor
    -PIXI.CanvasRenderer.constructor = PIXI.CanvasRenderer;
    +// constructor
    +PIXI.CanvasRenderer.prototype.constructor = PIXI.CanvasRenderer;
     
    -/**
    +/**
      * Renders the stage to its canvas view
    + *
      * @method render
      * @param stage {Stage} the Stage element to be rendered
    - */
    + */
     PIXI.CanvasRenderer.prototype.render = function(stage)
     {
    -	// update children if need be
     	
    -	//stage.__childrenAdded = [];
    -	//stage.__childrenRemoved = [];
    +	//stage.__childrenAdded = [];
    +	//stage.__childrenRemoved = [];
     	
    -	// update textures if need be
    +	// update textures if need be
     	PIXI.texturesToUpdate = [];
     	PIXI.texturesToDestroy = [];
     	
    +	PIXI.visibleCount++;
     	stage.updateTransform();
     	
    -	// update the background color
    +	// update the background color
     	if(this.view.style.backgroundColor!=stage.backgroundColorString && !this.transparent)this.view.style.backgroundColor = stage.backgroundColorString;
     
     	this.context.setTransform(1,0,0,1,0,0); 
     	this.context.clearRect(0, 0, this.width, this.height)
         this.renderDisplayObject(stage);
    -    //as
    +    //as
        
    -    // run interaction!
    +    // run interaction!
     	if(stage.interactive)
     	{
    -		//need to add some events!
    +		//need to add some events!
     		if(!stage._interactiveEventsAdded)
     		{
     			stage._interactiveEventsAdded = true;
    @@ -248,18 +273,22 @@ PIXI.CanvasRenderer.prototype.render = function(stage)
     		}
     	}
     	
    -	// remove frame updates..
    +	// remove frame updates..
     	if(PIXI.Texture.frameUpdates.length > 0)
     	{
     		PIXI.Texture.frameUpdates = [];
     	}
    +	
    +	
     }
     
    -/**
    +/**
      * resizes the canvas view to the specified width and height
    - * @param the new width of the canvas view
    - * @param the new height of the canvas view
    - */
    + *
    + * @method resize
    + * @param width {Number} the new width of the canvas view
    + * @param height {Number} the new height of the canvas view
    + */
     PIXI.CanvasRenderer.prototype.resize = function(width, height)
     {
     	this.width = width;
    @@ -269,19 +298,22 @@ PIXI.CanvasRenderer.prototype.resize = function(width, height)
     	this.view.height = height;
     }
     
    -/**
    +/**
    + * Renders a display object
    + *
    + * @method renderDisplayObject
    + * @param displayObject {DisplayObject} The displayObject to render
      * @private
    - */
    -
    + */
     PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
     {
    -	// no loger recurrsive!
    +	// no loger recurrsive!
     	var transform;
     	var context = this.context;
     	
     	context.globalCompositeOperation = 'source-over';
     	
    -	// one the display object hits this. we can break the loop	
    +	// one the display object hits this. we can break the loop	
     	var testObject = displayObject.last._iNext;
     	displayObject = displayObject.first;
     	
    @@ -306,7 +338,7 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
     				
     			var frame = displayObject.texture.frame;
     			
    -			if(frame)
    +			if(frame && frame.width && frame.height)
     			{
     				context.globalAlpha = displayObject.worldAlpha;
     				
    @@ -335,6 +367,7 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
     		}
     		else if(displayObject instanceof PIXI.CustomRenderable)
     		{
    +			context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]);
     			displayObject.renderCanvas(this);
     		}
     		else if(displayObject instanceof PIXI.Graphics)
    @@ -344,59 +377,69 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
     		}
     		else if(displayObject instanceof PIXI.FilterBlock)
     		{
    -			if(displayObject.open)
    -			{
    -				context.save();
    -				
    -				var cacheAlpha = displayObject.mask.alpha;
    -				var maskTransform = displayObject.mask.worldTransform;
    -				
    -				context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5])
    -				
    -				displayObject.mask.worldAlpha = 0.5;
    -				
    -				context.worldAlpha = 0;
    -				
    -				PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, context);
    -		//		context.fillStyle = 0xFF0000;
    -			//	context.fillRect(0, 0, 200, 200);
    -				context.clip();
    -				
    -				displayObject.mask.worldAlpha = cacheAlpha;
    -				//context.globalCompositeOperation = 'lighter';
    +			if(displayObject.data instanceof PIXI.Graphics)
    + 			{
    +				var mask = displayObject.data;
    +
    +				if(displayObject.open)
    +				{
    +					context.save();
    +					
    +					var cacheAlpha = mask.alpha;
    +					var maskTransform = mask.worldTransform;
    +					
    +					context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5])
    +					
    +					mask.worldAlpha = 0.5;
    +					
    +					context.worldAlpha = 0;
    +					
    +					PIXI.CanvasGraphics.renderGraphicsMask(mask, context);
    +					context.clip();
    +					
    +					mask.worldAlpha = cacheAlpha;
    +				}
    +				else
    +				{
    +					context.restore();
    +				}
     			}
     			else
     			{
    -				//context.globalCompositeOperation = 'source-over';
    -				context.restore();
    +				// only masks supported right now!
     			}
     		}
    -	//	count++
    +	//	count++
     		displayObject = displayObject._iNext;
     		
     		
     	}
     	while(displayObject != testObject)
    +
    +	
     }
     
    -
    -/**
    +/**
    + * Renders a flat strip
    + *
    + * @method renderStripFlat
    + * @param strip {Strip} The Strip to render
      * @private
    - */
    + */
     PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip)
     {
     	var context = this.context;
     	var verticies = strip.verticies;
     	var uvs = strip.uvs;
     	
    -	var length = verticies.length/2;
    +	var length = verticies.length/2;
     	this.count++;
     	
     	context.beginPath();
     	for (var i=1; i < length-2; i++) 
     	{
     		
    -		// draw some triangles!
    +		// draw some triangles!
     		var index = i*2;
     		
     		 var x0 = verticies[index],   x1 = verticies[index+2], x2 = verticies[index+4];
    @@ -413,9 +456,13 @@ PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip)
     	context.closePath();
     }
     
    -/**
    +/**
    + * Renders a tiling sprite
    + *
    + * @method renderTilingSprite
    + * @param sprite {TilingSprite} The tilingsprite to render
      * @private
    - */
    + */
     PIXI.CanvasRenderer.prototype.renderTilingSprite = function(sprite)
     {
     	var context = this.context;
    @@ -429,38 +476,40 @@ PIXI.CanvasRenderer.prototype.renderTilingSprite = function(sprite)
     	var tilePosition = sprite.tilePosition;
     	var tileScale = sprite.tileScale;
     	
    -    // offset
    +    // offset
         context.scale(tileScale.x,tileScale.y);
         context.translate(tilePosition.x, tilePosition.y);
      	
     	context.fillStyle = sprite.__tilePattern;
    -	context.fillRect(-tilePosition.x,-tilePosition.y,sprite.width / tileScale.x, sprite.height / tileScale.y);
    +	context.fillRect(-tilePosition.x,-tilePosition.y,sprite.width / tileScale.x, sprite.height / tileScale.y);
     	
    -	context.scale(1/tileScale.x, 1/tileScale.y);
    +	context.scale(1/tileScale.x, 1/tileScale.y);
         context.translate(-tilePosition.x, -tilePosition.y);
         
         context.closePath();
     }
     
    -
    -
    -/**
    +/**
    + * Renders a strip
    + *
    + * @method renderStrip
    + * @param strip {Strip} The Strip to render
      * @private
    - */
    + */
     PIXI.CanvasRenderer.prototype.renderStrip = function(strip)
     {
     	var context = this.context;
    -	//context.globalCompositeOperation = 'lighter';
    -	// draw triangles!!
    +
    +	// draw triangles!!
     	var verticies = strip.verticies;
     	var uvs = strip.uvs;
     	
    -	var length = verticies.length/2;
    +	var length = verticies.length/2;
     	this.count++;
     	for (var i=1; i < length-2; i++) 
     	{
     		
    -		// draw some triangles!
    +		// draw some triangles!
     		var index = i*2;
     		
     		 var x0 = verticies[index],   x1 = verticies[index+2], x2 = verticies[index+4];
    @@ -477,12 +526,10 @@ PIXI.CanvasRenderer.prototype.renderStrip = function(strip)
     		context.lineTo(x2, y2);
     		context.closePath();
     		
    -	//	context.fillStyle = "white"//rgb(1, 1, 1,1));
    -	//	context.fill();
     		context.clip();
     		
     		
    -        // Compute matrix transform
    +        // Compute matrix transform
             var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2;
             var delta_a = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2;
             var delta_b = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2;
    @@ -494,25 +541,16 @@ PIXI.CanvasRenderer.prototype.renderStrip = function(strip)
     		
     		
     		    
    -        context.transform(delta_a/delta, delta_d/delta,
    -                      delta_b/delta, delta_e/delta,
    -                      delta_c/delta, delta_f/delta);
    +        context.transform(delta_a/delta, delta_d/delta,
    +                      delta_b/delta, delta_e/delta,
    +                      delta_c/delta, delta_f/delta);
                      
     		context.drawImage(strip.texture.baseTexture.source, 0, 0);
     	  	context.restore();
     	};
     	
    -//	context.globalCompositeOperation = 'source-over';	
     }
     
    -
    -
    -
    -
    -
    -
    -
    -
         
    @@ -522,13 +560,13 @@ PIXI.CanvasRenderer.prototype.renderStrip = function(strip)
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_renderers_webgl_PixiShader.js.html b/docs/files/src_pixi_renderers_webgl_PixiShader.js.html new file mode 100644 index 0000000..a1b2a0a --- /dev/null +++ b/docs/files/src_pixi_renderers_webgl_PixiShader.js.html @@ -0,0 +1,311 @@ + + + + + src/pixi/renderers/webgl/PixiShader.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/renderers/webgl/PixiShader.js

    + +
    +
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +
    +PIXI.PixiShader = function()
    +{
    +	// the webGL program..
    +	this.program;
    +	
    +	this.fragmentSrc = [
    +	  "precision lowp float;",
    +	  "varying vec2 vTextureCoord;",
    +	  "varying float vColor;",
    +	  "uniform sampler2D uSampler;",
    +	  "void main(void) {",
    +	    "gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;",
    +	  "}"
    +	];
    +	
    +}
    +
    +PIXI.PixiShader.prototype.init = function()
    +{
    +	var program = PIXI.compileProgram(this.vertexSrc || PIXI.PixiShader.defaultVertexSrc, this.fragmentSrc)
    +	
    +	var gl = PIXI.gl;
    +	
    +    gl.useProgram(program);
    +	
    +	// get and store the uniforms for the shader
    +	this.uSampler = gl.getUniformLocation(program, "uSampler");
    +	this.projectionVector = gl.getUniformLocation(program, "projectionVector");
    +	this.offsetVector = gl.getUniformLocation(program, "offsetVector");
    +	this.colorAttribute = gl.getAttribLocation(program, "aColor");
    +	//this.dimensions = gl.getUniformLocation(this.program, "dimensions");
    +	
    +	// get and store the attributes
    +	this.aVertexPosition = gl.getAttribLocation(program, "aVertexPosition");
    +	this.aTextureCoord = gl.getAttribLocation(program, "aTextureCoord");
    +	  
    +    // add those custom shaders!
    +    for (var key in this.uniforms)
    +    {
    +       
    +    	// get the uniform locations..
    +		program[key] = gl.getUniformLocation(program, key);
    +
    +
    +      
    +    }
    +  
    +	this.program = program;
    +}
    +
    +PIXI.PixiShader.prototype.syncUniforms = function()
    +{
    +	var gl = PIXI.gl;
    +	
    +	for (var key in this.uniforms) 
    +    {
    +    	//var 
    +    	var type = this.uniforms[key].type;
    +    	
    +    	// need to grow this!
    +    	if(type == "f")
    +    	{
    +			gl.uniform1f(this.program[key], this.uniforms[key].value);
    +    	}
    +    	if(type == "f2")
    +    	{
    +    	//	console.log(this.program[key])
    +			gl.uniform2f(this.program[key], this.uniforms[key].value.x, this.uniforms[key].value.y);
    +    	}
    +        else if(type == "f4")
    +        {
    +           // console.log(this.uniforms[key].value)
    +            gl.uniform4fv(this.program[key], this.uniforms[key].value);
    +        }
    +    	else if(type == "mat4")
    +    	{
    +    		gl.uniformMatrix4fv(this.program[key], false, this.uniforms[key].value);
    +    	}
    +    	else if(type == "sampler2D")
    +    	{
    +    		// first texture...
    +    		var texture = this.uniforms[key].value;
    +    		
    +    		gl.activeTexture(gl.TEXTURE1);
    +	    	gl.bindTexture(gl.TEXTURE_2D, texture.baseTexture._glTexture);
    +	    	
    +    		gl.uniform1i(this.program[key], 1);
    +    		
    +    		// activate texture..
    +    		// gl.uniformMatrix4fv(this.program[key], false, this.uniforms[key].value);
    +    		// gl.uniformMatrix4fv(this.program[key], false, this.uniforms[key].value);
    +    	}
    +    }
    +    
    +}
    +
    +PIXI.PixiShader.defaultVertexSrc = [
    +  "attribute vec2 aVertexPosition;",
    +  "attribute vec2 aTextureCoord;",
    +  "attribute float aColor;",
    +  
    +  "uniform vec2 projectionVector;",
    + "uniform vec2 offsetVector;",
    +  "varying vec2 vTextureCoord;",
    +  
    +  "varying float vColor;",
    +
    +  "const vec2 center = vec2(-1.0, 1.0);",
    +  "void main(void) {",
    +    "gl_Position = vec4( ((aVertexPosition + offsetVector) / projectionVector) + center , 0.0, 1.0);",
    +    "vTextureCoord = aTextureCoord;",
    +    "vColor = aColor;",
    +  "}"
    +];
    +
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_renderers_webgl_PrimitiveShader.js.html b/docs/files/src_pixi_renderers_webgl_PrimitiveShader.js.html new file mode 100644 index 0000000..ec967e2 --- /dev/null +++ b/docs/files/src_pixi_renderers_webgl_PrimitiveShader.js.html @@ -0,0 +1,249 @@ + + + + + src/pixi/renderers/webgl/PrimitiveShader.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/renderers/webgl/PrimitiveShader.js

    + +
    +
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +
    +PIXI.PrimitiveShader = function()
    +{
    +	// the webGL program..
    +	this.program;
    +    	
    +    this.fragmentSrc = [
    +      "precision mediump float;",
    +      "varying vec4 vColor;",
    +      "void main(void) {",
    +        "gl_FragColor = vColor;",
    +      "}"
    +    ];
    +
    +    this.vertexSrc  = [
    +      "attribute vec2 aVertexPosition;",
    +      "attribute vec4 aColor;",
    +      "uniform mat3 translationMatrix;",
    +      "uniform vec2 projectionVector;",
    +      "uniform vec2 offsetVector;",
    +      "uniform float alpha;",
    +      "varying vec4 vColor;",
    +      "void main(void) {",
    +        "vec3 v = translationMatrix * vec3(aVertexPosition , 1.0);",
    +        "v -= offsetVector.xyx;",
    +        "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);",
    +        "vColor = aColor  * alpha;",
    +      "}"
    +    ];
    +	
    +}
    +
    +PIXI.PrimitiveShader.prototype.init = function()
    +{
    +	var program = PIXI.compileProgram(this.vertexSrc, this.fragmentSrc);
    +	
    +	var gl = PIXI.gl;
    +	
    +  gl.useProgram(program);
    +	
    +	// get and store the uniforms for the shader
    +	this.projectionVector = gl.getUniformLocation(program, "projectionVector");
    +	this.offsetVector = gl.getUniformLocation(program, "offsetVector");
    +	this.colorAttribute = gl.getAttribLocation(program, "aColor");
    +	
    +	// get and store the attributes
    +	this.aVertexPosition = gl.getAttribLocation(program, "aVertexPosition");
    +	
    +    this.translationMatrix = gl.getUniformLocation(program, "translationMatrix");
    +    this.alpha = gl.getUniformLocation(program, "alpha");
    +
    +	this.program = program;
    +}
    +
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_renderers_webgl_StripShader.js.html b/docs/files/src_pixi_renderers_webgl_StripShader.js.html new file mode 100644 index 0000000..4e56dc0 --- /dev/null +++ b/docs/files/src_pixi_renderers_webgl_StripShader.js.html @@ -0,0 +1,257 @@ + + + + + src/pixi/renderers/webgl/StripShader.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/renderers/webgl/StripShader.js

    + +
    +
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +
    +PIXI.StripShader = function()
    +{
    +	// the webGL program..
    +	this.program;
    +	
    +    this.fragmentSrc = [
    +      "precision mediump float;",
    +      "varying vec2 vTextureCoord;",
    +      "varying float vColor;",
    +      "uniform float alpha;",
    +      "uniform sampler2D uSampler;",
    +      "void main(void) {",
    +        "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));",
    +        "gl_FragColor = gl_FragColor * alpha;",
    +      "}"
    +    ];
    +
    +    this.vertexSrc = [
    +      "attribute vec2 aVertexPosition;",
    +      "attribute vec2 aTextureCoord;",
    +      "attribute float aColor;",
    +      "uniform mat3 translationMatrix;",
    +      "uniform vec2 projectionVector;",
    +      "varying vec2 vTextureCoord;",
    +      "varying vec2 offsetVector;",
    +      "varying float vColor;",
    +      "void main(void) {",
    +        "vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);",
    +        "v -= offsetVector.xyx;",
    +        "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / projectionVector.y + 1.0 , 0.0, 1.0);",
    +        "vTextureCoord = aTextureCoord;",
    +        "vColor = aColor;",
    +      "}"
    +    ];
    +}
    +
    +PIXI.StripShader.prototype.init = function()
    +{
    +	var program = PIXI.compileProgram(this.vertexSrc, this.fragmentSrc)
    +	
    +	var gl = PIXI.gl;
    +	
    +    gl.useProgram(program);
    +
    +	// get and store the uniforms for the shader
    +	this.uSampler = gl.getUniformLocation(program, "uSampler");
    +	this.projectionVector = gl.getUniformLocation(program, "projectionVector");
    +	this.offsetVector = gl.getUniformLocation(program, "offsetVector");
    +	this.colorAttribute = gl.getAttribLocation(program, "aColor");
    +	//this.dimensions = gl.getUniformLocation(this.program, "dimensions");
    +	
    +	// get and store the attributes
    +	this.aVertexPosition = gl.getAttribLocation(program, "aVertexPosition");
    +	this.aTextureCoord = gl.getAttribLocation(program, "aTextureCoord");
    +	  
    +    this.translationMatrix = gl.getUniformLocation(program, "translationMatrix");
    +    this.alpha = gl.getUniformLocation(program, "alpha");
    +  
    +	this.program = program;
    +}
    +
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_renderers_webgl_WebGLBatch.js.html b/docs/files/src_pixi_renderers_webgl_WebGLBatch.js.html index 3d14d09..0d6c2ab 100644 --- a/docs/files/src_pixi_renderers_webgl_WebGLBatch.js.html +++ b/docs/files/src_pixi_renderers_webgl_WebGLBatch.js.html @@ -2,12 +2,12 @@ - src/pixi/renderers/webgl/WebGLBatch.js - Pixi.JS - - - - - + src/pixi/renderers/webgl/WebGLBatch.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,19 +166,19 @@
    -

    File: src/pixi/renderers/webgl/WebGLBatch.js

    +

    File: src/pixi/renderers/webgl/WebGLBatch.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
     PIXI._batchs = [];
     
    -/**
    +/**
      * @private
    - */
    + */
     PIXI._getBatch = function(gl)
     {
     	if(PIXI._batchs.length == 0)
    @@ -167,18 +191,18 @@ PIXI._getBatch = function(gl)
     	}
     }
     
    -/**
    +/**
      * @private
    - */
    + */
     PIXI._returnBatch = function(batch)
     {
     	batch.clean();	
     	PIXI._batchs.push(batch);
     }
     
    -/**
    +/**
      * @private
    - */
    + */
     PIXI._restoreBatchs = function(gl)
     {
     	for (var i=0; i < PIXI._batchs.length; i++) 
    @@ -187,13 +211,18 @@ PIXI._restoreBatchs = function(gl)
     	};
     }
     
    -/**
    +/**
      * A WebGLBatch Enables a group of sprites to be drawn using the same settings.
    - * if a group of sprites all have the same baseTexture and blendMode then they can be grouped into a batch. All the sprites in a batch can then be drawn in one go by the GPU which is hugely efficient. ALL sprites in the webGL renderer are added to a batch even if the batch only contains one sprite. Batching is handled automatically by the webGL renderer. A good tip is: the smaller the number of batchs there are, the faster the webGL renderer will run. 
    + * if a group of sprites all have the same baseTexture and blendMode then they can be grouped into a batch.
    + * All the sprites in a batch can then be drawn in one go by the GPU which is hugely efficient. ALL sprites
    + * in the webGL renderer are added to a batch even if the batch only contains one sprite. Batching is handled
    + * automatically by the webGL renderer. A good tip is: the smaller the number of batchs there are, the faster
    + * the webGL renderer will run.
    + *
      * @class WebGLBatch
    - * @param an instance of the webGL context
    - * @return {PIXI.renderers.WebGLBatch} WebGLBatch {@link PIXI.renderers.WebGLBatch}
    - */
    + * @constructor
    + * @param gl {WebGLContext} an instance of the webGL context
    + */
     PIXI.WebGLBatch = function(gl)
     {
     	this.gl = gl;
    @@ -208,32 +237,34 @@ PIXI.WebGLBatch = function(gl)
     	this.dynamicSize = 1;
     }
     
    +// constructor
    +PIXI.WebGLBatch.prototype.constructor = PIXI.WebGLBatch;
     
    -// constructor
    -PIXI.WebGLBatch.constructor = PIXI.WebGLBatch;
    -
    -/**
    +/**
      * Cleans the batch so that is can be returned to an object pool and reused
    - */
    + *
    + * @method clean
    + */
     PIXI.WebGLBatch.prototype.clean = function()
     {
     	this.verticies = [];
     	this.uvs = [];
     	this.indices = [];
     	this.colors = [];
    -	//this.sprites = [];
     	this.dynamicSize = 1;
     	this.texture = null;
     	this.last = null;
     	this.size = 0;
    -	
     	this.head;
     	this.tail;
     }
     
    -/*
    - * recreates the buffers in the event of a context loss
    - */
    +/**
    + * Recreates the buffers in the event of a context loss
    + *
    + * @method restoreLostContext
    + * @param gl {WebGLContext}
    + */
     PIXI.WebGLBatch.prototype.restoreLostContext = function(gl)
     {
     	this.gl = gl;
    @@ -243,41 +274,43 @@ PIXI.WebGLBatch.prototype.restoreLostContext = function(gl)
     	this.colorBuffer =  gl.createBuffer();
     }
     
    -/**
    +/**
      * inits the batch's texture and blend mode based if the supplied sprite
    + *
      * @method init
    - * @param sprite {Sprite} the first sprite to be added to the batch. Only sprites with the same base texture and blend mode will be allowed to be added to this batch
    - */	
    + * @param sprite {Sprite} the first sprite to be added to the batch. Only sprites with
    + *		the same base texture and blend mode will be allowed to be added to this batch
    + */	
     PIXI.WebGLBatch.prototype.init = function(sprite)
     {
     	sprite.batch = this;
     	this.dirty = true;
     	this.blendMode = sprite.blendMode;
     	this.texture = sprite.texture.baseTexture;
    -//	this.sprites.push(sprite);
     	this.head = sprite;
     	this.tail = sprite;
     	this.size = 1;
    -	
    +
     	this.growBatch();
     }
     
    -/**
    +/**
      * inserts a sprite before the specified sprite
    + *
      * @method insertBefore
      * @param sprite {Sprite} the sprite to be added
      * @param nextSprite {nextSprite} the first sprite will be inserted before this sprite
    - */	
    + */	
     PIXI.WebGLBatch.prototype.insertBefore = function(sprite, nextSprite)
     {
     	this.size++;
    -	
    +
     	sprite.batch = this;
     	this.dirty = true;
     	var tempPrev = nextSprite.__prev;
     	nextSprite.__prev = sprite;
     	sprite.__next = nextSprite;
    -	
    +
     	if(tempPrev)
     	{
     		sprite.__prev = tempPrev;
    @@ -286,28 +319,27 @@ PIXI.WebGLBatch.prototype.insertBefore = function(sprite, nextSprite)
     	else
     	{
     		this.head = sprite;
    -		//this.head.__prev = null
     	}
     }
     
    -/**
    +/**
      * inserts a sprite after the specified sprite
    + *
      * @method insertAfter
      * @param sprite {Sprite} the sprite to be added
      * @param  previousSprite {Sprite} the first sprite will be inserted after this sprite
    - */	
    + */	
     PIXI.WebGLBatch.prototype.insertAfter = function(sprite, previousSprite)
     {
     	this.size++;
    -	
    -	
    +
     	sprite.batch = this;
     	this.dirty = true;
    -	
    +
     	var tempNext = previousSprite.__next;
     	previousSprite.__next = sprite;
     	sprite.__prev = previousSprite;
    -	
    +
     	if(tempNext)
     	{
     		sprite.__next = tempNext;
    @@ -317,18 +349,18 @@ PIXI.WebGLBatch.prototype.insertAfter = function(sprite, previousSprite)
     	{
     		this.tail = sprite
     	}
    -	
     }
     
    -/**
    +/**
      * removes a sprite from the batch
    + *
      * @method remove
      * @param sprite {Sprite} the sprite to be removed
    - */	
    + */	
     PIXI.WebGLBatch.prototype.remove = function(sprite)
     {
     	this.size--;
    -	
    +
     	if(this.size == 0)
     	{
     		sprite.batch = null;
    @@ -336,7 +368,7 @@ PIXI.WebGLBatch.prototype.remove = function(sprite)
     		sprite.__next = null;
     		return;
     	}
    -	
    +
     	if(sprite.__prev)
     	{
     		sprite.__prev.__next = sprite.__next;
    @@ -346,7 +378,7 @@ PIXI.WebGLBatch.prototype.remove = function(sprite)
     		this.head = sprite.__next;
     		this.head.__prev = null;
     	}
    -	
    +
     	if(sprite.__next)
     	{
     		sprite.__next.__prev = sprite.__prev;
    @@ -356,49 +388,40 @@ PIXI.WebGLBatch.prototype.remove = function(sprite)
     		this.tail = sprite.__prev;
     		this.tail.__next = null
     	}
    -	
    +
     	sprite.batch = null;
     	sprite.__next = null;
     	sprite.__prev = null;
     	this.dirty = true;
     }
     
    -/**
    +/**
      * Splits the batch into two with the specified sprite being the start of the new batch.
    + *
      * @method split
      * @param sprite {Sprite} the sprite that indicates where the batch should be split
      * @return {WebGLBatch} the new batch
    - */
    + */
     PIXI.WebGLBatch.prototype.split = function(sprite)
     {
    -	
    -	//console.log("Splitting batch :" + this.size)
    -//	console.log(sprite)
    -//	console.log("-------")
     	this.dirty = true;
    -	
    -	//var val = (this.tail == this.head)
    -	//console.log(val + " SAME?");
    -	var batch = new PIXI.WebGLBatch(this.gl)//PIXI._getBatch(this.gl);
    +
    +	var batch = new PIXI.WebGLBatch(this.gl);
     	batch.init(sprite);
     	batch.texture = this.texture;
     	batch.tail = this.tail;
    -	//console.log("id is " +batcheee.id)
    -	
    +
     	this.tail = sprite.__prev;
     	this.tail.__next = null;
    -	
    +
     	sprite.__prev = null;
    -	// return a splite batch!
    -	//sprite.__prev.__next = null;
    -	//sprite.__prev = null;
    -	
    -	
    -	// TODO this size is wrong!
    -	// need to recalculate :/ problem with a linked list!
    -	// unless it gets calculated in the "clean"?
    -	
    -	// need to loop through items as there is no way to know the length on a linked list :/
    +	// return a splite batch!
    +
    +	// TODO this size is wrong!
    +	// need to recalculate :/ problem with a linked list!
    +	// unless it gets calculated in the "clean"?
    +
    +	// need to loop through items as there is no way to know the length on a linked list :/
     	var tempSize = 0;
     	while(sprite)
     	{
    @@ -406,42 +429,45 @@ PIXI.WebGLBatch.prototype.split = function(sprite)
     		sprite.batch = batch;
     		sprite = sprite.__next;
     	}
    -	
    +
     	batch.size = tempSize;
     	this.size -= tempSize;
    -	
    +
     	return batch;
     }
     
    -/**
    +/**
      * Merges two batchs together
    + *
      * @method merge
      * @param batch {WebGLBatch} the batch that will be merged 
    - */
    + */
     PIXI.WebGLBatch.prototype.merge = function(batch)
     {
     	this.dirty = true;
    -	
    +
     	this.tail.__next = batch.head;
     	batch.head.__prev = this.tail;
    -	
    +
     	this.size += batch.size;
    -			
    +
     	this.tail = batch.tail;
    -	
    +
     	var sprite = batch.head;
     	while(sprite)
     	{
     		sprite.batch = this;
     		sprite = sprite.__next;
     	}
    -	
     }
     
    -/**
    - * Grows the size of the batch. As the elements in the batch cannot have a dynamic size this function is used to increase the size of the batch. It also creates a little extra room so that the batch does not need to be resized every time a sprite is added
    - * @methos growBatch
    - */
    +/**
    + * Grows the size of the batch. As the elements in the batch cannot have a dynamic size this
    + * function is used to increase the size of the batch. It also creates a little extra room so
    + * that the batch does not need to be resized every time a sprite is added
    + *
    + * @method growBatch
    + */
     PIXI.WebGLBatch.prototype.growBatch = function()
     {
     	var gl = this.gl;
    @@ -453,27 +479,27 @@ PIXI.WebGLBatch.prototype.growBatch = function()
     	{
     		this.dynamicSize = this.size * 1.5
     	}
    -	// grow verts
    +	// grow verts
     	this.verticies = new Float32Array(this.dynamicSize * 8);
    -	
    +
     	gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
     	gl.bufferData(gl.ARRAY_BUFFER,this.verticies , gl.DYNAMIC_DRAW);
    -	
    -	this.uvs  = new Float32Array( this.dynamicSize * 8 )  
    +
    +	this.uvs  = new Float32Array( this.dynamicSize * 8 );
     	gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer);
     	gl.bufferData(gl.ARRAY_BUFFER, this.uvs , gl.DYNAMIC_DRAW);
    -	
    +
     	this.dirtyUVS = true;
    -	
    -	this.colors  = new Float32Array( this.dynamicSize * 4 )  
    +
    +	this.colors  = new Float32Array( this.dynamicSize * 4 );
     	gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer);
     	gl.bufferData(gl.ARRAY_BUFFER, this.colors , gl.DYNAMIC_DRAW);
    -	
    +
     	this.dirtyColors = true;
    -	
    +
     	this.indices = new Uint16Array(this.dynamicSize * 6); 
    -	var length = this.indices.length/6;
    -	
    +	var length = this.indices.length/6;
    +
     	for (var i=0; i < length; i++) 
     	{
     	    var index2 = i * 6;
    @@ -485,215 +511,208 @@ PIXI.WebGLBatch.prototype.growBatch = function()
     		this.indices[index2 + 4] = index3 + 2;
     		this.indices[index2 + 5] = index3 + 3;
     	};
    -	
    +
     	gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
         gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW);
    -	
     }
     
    -/**
    +/**
      * Refresh's all the data in the batch and sync's it with the webGL buffers
    + *
      * @method refresh
    - */
    + */
     PIXI.WebGLBatch.prototype.refresh = function()
     {
     	var gl = this.gl;
    -	
    +
     	if (this.dynamicSize < this.size)
     	{
     		this.growBatch();
     	}
     
     	var indexRun = 0;
    -	var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index
    -	var a, b, c, d, tx, ty
    -	
    -	var displayObject = this.head
    +	var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index;
    +	var a, b, c, d, tx, ty;
    +
    +	var displayObject = this.head;
     
     	while(displayObject)
     	{
     		index = indexRun * 8;
    -		
    +
     		var texture = displayObject.texture;
    -			
    +
     		var frame = texture.frame;
     		var tw = texture.baseTexture.width;
     		var th = texture.baseTexture.height;
    -		
    -		this.uvs[index + 0] = frame.x / tw;
    -		this.uvs[index +1] = frame.y / th;
    -		
    -		this.uvs[index +2] = (frame.x + frame.width) / tw;
    -		this.uvs[index +3] = frame.y / th;
    -		
    -		this.uvs[index +4] = (frame.x + frame.width) / tw;
    -		this.uvs[index +5] = (frame.y + frame.height) / th; 
    -		
    -		this.uvs[index +6] = frame.x / tw;
    -		this.uvs[index +7] = (frame.y + frame.height) / th;
    -		
    +
    +		this.uvs[index + 0] = frame.x / tw;
    +		this.uvs[index +1] = frame.y / th;
    +
    +		this.uvs[index +2] = (frame.x + frame.width) / tw;
    +		this.uvs[index +3] = frame.y / th;
    +
    +		this.uvs[index +4] = (frame.x + frame.width) / tw;
    +		this.uvs[index +5] = (frame.y + frame.height) / th; 
    +
    +		this.uvs[index +6] = frame.x / tw;
    +		this.uvs[index +7] = (frame.y + frame.height) / th;
    +
     		displayObject.updateFrame = false;
    -		
    +
     		colorIndex = indexRun * 4;
     		this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha;
    -		
    +
     		displayObject = displayObject.__next;
    -		
    +
     		indexRun ++;
     	}
    -	
    +
     	this.dirtyUVS = true;
     	this.dirtyColors = true;
     }
     
    -/**
    +/**
      * Updates all the relevant geometry and uploads the data to the GPU
    + *
      * @method update
    - */
    + */
     PIXI.WebGLBatch.prototype.update = function()
     {
     	var gl = this.gl;
     	var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, index2, index3
    -	
    +
     	var a, b, c, d, tx, ty;
    -	
    +
     	var indexRun = 0;
    -	
    +
     	var displayObject = this.head;
    +	var verticies = this.verticies;
    +	var uvs = this.uvs;
    +	var colors = this.colors;
     	
     	while(displayObject)
     	{
    -		if(displayObject.worldVisible)
    +		if(displayObject.vcount === PIXI.visibleCount)
     		{
     			width = displayObject.texture.frame.width;
     			height = displayObject.texture.frame.height;
    -			
    -			// TODO trim??
    -			aX = displayObject.anchor.x;// - displayObject.texture.trim.x
    -			aY = displayObject.anchor.y; //- displayObject.texture.trim.y
    +
    +			// TODO trim??
    +			aX = displayObject.anchor.x;// - displayObject.texture.trim.x
    +			aY = displayObject.anchor.y; //- displayObject.texture.trim.y
     			w0 = width * (1-aX);
     			w1 = width * -aX;
    -			 
    +
     			h0 = height * (1-aY);
     			h1 = height * -aY;
    -			 
    +
     			index = indexRun * 8;
    -	
    +
     			worldTransform = displayObject.worldTransform;
    -		
    +
     			a = worldTransform[0];
     			b = worldTransform[3];
     			c = worldTransform[1];
     			d = worldTransform[4];
     			tx = worldTransform[2];
     			ty = worldTransform[5];
    -		
    -			this.verticies[index + 0 ] = a * w1 + c * h1 + tx; 
    -			this.verticies[index + 1 ] = d * h1 + b * w1 + ty;
    -			 
    -			this.verticies[index + 2 ] = a * w0 + c * h1 + tx; 
    -			this.verticies[index + 3 ] = d * h1 + b * w0 + ty; 
    -			
    -			this.verticies[index + 4 ] = a * w0 + c * h0 + tx; 
    -			this.verticies[index + 5 ] = d * h0 + b * w0 + ty; 
    -			
    -			this.verticies[index + 6] =  a * w1 + c * h0 + tx; 
    -			this.verticies[index + 7] =  d * h0 + b * w1 + ty; 
    -			
    -			
    +
    +			verticies[index + 0 ] = a * w1 + c * h1 + tx; 
    +			verticies[index + 1 ] = d * h1 + b * w1 + ty;
    +
    +			verticies[index + 2 ] = a * w0 + c * h1 + tx; 
    +			verticies[index + 3 ] = d * h1 + b * w0 + ty; 
    +
    +			verticies[index + 4 ] = a * w0 + c * h0 + tx; 
    +			verticies[index + 5 ] = d * h0 + b * w0 + ty; 
    +
    +			verticies[index + 6] =  a * w1 + c * h0 + tx; 
    +			verticies[index + 7] =  d * h0 + b * w1 + ty; 
    +
     			if(displayObject.updateFrame || displayObject.texture.updateFrame)
     			{
     				this.dirtyUVS = true;
    -				
    +
     				var texture = displayObject.texture;
    -				
    +
     				var frame = texture.frame;
     				var tw = texture.baseTexture.width;
     				var th = texture.baseTexture.height;
    -				
    -				this.uvs[index + 0] = frame.x / tw;
    -				this.uvs[index +1] = frame.y / th;
    -				
    -				this.uvs[index +2] = (frame.x + frame.width) / tw;
    -				this.uvs[index +3] = frame.y / th;
    -				
    -				this.uvs[index +4] = (frame.x + frame.width) / tw;
    -				this.uvs[index +5] = (frame.y + frame.height) / th; 
    -				
    -				this.uvs[index +6] = frame.x / tw;
    -				this.uvs[index +7] = (frame.y + frame.height) / th;
    -				
    +
    +				uvs[index + 0] = frame.x / tw;
    +				uvs[index +1] = frame.y / th;
    +
    +				uvs[index +2] = (frame.x + frame.width) / tw;
    +				uvs[index +3] = frame.y / th;
    +
    +				uvs[index +4] = (frame.x + frame.width) / tw;
    +				uvs[index +5] = (frame.y + frame.height) / th; 
    +
    +				uvs[index +6] = frame.x / tw;
    +				uvs[index +7] = (frame.y + frame.height) / th;
    +
     				displayObject.updateFrame = false;
     			}
    -			
    -			// TODO this probably could do with some optimisation....
    +
    +			// TODO this probably could do with some optimisation....
     			if(displayObject.cacheAlpha != displayObject.worldAlpha)
     			{
     				displayObject.cacheAlpha = displayObject.worldAlpha;
    -				
    +
     				var colorIndex = indexRun * 4;
    -				this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha;
    +				colors[colorIndex] = colors[colorIndex + 1] = colors[colorIndex + 2] = colors[colorIndex + 3] = displayObject.worldAlpha;
     				this.dirtyColors = true;
     			}
     		}
     		else
     		{
     			index = indexRun * 8;
    -			
    -			this.verticies[index + 0 ] = 0;
    -			this.verticies[index + 1 ] = 0;
    -			 
    -			this.verticies[index + 2 ] = 0;
    -			this.verticies[index + 3 ] = 0;
    -			
    -			this.verticies[index + 4 ] = 0;
    -			this.verticies[index + 5 ] = 0;
    -			
    -			this.verticies[index + 6] = 0;
    -			this.verticies[index + 7] = 0;
    +
    +			verticies[index + 0 ] = verticies[index + 1 ] = verticies[index + 2 ] = verticies[index + 3 ] = verticies[index + 4 ] = verticies[index + 5 ] = verticies[index + 6] = 	verticies[index + 7] = 0;
     		}
    -		
    +
     		indexRun++;
     		displayObject = displayObject.__next;
        }
     }
     
    -/**
    +/**
      * Draws the batch to the frame buffer
    + *
      * @method render
    - */
    + */
     PIXI.WebGLBatch.prototype.render = function(start, end)
     {
    -	
    -//	console.log(start + " :: " + end + " : " + this.size);
     	start = start || 0;
    -	//end = end || this.size;
    -	if(end == undefined)end = this.size;
     
    +	if(end == undefined)end = this.size;
    +	
     	if(this.dirty)
     	{
     		this.refresh();
     		this.dirty = false;
    -		
     	}
    -	
    -	
    +
     	if (this.size == 0)return;
    -	
    +
     	this.update();
     	var gl = this.gl;
    +
    +	//TODO optimize this!
    +
    +	var shaderProgram = PIXI.defaultShader;
     	
    -	//TODO optimize this!
    -	
    -	var shaderProgram = PIXI.shaderProgram;
    -	gl.useProgram(shaderProgram);
    -	
    -	// update the verts..
    +	//gl.useProgram(shaderProgram);
    +
    +	// update the verts..
     	gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
    -	// ok..
    +	// ok..
     	gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.verticies)
    -    gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
    -	// update the uvs
    +    gl.vertexAttribPointer(shaderProgram.aVertexPosition, 2, gl.FLOAT, false, 0, 0);
    +	// update the uvs
    +	//var isDefault = (shaderProgram == PIXI.shaderProgram)
    +
        	gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer);
     
         if(this.dirtyUVS)
    @@ -701,13 +720,13 @@ PIXI.WebGLBatch.prototype.render = function(start, end)
         	this.dirtyUVS = false;
         	gl.bufferSubData(gl.ARRAY_BUFFER,  0, this.uvs);
         }
    -    
    -    gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0);
    -	
    +
    +    gl.vertexAttribPointer(shaderProgram.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
    +
         gl.activeTexture(gl.TEXTURE0);
         gl.bindTexture(gl.TEXTURE_2D, this.texture._glTexture);
    -	
    -	// update color!
    +
    +	// update color!
     	gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer);
     
     	if(this.dirtyColors)
    @@ -715,21 +734,17 @@ PIXI.WebGLBatch.prototype.render = function(start, end)
         	this.dirtyColors = false;
         	gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.colors);
     	}
    -	
    +
         gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0);
    -	
    -	// dont need to upload!
    +	// dont need to upload!
         gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
    -	
    -	
    -	//var startIndex = 0//1;
    +
     	var len = end - start;
    -	// console.log(this.size)
    -    // DRAW THAT this!
    +
    +    // DRAW THAT this!
         gl.drawElements(gl.TRIANGLES, len * 6, gl.UNSIGNED_SHORT, start * 2 * 6 );
     }
     
    -
         
    @@ -739,13 +754,13 @@ PIXI.WebGLBatch.prototype.render = function(start, end)
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_renderers_webgl_WebGLFilterManager.js.html b/docs/files/src_pixi_renderers_webgl_WebGLFilterManager.js.html new file mode 100644 index 0000000..d109a7c --- /dev/null +++ b/docs/files/src_pixi_renderers_webgl_WebGLFilterManager.js.html @@ -0,0 +1,708 @@ + + + + + src/pixi/renderers/webgl/WebGLFilterManager.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/renderers/webgl/WebGLFilterManager.js

    + +
    +
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
    +
    +
    +PIXI.WebGLFilterManager = function()
    +{
    +	this.filterStack = [];
    +	this.texturePool = [];
    +	
    +	this.offsetX = 0;
    +	this.offsetY = 0;
    +	
    +	this.initShaderBuffers();
    +}
    +
    +// API
    +
    +PIXI.WebGLFilterManager.prototype.begin = function(projection, buffer)
    +{
    +	this.width = projection.x * 2;
    +	this.height = -projection.y * 2;
    +	this.buffer = buffer;
    +}
    +
    +PIXI.WebGLFilterManager.prototype.pushFilter = function(filterBlock)
    +{
    +	var gl = PIXI.gl;
    +
    +	// filter program
    +	// OPTIMISATION - the first filter is free if its a simple color change?
    +	this.filterStack.push(filterBlock);
    +
    +	var filter = filterBlock.filterPasses[0];
    +
    +	
    +
    +	this.offsetX += filterBlock.target.filterArea.x;
    +	this.offsetY += filterBlock.target.filterArea.y;
    +	
    +	
    +	
    +	
    +	
    +	var texture = this.texturePool.pop();
    +	if(!texture)texture = new PIXI.FilterTexture(this.width, this.height);
    +	
    +	gl.bindTexture(gl.TEXTURE_2D,  texture.texture);
    +	
    +	this.getBounds(filterBlock.target);
    +		
    +	// addpadding?
    +	//displayObject.filterArea.x
    +
    +	var filterArea = filterBlock.target.filterArea;
    +
    +	var padidng = filter.padding;
    +	filterArea.x -= padidng;
    +	filterArea.y -= padidng;
    +	filterArea.width += padidng * 2;
    +	filterArea.height += padidng * 2;
    +
    +	// cap filter to screen size..
    +	if(filterArea.x < 0)filterArea.x = 0;	
    +	if(filterArea.width > this.width)filterArea.width = this.width;
    +	if(filterArea.y < 0)filterArea.y = 0;	
    +	if(filterArea.height > this.height)filterArea.height = this.height;
    +
    +
    +	//gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA,  filterArea.width, filterArea.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
    +	gl.bindFramebuffer(gl.FRAMEBUFFER, texture.frameBuffer);
    +   
    +  // console.log(filterArea)
    +	// set view port
    +	gl.viewport(0, 0, filterArea.width, filterArea.height);	
    +	
    +	PIXI.projection.x = filterArea.width/2;
    +	PIXI.projection.y = -filterArea.height/2;
    +	
    +	PIXI.offset.x = -filterArea.x; 
    +	PIXI.offset.y = -filterArea.y;
    +
    +	//console.log(PIXI.defaultShader.projectionVector)
    +	// update projection
    +	gl.uniform2f(PIXI.defaultShader.projectionVector, filterArea.width/2, -filterArea.height/2);
    +	gl.uniform2f(PIXI.defaultShader.offsetVector, -filterArea.x, -filterArea.y);
    +	//PIXI.primitiveProgram
    +
    +	gl.colorMask(true, true, true, true); 
    +	gl.clearColor(0,0,0, 0);     
    +	gl.clear(gl.COLOR_BUFFER_BIT);
    +	
    +	//filter.texture = texture;
    +	filterBlock._glFilterTexture = texture;
    +
    +	//console.log("PUSH")
    +}
    +
    +
    +PIXI.WebGLFilterManager.prototype.popFilter = function()
    +{
    +	
    +	var gl = PIXI.gl;
    +	
    +	var filterBlock = this.filterStack.pop();
    +
    +
    +
    +	var filterArea = filterBlock.target.filterArea;
    +
    +	var texture = filterBlock._glFilterTexture;
    +
    +	if(filterBlock.filterPasses.length > 1)
    +	{
    +		gl.viewport(0, 0, filterArea.width, filterArea.height);
    +
    +		gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
    +	
    +		this.vertexArray[0] = 0;
    +		this.vertexArray[1] = filterArea.height;
    +		
    +		this.vertexArray[2] = filterArea.width;
    +		this.vertexArray[3] = filterArea.height;
    +		
    +		this.vertexArray[4] = 0;
    +		this.vertexArray[5] = 0;
    +		
    +		this.vertexArray[6] = filterArea.width;
    +		this.vertexArray[7] = 0;
    +
    +
    +		gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.vertexArray);
    +
    +	
    +		gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer);
    +		// nnow set the uvs..
    +		this.uvArray[2] = filterArea.width/this.width;
    +		this.uvArray[5] = filterArea.height/this.height;
    +		this.uvArray[6] = filterArea.width/this.width;
    +		this.uvArray[7] = filterArea.height/this.height;
    +		
    +		gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray);
    +
    +		var inputTexture = texture;
    +		var outputTexture = this.texturePool.pop();
    +		if(!outputTexture)outputTexture = new PIXI.FilterTexture(this.width, this.height);
    +		
    +		// need to clear this FBO as it may have some left over elements from a prvious filter.
    +		gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer );     
    +		gl.clear(gl.COLOR_BUFFER_BIT);
    +	 
    +		gl.disable(gl.BLEND);
    +		
    +		for (var i = 0; i < filterBlock.filterPasses.length-1; i++) 
    +		{
    +			var filterPass = filterBlock.filterPasses[i];
    +	
    +			gl.bindFramebuffer(gl.FRAMEBUFFER, outputTexture.frameBuffer );
    +			
    +			// set texture
    +		    gl.activeTexture(gl.TEXTURE0);
    +			gl.bindTexture(gl.TEXTURE_2D, inputTexture.texture);
    +			
    +			// draw texture..
    +			//filterPass.applyFilterPass(filterArea.width, filterArea.height);
    +			this.applyFilterPass(filterPass, filterArea, filterArea.width, filterArea.height);
    +
    +			// swap the textures..
    +			var temp = inputTexture;
    +			inputTexture = outputTexture;
    +			outputTexture = temp;
    +			
    +		};
    +
    +		gl.enable(gl.BLEND);
    +
    +		texture = inputTexture;
    +		this.texturePool.push(outputTexture);
    +	}
    +
    +	var filter = filterBlock.filterPasses[filterBlock.filterPasses.length-1];
    +	
    +	this.offsetX -= filterArea.x;
    +	this.offsetY -= filterArea.y;
    +
    +	
    +	var sizeX = this.width;
    +	var sizeY = this.height;
    +	
    +	var offsetX = 0;
    +	var offsetY = 0;
    +	
    +	var buffer = this.buffer;
    +	
    +	// time to render the filters texture to the previous scene
    +	if(this.filterStack.length === 0)
    +	{
    +		gl.colorMask(true, true, true, this.buffer); 
    +	}
    +	else
    +	{
    +		var currentFilter = this.filterStack[this.filterStack.length-1];
    +		var filterArea = currentFilter.target.filterArea;
    +		
    +		sizeX = filterArea.width;
    +		sizeY = filterArea.height;
    +		
    +		offsetX = filterArea.x;
    +		offsetY = filterArea.y;
    +		
    +		buffer =  currentFilter._glFilterTexture.frameBuffer;
    +	}
    +	
    +	
    +
    +	// TODO need toremove thease global elements..
    +	PIXI.projection.x = sizeX/2;
    +	PIXI.projection.y = -sizeY/2;
    +
    +	PIXI.offset.x = offsetX;
    +	PIXI.offset.y = offsetY; 
    +	
    +
    +	var filterArea =  filterBlock.target.filterArea;
    +	var x = filterArea.x-offsetX;
    +	var y = filterArea.y-offsetY;
    +	
    +	// update the buffers..	
    +	// make sure to flip the y!
    +	gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
    +	
    +	this.vertexArray[0] = x;
    +	this.vertexArray[1] = y + filterArea.height;
    +	
    +	this.vertexArray[2] = x + filterArea.width;
    +	this.vertexArray[3] = y + filterArea.height;
    +	
    +	this.vertexArray[4] = x;
    +	this.vertexArray[5] = y;
    +	
    +	this.vertexArray[6] = x + filterArea.width;
    +	this.vertexArray[7] = y;
    +
    +	gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.vertexArray);
    +	
    +	gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer);
    +
    +	this.uvArray[2] = filterArea.width/this.width;
    +	this.uvArray[5] = filterArea.height/this.height;
    +	this.uvArray[6] = filterArea.width/this.width;
    +	this.uvArray[7] = filterArea.height/this.height;
    +	
    +	gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvArray);
    +
    +	gl.viewport(0, 0, sizeX, sizeY);	
    +	// bind the buffer
    +	gl.bindFramebuffer(gl.FRAMEBUFFER, buffer );
    +	
    +	// set texture
    +    gl.activeTexture(gl.TEXTURE0);
    +	gl.bindTexture(gl.TEXTURE_2D, texture.texture);
    +	
    +	// apply!
    +	//filter.applyFilterPass(sizeX, sizeY);
    +	this.applyFilterPass(filter, filterArea, sizeX, sizeY);
    +
    +	// now restore the regular shader..
    +    gl.useProgram(PIXI.defaultShader.program);
    +	gl.uniform2f(PIXI.defaultShader.projectionVector, sizeX/2, -sizeY/2);
    +	gl.uniform2f(PIXI.defaultShader.offsetVector, -offsetX, -offsetY);
    +
    +	// return the texture to the pool
    +	this.texturePool.push(texture);
    +	filterBlock._glFilterTexture = null;	
    +}
    +
    +PIXI.WebGLFilterManager.prototype.applyFilterPass = function(filter, filterArea, width, height)
    +{
    +	// use program
    +	var gl = PIXI.gl;
    +
    +	if(!filter.shader)
    +	{
    +		var shader = new PIXI.PixiShader();
    +				
    +		shader.fragmentSrc = filter.fragmentSrc;
    +		shader.uniforms = filter.uniforms;
    +		shader.init();
    +		
    +		filter.shader = shader;
    +	}
    +
    +	var shader = filter.shader;
    +	
    +	// set the shader
    +	gl.useProgram(shader.program);
    +
    +	gl.uniform2f(shader.projectionVector, width/2, -height/2);
    +	gl.uniform2f(shader.offsetVector, 0,0)
    +
    +	if(filter.uniforms.dimensions)
    +	{
    +		//console.log(filter.uniforms.dimensions)
    +		filter.uniforms.dimensions.value[0] = this.width;//width;
    +		filter.uniforms.dimensions.value[1] = this.height;//height;
    +		filter.uniforms.dimensions.value[2] = this.vertexArray[0];
    +		filter.uniforms.dimensions.value[3] = this.vertexArray[5];//filterArea.height;
    +	//	console.log(this.vertexArray[5])
    +	}
    +
    +	shader.syncUniforms();
    +	
    +	gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
    +    gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, 0, 0);
    +   
    +   	gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer);
    +    gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
    +	
    +    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
    +    
    +	// draw the filter...
    +    gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
    +}
    +
    +PIXI.WebGLFilterManager.prototype.initShaderBuffers = function()
    +{
    +	var gl = PIXI.gl;
    +	
    +	// create some buffers
    +	this.vertexBuffer = gl.createBuffer();	
    +	this.uvBuffer = gl.createBuffer();
    +	this.indexBuffer = gl.createBuffer();
    +	
    +	// bind and upload the vertexs..
    +	// keep a refferance to the vertexFloatData..
    +	this.vertexArray = new Float32Array([0.0, 0.0, 
    +								         1.0, 0.0, 
    +								         0.0, 1.0, 
    +								         1.0, 1.0]);
    +	
    +	gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
    +	gl.bufferData(
    +    gl.ARRAY_BUFFER, 
    +    this.vertexArray, 
    +    gl.STATIC_DRAW);
    +    
    +    
    +    // bind and upload the uv buffer
    +	this.uvArray = new Float32Array([0.0, 0.0, 
    +								     1.0, 0.0, 
    +								     0.0, 1.0, 
    +								     1.0, 1.0]);
    +								         
    +	gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer);
    +	gl.bufferData(
    +    gl.ARRAY_BUFFER, 
    +    this.uvArray, 
    +    gl.STATIC_DRAW);
    +    
    +	// bind and upload the index
    +	gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
    +	gl.bufferData(
    +    gl.ELEMENT_ARRAY_BUFFER, 
    +    new Uint16Array([0, 1, 2, 1, 3, 2]), 
    +    gl.STATIC_DRAW);
    +}
    +
    +PIXI.WebGLFilterManager.prototype.getBounds = function(displayObject)
    +{
    +	// time to get the width and height of the object!
    +	var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, doTest;
    +	var a, b, c, d, tx, ty, x1, x2, x3, x4, y1, y2, y3, y4;
    +
    +	var tempObject = displayObject.first;
    +	var testObject = displayObject.last._iNext;
    +	
    +	var maxX = -Infinity;
    +	var maxY = -Infinity;
    +	
    +	var minX = Infinity;
    +	var minY = Infinity;
    +	
    +	do	
    +	{
    +		// TODO can be optimized! - what if there is no scale / rotation?
    +		
    +		if(tempObject.visible)
    +		{
    +			if(tempObject instanceof PIXI.Sprite)
    +			{
    +				width = tempObject.texture.frame.width;
    +				height = tempObject.texture.frame.height;
    +
    +				// TODO trim??
    +				aX = tempObject.anchor.x;
    +				aY = tempObject.anchor.y;
    +				w0 = width * (1-aX);
    +				w1 = width * -aX;
    +
    +				h0 = height * (1-aY);
    +				h1 = height * -aY;
    +
    +				doTest = true;
    +			}
    +			else if(tempObject instanceof PIXI.Graphics)
    +			{
    +				tempObject.updateFilterBounds();
    +
    +				var bounds = tempObject.bounds;
    +
    +				width = bounds.width;
    +				height = bounds.height;
    +
    +				w0 = bounds.x
    +				w1 = bounds.x + bounds.width;
    +
    +				h0 = bounds.y
    +				h1 = bounds.y + bounds.height;
    +
    +				doTest = true;	
    +			}
    +		}
    +		
    +		if(doTest)
    +		{
    +			worldTransform = tempObject.worldTransform;
    +
    +			a = worldTransform[0];
    +			b = worldTransform[3];
    +			c = worldTransform[1];
    +			d = worldTransform[4];
    +			tx = worldTransform[2];
    +			ty = worldTransform[5];
    +
    +			x1 = a * w1 + c * h1 + tx; 
    +			y1 = d * h1 + b * w1 + ty;
    +
    +			x2 = a * w0 + c * h1 + tx; 
    +			y2 = d * h1 + b * w0 + ty; 
    +
    +			x3 = a * w0 + c * h0 + tx; 
    +			y3 = d * h0 + b * w0 + ty; 
    +
    +			x4 =  a * w1 + c * h0 + tx; 
    +			y4 =  d * h0 + b * w1 + ty; 
    +
    +			minX = x1 < minX ? x1 : minX;
    +			minX = x2 < minX ? x2 : minX;
    +			minX = x3 < minX ? x3 : minX;
    +			minX = x4 < minX ? x4 : minX;
    +			
    +			minY = y1 < minY ? y1 : minY;
    +			minY = y2 < minY ? y2 : minY;
    +			minY = y3 < minY ? y3 : minY;
    +			minY = y4 < minY ? y4 : minY;
    +			
    +			maxX = x1 > maxX ? x1 : maxX;
    +			maxX = x2 > maxX ? x2 : maxX;
    +			maxX = x3 > maxX ? x3 : maxX;
    +			maxX = x4 > maxX ? x4 : maxX;
    +			
    +			maxY = y1 > maxY ? y1 : maxY;
    +			maxY = y2 > maxY ? y2 : maxY;
    +			maxY = y3 > maxY ? y3 : maxY;
    +			maxY = y4 > maxY ? y4 : maxY;
    +		}
    +
    +		doTest = false;
    +		tempObject = tempObject._iNext;
    +
    +	}
    +	while(tempObject != testObject)
    +	
    +	// maximum bounds is the size of the screen..
    +	//minX = minX > 0 ? minX : 0;
    +	//minY = minY > 0 ? minY : 0;
    +
    +	displayObject.filterArea.x = minX;
    +	displayObject.filterArea.y = minY;
    +
    +//	console.log(maxX+ " : " + minX)
    +	displayObject.filterArea.width = maxX - minX;
    +	displayObject.filterArea.height = maxY - minY;
    +}
    +
    +PIXI.FilterTexture = function(width, height)
    +{
    +	var gl = PIXI.gl;
    +	
    +    // next time to create a frame buffer and texture
    +	this.frameBuffer = gl.createFramebuffer();
    +    this.texture = gl.createTexture();
    +
    +    gl.bindTexture(gl.TEXTURE_2D,  this.texture);
    +    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
    +	gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
    +	gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
    +	gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
    +	gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer );
    +	
    +	gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer );
    +	gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture, 0);
    +	
    +	this.resize(width, height);
    +}
    +
    +PIXI.FilterTexture.prototype.resize = function(width, height)
    +{
    +	this.width = width;
    +	this.height = height;
    +
    +	var gl = PIXI.gl;
    +
    +	gl.bindTexture(gl.TEXTURE_2D,  this.texture);
    +	gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA,  width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
    +	
    +}
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_renderers_webgl_WebGLGraphics.js.html b/docs/files/src_pixi_renderers_webgl_WebGLGraphics.js.html index 0240783..9279cb9 100644 --- a/docs/files/src_pixi_renderers_webgl_WebGLGraphics.js.html +++ b/docs/files/src_pixi_renderers_webgl_WebGLGraphics.js.html @@ -2,12 +2,12 @@ - src/pixi/renderers/webgl/WebGLGraphics.js - Pixi.JS - - - - - + src/pixi/renderers/webgl/WebGLGraphics.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,28 +166,35 @@
    -

    File: src/pixi/renderers/webgl/WebGLGraphics.js

    +

    File: src/pixi/renderers/webgl/WebGLGraphics.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -
    -
    -/**
    +/**
      * A set of functions used by the webGL renderer to draw the primitive graphics data
    - * @class CanvasGraphics 
    - */
    + *
    + * @class CanvasGraphics
    + */
     PIXI.WebGLGraphics = function()
     {
     	
     }
     
    +/**
    + * Renders the graphics object
    + *
    + * @static
    + * @private
    + * @method renderGraphics
    + * @param graphics {Graphics}
    + * @param projection {Object}
    + */
     PIXI.WebGLGraphics.renderGraphics = function(graphics, projection)
     {
    -	
     	var gl = PIXI.gl;
     	
     	if(!graphics._webGL)graphics._webGL = {points:[], indices:[], lastIndex:0, 
    @@ -187,42 +218,52 @@ PIXI.WebGLGraphics.renderGraphics = function(graphics, projection)
     		PIXI.WebGLGraphics.updateGraphics(graphics);
     	}
     	
    -	
     	PIXI.activatePrimitiveShader();
     	
    -	// This  could be speeded up fo sure!
    +	// This  could be speeded up fo sure!
     	var m = PIXI.mat3.clone(graphics.worldTransform);
     	
     	PIXI.mat3.transpose(m);
     	
    -	// set the matrix transform for the 
    +	// set the matrix transform for the 
      	gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
    +
    + 	gl.uniformMatrix3fv(PIXI.primitiveShader.translationMatrix, false, m);
      	
    - 	gl.uniformMatrix3fv(PIXI.primitiveProgram.translationMatrix, false, m);
    - 	
    -	gl.uniform2f(PIXI.primitiveProgram.projectionVector, projection.x, projection.y);
    +	gl.uniform2f(PIXI.primitiveShader.projectionVector, projection.x, -projection.y);
    +	gl.uniform2f(PIXI.primitiveShader.offsetVector, -PIXI.offset.x, -PIXI.offset.y);
     	
    -	gl.uniform1f(PIXI.primitiveProgram.alpha, graphics.worldAlpha);
    +	gl.uniform1f(PIXI.primitiveShader.alpha, graphics.worldAlpha);
     
     	gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer);
     	
    -	// WHY DOES THIS LINE NEED TO BE THERE???
    -	gl.vertexAttribPointer(PIXI.shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
    -	// its not even used.. but need to be set or it breaks?
    -	// only on pc though..
    +	// WHY DOES THIS LINE NEED TO BE THERE???
    +	//gl.vertexAttribPointer(PIXI.shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
    +	// its not even used.. but need to be set or it breaks?
    +	// only on pc though..
     	
    -	gl.vertexAttribPointer(PIXI.primitiveProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 4 * 6, 0);
    -	gl.vertexAttribPointer(PIXI.primitiveProgram.colorAttribute, 4, gl.FLOAT, false,4 * 6, 2 * 4);
    +	gl.vertexAttribPointer(PIXI.primitiveShader.aVertexPosition, 2, gl.FLOAT, false, 4 * 6, 0);
    +	gl.vertexAttribPointer(PIXI.primitiveShader.colorAttribute, 4, gl.FLOAT, false,4 * 6, 2 * 4);
     	
    -	// set the index buffer!
    +	// set the index buffer!
     	gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer);
     	
     	gl.drawElements(gl.TRIANGLE_STRIP,  graphics._webGL.indices.length, gl.UNSIGNED_SHORT, 0 );
     	
    -	// return to default shader...
    -	PIXI.activateDefaultShader();
    +	PIXI.deactivatePrimitiveShader();
    +	
    +	// return to default shader...
    +//	PIXI.activateShader(PIXI.defaultShader);
     }
     
    +/**
    + * Updates the graphics object
    + *
    + * @static
    + * @private
    + * @method updateGraphics
    + * @param graphics {Graphics}
    + */
     PIXI.WebGLGraphics.updateGraphics = function(graphics)
     {
     	for (var i=graphics._webGL.lastIndex; i < graphics.graphicsData.length; i++) 
    @@ -267,12 +308,20 @@ PIXI.WebGLGraphics.updateGraphics = function(graphics)
         gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.glIndicies, gl.STATIC_DRAW);
     }
     
    -
    +/**
    + * Builds a rectangle to draw
    + *
    + * @static
    + * @private
    + * @method buildRectangle
    + * @param graphics {Graphics}
    + * @param webGLData {Object}
    + */
     PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData)
     {
    -	// --- //
    -	// need to convert points to a nice regular data
    -	// 
    +	// --- //
    +	// need to convert points to a nice regular data
    +	// 
     	var rectData = graphicsData.points;
     	var x = rectData[0];
     	var y = rectData[1];
    @@ -292,9 +341,9 @@ PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData)
     		var verts = webGLData.points;
     		var indices = webGLData.indices;
     	
    -		var vertPos = verts.length/6;
    +		var vertPos = verts.length/6;
     		
    -		// start
    +		// start
     		verts.push(x, y);
     		verts.push(r, g, b, alpha);
     		
    @@ -307,7 +356,7 @@ PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData)
     		verts.push(x + width, y + height);
     		verts.push(r, g, b, alpha);
     		
    -		// insert 2 dead triangles..
    +		// insert 2 dead triangles..
     		indices.push(vertPos, vertPos, vertPos+1, vertPos+2, vertPos+3, vertPos+3)
     	}
     	
    @@ -324,11 +373,20 @@ PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData)
     	
     }
     
    +/**
    + * Builds a circle to draw
    + *
    + * @static
    + * @private
    + * @method buildCircle
    + * @param graphics {Graphics}
    + * @param webGLData {Object}
    + */
     PIXI.WebGLGraphics.buildCircle = function(graphicsData, webGLData)
     {
    -	// --- //
    -	// need to convert points to a nice regular data
    -	// 
    +	// --- //
    +	// need to convert points to a nice regular data
    +	// 
     	var rectData = graphicsData.points;
     	var x = rectData[0];
     	var y = rectData[1];
    @@ -336,7 +394,7 @@ PIXI.WebGLGraphics.buildCircle = function(graphicsData, webGLData)
     	var height = rectData[3];
     	
     	var totalSegs = 40;
    -	var seg = (Math.PI * 2) / totalSegs ;
    +	var seg = (Math.PI * 2) / totalSegs ;
     		
     	if(graphicsData.fill)
     	{
    @@ -350,7 +408,7 @@ PIXI.WebGLGraphics.buildCircle = function(graphicsData, webGLData)
     		var verts = webGLData.points;
     		var indices = webGLData.indices;
     	
    -		var vecPos = verts.length/6;
    +		var vecPos = verts.length/6;
     		
     		indices.push(vecPos);
     		
    @@ -383,19 +441,28 @@ PIXI.WebGLGraphics.buildCircle = function(graphicsData, webGLData)
     	
     }
     
    +/**
    + * Builds a line to draw
    + *
    + * @static
    + * @private
    + * @method buildLine
    + * @param graphics {Graphics}
    + * @param webGLData {Object}
    + */
     PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData)
     {
    -	// TODO OPTIMISE!
    +	// TODO OPTIMISE!
     	
     	var wrap = true;
     	var points = graphicsData.points;
     	if(points.length == 0)return;
     	
    -	// get first and last point.. figure out the middle!
    +	// get first and last point.. figure out the middle!
     	var firstPoint = new PIXI.Point( points[0], points[1] );
     	var lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] );
     	
    -	// if the first point is the last point - goona have issues :)
    +	// if the first point is the last point - goona have issues :)
     	if(firstPoint.x == lastPoint.x && firstPoint.y == lastPoint.y)
     	{
     		points.pop();
    @@ -412,14 +479,14 @@ PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData)
     	
     	var verts = webGLData.points;
     	var indices = webGLData.indices;
    -	var length = points.length / 2;
    +	var length = points.length / 2;
     	var indexCount = points.length;
    -	var indexStart = verts.length/6;
    +	var indexStart = verts.length/6;
     	
    -	// DRAW the Line
    -	var width = graphicsData.lineWidth / 2;
    +	// DRAW the Line
    +	var width = graphicsData.lineWidth / 2;
     	
    -	// sort color
    +	// sort color
     	var color = HEXtoRGB(graphicsData.lineColor);
     	var alpha = graphicsData.lineAlpha;
     	var r = color[0] * alpha;
    @@ -443,12 +510,12 @@ PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData)
     	
     	dist = Math.sqrt(perpx*perpx + perpy*perpy);
     	
    -	perpx /= dist;
    -	perpy /= dist;
    +	perpx /= dist;
    +	perpy /= dist;
     	perpx *= width;
     	perpy *= width;
     	
    -	// start
    +	// start
     	verts.push(p1x - perpx , p1y - perpy,
     				r, g, b, alpha);
     	
    @@ -470,8 +537,8 @@ PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData)
     		perpy = p1x - p2x;
     		
     		dist = Math.sqrt(perpx*perpx + perpy*perpy);
    -		perpx /= dist;
    -		perpy /= dist;
    +		perpx /= dist;
    +		perpy /= dist;
     		perpx *= width;
     		perpy *= width;
     
    @@ -479,8 +546,8 @@ PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData)
     		perp2y = p2x - p3x;
     		
     		dist = Math.sqrt(perp2x*perp2x + perp2y*perp2y);
    -		perp2x /= dist;
    -		perp2y /= dist;
    +		perp2x /= dist;
    +		perp2y /= dist;
     		perp2x *= width;
     		perp2y *= width;
     		
    @@ -497,8 +564,8 @@ PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData)
     	    	denom+=1;
     	    }
     	    
    -	    px = (b1*c2 - b2*c1)/denom;
    -	    py = (a2*c1 - a1*c2)/denom;
    +	    px = (b1*c2 - b2*c1)/denom;
    +	    py = (a2*c1 - a1*c2)/denom;
     		
     		pdist = (px -p2x) * (px -p2x) + (py -p2y) + (py -p2y);
     		
    @@ -508,8 +575,8 @@ PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData)
     			perp3y = perpy - perp2y;
     			
     			dist = Math.sqrt(perp3x*perp3x + perp3y*perp3y);
    -			perp3x /= dist;
    -			perp3y /= dist;
    +			perp3x /= dist;
    +			perp3y /= dist;
     			perp3x *= width;
     			perp3y *= width;
     			
    @@ -529,7 +596,7 @@ PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData)
     			verts.push(px , py);
     			verts.push(r, g, b, alpha);
     			
    -			verts.push(p2x - (px-p2x), p2y - (py - p2y));//, 4);
    +			verts.push(p2x - (px-p2x), p2y - (py - p2y));
     			verts.push(r, g, b, alpha);
     		}
     	}
    @@ -544,8 +611,8 @@ PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData)
     	perpy = p1x - p2x;
     	
     	dist = Math.sqrt(perpx*perpx + perpy*perpy);
    -	perpx /= dist;
    -	perpy /= dist;
    +	perpx /= dist;
    +	perpy /= dist;
     	perpx *= width;
     	perpy *= width;
     	
    @@ -565,19 +632,27 @@ PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData)
     	indices.push(indexStart-1);
     }
     
    -
    +/**
    + * Builds a polygon to draw
    + *
    + * @static
    + * @private
    + * @method buildPoly
    + * @param graphics {Graphics}
    + * @param webGLData {Object}
    + */
     PIXI.WebGLGraphics.buildPoly = function(graphicsData, webGLData)
     {
     	var points = graphicsData.points;
     	if(points.length < 6)return;
     	
    -	// get first and last point.. figure out the middle!
    +	// get first and last point.. figure out the middle!
     	var verts = webGLData.points;
     	var indices = webGLData.indices;
     	
    -	var length = points.length / 2;
    +	var length = points.length / 2;
     	
    -	// sort color
    +	// sort color
     	var color = HEXtoRGB(graphicsData.fillColor);
     	var alpha = graphicsData.fillAlpha;
     	var r = color[0] * alpha;
    @@ -586,7 +661,7 @@ PIXI.WebGLGraphics.buildPoly = function(graphicsData, webGLData)
     	
     	var triangles = PIXI.PolyK.Triangulate(points);
     	
    -	var vertPos = verts.length / 6;
    +	var vertPos = verts.length / 6;
     	
     	for (var i=0; i < triangles.length; i+=3) 
     	{
    @@ -605,7 +680,7 @@ PIXI.WebGLGraphics.buildPoly = function(graphicsData, webGLData)
     }
     
     function HEXtoRGB(hex) {
    -	return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
    +	return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
     }
     
     
    @@ -621,13 +696,13 @@ function HEXtoRGB(hex) {
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_renderers_webgl_WebGLRenderGroup.js.html b/docs/files/src_pixi_renderers_webgl_WebGLRenderGroup.js.html index d73c577..59183b3 100644 --- a/docs/files/src_pixi_renderers_webgl_WebGLRenderGroup.js.html +++ b/docs/files/src_pixi_renderers_webgl_WebGLRenderGroup.js.html @@ -2,12 +2,12 @@ - src/pixi/renderers/webgl/WebGLRenderGroup.js - Pixi.JS - - - - - + src/pixi/renderers/webgl/WebGLRenderGroup.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,24 +166,27 @@
    -

    File: src/pixi/renderers/webgl/WebGLRenderGroup.js

    +

    File: src/pixi/renderers/webgl/WebGLRenderGroup.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -
    -
    -
    -/**
    +/**
      * A WebGLBatch Enables a group of sprites to be drawn using the same settings.
    - * if a group of sprites all have the same baseTexture and blendMode then they can be grouped into a batch. All the sprites in a batch can then be drawn in one go by the GPU which is hugely efficient. ALL sprites in the webGL renderer are added to a batch even if the batch only contains one sprite. Batching is handled automatically by the webGL renderer. A good tip is: the smaller the number of batchs there are, the faster the webGL renderer will run. 
    + * if a group of sprites all have the same baseTexture and blendMode then they can be
    + * grouped into a batch. All the sprites in a batch can then be drawn in one go by the
    + * GPU which is hugely efficient. ALL sprites in the webGL renderer are added to a batch
    + * even if the batch only contains one sprite. Batching is handled automatically by the
    + * webGL renderer. A good tip is: the smaller the number of batchs there are, the faster
    + * the webGL renderer will run.
    + *
      * @class WebGLBatch
    - * @param an instance of the webGL context
    - * @return {PIXI.renderers.WebGLBatch} WebGLBatch {@link PIXI.renderers.WebGLBatch}
    - */
    + * @contructor
    + * @param gl {WebGLContext} An instance of the webGL context
    + */
     PIXI.WebGLRenderGroup = function(gl)
     {
     	this.gl = gl;
    @@ -168,106 +195,90 @@ PIXI.WebGLRenderGroup = function(gl)
     	this.backgroundColor;
     	this.batchs = [];
     	this.toRemove = [];
    +	
    +	this.filterManager = new PIXI.WebGLFilterManager();
     }
     
    -// constructor
    -PIXI.WebGLRenderGroup.constructor = PIXI.WebGLRenderGroup;
    +// constructor
    +PIXI.WebGLRenderGroup.prototype.constructor = PIXI.WebGLRenderGroup;
     
    +/**
    + * Add a display object to the webgl renderer
    + *
    + * @method setRenderable
    + * @param displayObject {DisplayObject}
    + * @private 
    + */
     PIXI.WebGLRenderGroup.prototype.setRenderable = function(displayObject)
     {
    -	// has this changed??
    +	// has this changed??
     	if(this.root)this.removeDisplayObjectAndChildren(this.root);
     	
     	displayObject.worldVisible = displayObject.visible;
     	
    -	// soooooo //
    -	// to check if any batchs exist already??
    +	// soooooo //
    +	// to check if any batchs exist already??
     	
    -	// TODO what if its already has an object? should remove it
    +	// TODO what if its already has an object? should remove it
     	this.root = displayObject;
     	this.addDisplayObjectAndChildren(displayObject);
     }
     
    -PIXI.WebGLRenderGroup.prototype.render = function(projection)
    +/**
    + * Renders the stage to its webgl view
    + *
    + * @method render
    + * @param projection {Object}
    + */
    +PIXI.WebGLRenderGroup.prototype.render = function(projection, buffer)
     {
     	PIXI.WebGLRenderer.updateTextures();
     	
     	var gl = this.gl;
    +	gl.uniform2f(PIXI.defaultShader.projectionVector, projection.x, projection.y);
     
    -	gl.uniform2f(PIXI.shaderProgram.projectionVector, projection.x, projection.y);
    +	this.filterManager.begin(projection, buffer);
    +
    +	
     	gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
    -	
    -	// TODO remove this by replacing visible with getter setters..	
    -	this.checkVisibility(this.root, this.root.visible);
    -	
    -	// will render all the elements in the group
    +	// will render all the elements in the group
     	var renderable;
    -	
    -	
    +
     	for (var i=0; i < this.batchs.length; i++) 
     	{
    +		
     		renderable = this.batchs[i];
     		if(renderable instanceof PIXI.WebGLBatch)
     		{
     			this.batchs[i].render();
    +			continue;
     		}
    -		else if(renderable instanceof PIXI.TilingSprite)
    -		{
    -			if(renderable.visible)this.renderTilingSprite(renderable, projection);
    -		}
    -		else if(renderable instanceof PIXI.Strip)
    -		{
    -			if(renderable.visible)this.renderStrip(renderable, projection);
    -		}
    -		else if(renderable instanceof PIXI.Graphics)
    -		{
    -			if(renderable.visible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable, projection);//, projectionMatrix);
    -		}
    -		else if(renderable instanceof PIXI.FilterBlock)
    -		{
    -			/*
    -			 * for now only masks are supported..
    -			 */
    -			if(renderable.open)
    -			{
    -    			gl.enable(gl.STENCIL_TEST);
    -					
    -				gl.colorMask(false, false, false, false);
    -				gl.stencilFunc(gl.ALWAYS,1,0xff);
    -				gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE);
    -  
    -				PIXI.WebGLGraphics.renderGraphics(renderable.mask, projection);
    -  					
    -				gl.colorMask(true, true, true, false);
    -				gl.stencilFunc(gl.NOTEQUAL,0,0xff);
    -				gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP);
    -			}
    -			else
    -			{
    -				gl.disable(gl.STENCIL_TEST);
    -			}
    -		}
    +		
    +		// render special
    +		this.renderSpecial(renderable, projection);
     	}
     	
     }
     
    -PIXI.WebGLRenderGroup.prototype.handleFilter = function(filter, projection)
    -{
    -	
    -}
    -
    -PIXI.WebGLRenderGroup.prototype.renderSpecific = function(displayObject, projection)
    +/**
    + * Renders a specific displayObject
    + *
    + * @method renderSpecific
    + * @param displayObject {DisplayObject}
    + * @param projection {Object}
    + * @private
    + */
    +PIXI.WebGLRenderGroup.prototype.renderSpecific = function(displayObject, projection, buffer)
     {
     	PIXI.WebGLRenderer.updateTextures();
    -	
     	var gl = this.gl;
    -	this.checkVisibility(displayObject, displayObject.visible);
    -	
    -//	gl.uniformMatrix4fv(PIXI.shaderProgram.mvMatrixUniform, false, projectionMatrix);
    -	gl.uniform2f(PIXI.shaderProgram.projectionVector, projection.x, projection.y);
     
    -	// to do!
    -	// render part of the scene...
    +	gl.uniform2f(PIXI.defaultShader.projectionVector, projection.x, projection.y);
    +
    +	this.filterManager.begin(projection, buffer);
    +
    +	// to do!
    +	// render part of the scene...
     	
     	var startIndex;
     	var startBatchIndex;
    @@ -275,20 +286,22 @@ PIXI.WebGLRenderGroup.prototype.renderSpecific = function(displayObject, project
     	var endIndex;
     	var endBatchIndex;
     	
    -	/*
    +	/*
     	 *  LOOK FOR THE NEXT SPRITE
     	 *  This part looks for the closest next sprite that can go into a batch
     	 *  it keeps looking until it finds a sprite or gets to the end of the display
     	 *  scene graph
    -	 */
    -	var nextRenderable = displayObject.last;
    +	 */
    +	var nextRenderable = displayObject.first;
     	while(nextRenderable._iNext)
     	{
    -		nextRenderable = nextRenderable._iNext;
     		if(nextRenderable.renderable && nextRenderable.__renderGroup)break;
    +		nextRenderable = nextRenderable._iNext;
     	}
     	var startBatch = nextRenderable.batch;
    +	//console.log(nextRenderable);
     	
    +	//console.log(renderable)
     	if(nextRenderable instanceof PIXI.Sprite)
     	{
     		startBatch = nextRenderable.batch;
    @@ -296,7 +309,7 @@ PIXI.WebGLRenderGroup.prototype.renderSpecific = function(displayObject, project
     		var head = startBatch.head;
     		var next = head;
     		
    -		// ok now we have the batch.. need to find the start index!
    +		// ok now we have the batch.. need to find the start index!
     		if(head == nextRenderable)
     		{
     			startIndex = 0;
    @@ -317,14 +330,12 @@ PIXI.WebGLRenderGroup.prototype.renderSpecific = function(displayObject, project
     		startBatch = nextRenderable;
     	}
     	
    -	// Get the LAST renderable object
    -	var lastRenderable = displayObject;
    -	var endBatch;
    -	var lastItem = displayObject;
    -	while(lastItem.children.length > 0)
    +	// Get the LAST renderable object
    +	var lastRenderable = displayObject.last;
    +	while(lastRenderable._iPrev)
     	{
    -		lastItem = lastItem.children[lastItem.children.length-1];
    -		if(lastItem.renderable)lastRenderable = lastItem;
    +		if(lastRenderable.renderable && lastRenderable.__renderGroup)break;
    +		lastRenderable = lastRenderable._iNext;
     	}
     	
     	if(lastRenderable instanceof PIXI.Sprite)
    @@ -353,7 +364,8 @@ PIXI.WebGLRenderGroup.prototype.renderSpecific = function(displayObject, project
     		endBatch = lastRenderable;
     	}
     	
    -	// TODO - need to fold this up a bit!
    +	//console.log(endBatch);
    +	// TODO - need to fold this up a bit!
     	
     	if(startBatch == endBatch)
     	{
    @@ -363,26 +375,26 @@ PIXI.WebGLRenderGroup.prototype.renderSpecific = function(displayObject, project
     		}
     		else
     		{
    -			this.renderSpecial(startBatch);
    +			this.renderSpecial(startBatch, projection);
     		}
     		return;
     	}
     	
    -	// now we have first and last!
    +	// now we have first and last!
     	startBatchIndex = this.batchs.indexOf(startBatch);
     	endBatchIndex = this.batchs.indexOf(endBatch);
     	
    -	// DO the first batch
    +	// DO the first batch
     	if(startBatch instanceof PIXI.WebGLBatch)
     	{
     		startBatch.render(startIndex);
     	}
     	else
     	{
    -		this.renderSpecial(startBatch);
    +		this.renderSpecial(startBatch, projection);
     	}
     	
    -	// DO the middle batchs..
    +	// DO the middle batchs..
     	for (var i=startBatchIndex+1; i < endBatchIndex; i++) 
     	{
     		renderable = this.batchs[i];
    @@ -393,58 +405,97 @@ PIXI.WebGLRenderGroup.prototype.renderSpecific = function(displayObject, project
     		}
     		else
     		{
    -			this.renderSpecial(renderable);
    +			this.renderSpecial(renderable, projection);
     		}
     	}
     	
    -	// DO the last batch..
    +	// DO the last batch..
     	if(endBatch instanceof PIXI.WebGLBatch)
     	{
     		endBatch.render(0, endIndex+1);
     	}
     	else
     	{
    -		this.renderSpecial(endBatch);
    +		this.renderSpecial(endBatch, projection);
     	}
     }
     
    -PIXI.WebGLRenderGroup.prototype.renderSpecial = function(renderable)
    +/**
    + * Renders a specific renderable
    + *
    + * @method renderSpecial
    + * @param renderable {DisplayObject}
    + * @param projection {Object}
    + * @private
    + */
    +PIXI.WebGLRenderGroup.prototype.renderSpecial = function(renderable, projection)
     {
    +	
    +	var worldVisible = renderable.vcount === PIXI.visibleCount
    +
    +
     	if(renderable instanceof PIXI.TilingSprite)
     	{
    -		if(renderable.visible)this.renderTilingSprite(renderable, projectionMatrix);
    +		if(worldVisible)this.renderTilingSprite(renderable, projection);
     	}
     	else if(renderable instanceof PIXI.Strip)
     	{
    -		if(renderable.visible)this.renderStrip(renderable, projectionMatrix);
    +		if(worldVisible)this.renderStrip(renderable, projection);
     	}
     	else if(renderable instanceof PIXI.CustomRenderable)
     	{
    -		if(renderable.visible) renderable.renderWebGL(this, projectionMatrix);
    +		if(worldVisible) renderable.renderWebGL(this, projection);
     	}
     	else if(renderable instanceof PIXI.Graphics)
     	{
    -		if(renderable.visible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable);//, projectionMatrix);
    +		if(worldVisible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable, projection);
     	}
     	else if(renderable instanceof PIXI.FilterBlock)
     	{
    -		/*
    -		 * for now only masks are supported..
    -		 */
    -		if(renderable.open)
    +		this.handleFilterBlock(renderable, projection);
    +	}
    +}
    +
    +PIXI.WebGLRenderGroup.prototype.handleFilterBlock = function(filterBlock, projection)
    +{
    +	/*
    +	 * for now only masks are supported..
    +	 */
    +	var gl = PIXI.gl;
    +	
    +	if(filterBlock.open)
    +	{
    +		if(filterBlock.data instanceof Array)
     		{
    +			//var filter = filterBlock.data[0];
    +			//console.log(filter)
    +			this.filterManager.pushFilter(filterBlock);//filter);
    +			// ok so..
    +			
    +		}
    +		else
    +		{
    +			
     			gl.enable(gl.STENCIL_TEST);
     				
     			gl.colorMask(false, false, false, false);
     			gl.stencilFunc(gl.ALWAYS,1,0xff);
     			gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE);
    -  
    -			PIXI.WebGLGraphics.renderGraphics(renderable.mask, projection);
    +			PIXI.WebGLGraphics.renderGraphics(filterBlock.data, projection);
     				
    -			gl.colorMask(true, true, true, false);
    +			gl.colorMask(true, true, true, true);
     			gl.stencilFunc(gl.NOTEQUAL,0,0xff);
     			gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP);
     		}
    +	}
    +	else
    +	{
    +		if(filterBlock.data instanceof Array)
    +		{
    +			this.filterManager.popFilter();
    +		//	PIXI.popShader();
    +		//	gl.uniform2f(PIXI.currentShader.projectionVector, projection.x, projection.y);
    +		}
     		else
     		{
     			gl.disable(gl.STENCIL_TEST);
    @@ -452,46 +503,25 @@ PIXI.WebGLRenderGroup.prototype.renderSpecial = function(renderable)
     	}
     }
     
    -PIXI.WebGLRenderGroup.prototype.checkVisibility = function(displayObject, globalVisible)
    -{
    -	// give the dp a reference to its renderGroup...
    -	var children = displayObject.children;
    -	//displayObject.worldVisible = globalVisible;
    -	for (var i=0; i < children.length; i++) 
    -	{
    -		var child = children[i];
    -		
    -		// TODO optimize... should'nt need to loop through everything all the time
    -		child.worldVisible = child.visible && globalVisible;
    -		
    -		// everything should have a batch!
    -		// time to see whats new!
    -		if(child.textureChange)
    -		{
    -			child.textureChange = false;
    -			if(child.worldVisible)this.updateTexture(child);
    -			// update texture!!
    -		}
    -		
    -		if(child.children.length > 0)
    -		{
    -			this.checkVisibility(child, child.worldVisible);
    -		}
    -	};
    -}
    -
    +/**
    + * Updates a webgl texture
    + *
    + * @method updateTexture
    + * @param displayObject {DisplayObject}
    + * @private
    + */
     PIXI.WebGLRenderGroup.prototype.updateTexture = function(displayObject)
     {
     	
    -	// TODO definitely can optimse this function..
    +	// TODO definitely can optimse this function..
     	
     	this.removeObject(displayObject);
     	
    -	/*
    +	/*
     	 *  LOOK FOR THE PREVIOUS RENDERABLE
     	 *  This part looks for the closest previous sprite that can go into a batch
     	 *  It keeps going back until it finds a sprite or the stage
    -	 */
    +	 */
     	var previousRenderable = displayObject.first;
     	while(previousRenderable != this.root)
     	{
    @@ -499,12 +529,12 @@ PIXI.WebGLRenderGroup.prototype.updateTexture = function(displayObject)
     		if(previousRenderable.renderable && previousRenderable.__renderGroup)break;
     	}
     	
    -	/*
    +	/*
     	 *  LOOK FOR THE NEXT SPRITE
     	 *  This part looks for the closest next sprite that can go into a batch
     	 *  it keeps looking until it finds a sprite or gets to the end of the display
     	 *  scene graph
    -	 */
    +	 */
     	var nextRenderable = displayObject.last;
     	while(nextRenderable._iNext)
     	{
    @@ -515,31 +545,39 @@ PIXI.WebGLRenderGroup.prototype.updateTexture = function(displayObject)
     	this.insertObject(displayObject, previousRenderable, nextRenderable);
     }
     
    +/**
    + * Adds filter blocks
    + *
    + * @method addFilterBlocks
    + * @param start {FilterBlock}
    + * @param end {FilterBlock}
    + * @private
    + */
     PIXI.WebGLRenderGroup.prototype.addFilterBlocks = function(start, end)
     {
     	start.__renderGroup = this;
     	end.__renderGroup = this;
    -	/*
    +	/*
     	 *  LOOK FOR THE PREVIOUS RENDERABLE
     	 *  This part looks for the closest previous sprite that can go into a batch
     	 *  It keeps going back until it finds a sprite or the stage
    -	 */
    +	 */
     	var previousRenderable = start;
    -	while(previousRenderable != this.root)
    +	while(previousRenderable != this.root.first)
     	{
     		previousRenderable = previousRenderable._iPrev;
     		if(previousRenderable.renderable && previousRenderable.__renderGroup)break;
     	}
     	this.insertAfter(start, previousRenderable);
     		
    -	/*
    +	/*
     	 *  LOOK FOR THE NEXT SPRITE
     	 *  This part looks for the closest next sprite that can go into a batch
     	 *  it keeps looking until it finds a sprite or gets to the end of the display
     	 *  scene graph
    -	 */
    +	 */
     	var previousRenderable2 = end;
    -	while(previousRenderable2 != this.root)
    +	while(previousRenderable2 != this.root.first)
     	{
     		previousRenderable2 = previousRenderable2._iPrev;
     		if(previousRenderable2.renderable && previousRenderable2.__renderGroup)break;
    @@ -547,35 +585,50 @@ PIXI.WebGLRenderGroup.prototype.addFilterBlocks = function(start, end)
     	this.insertAfter(end, previousRenderable2);
     }
     
    +/**
    + * Remove filter blocks
    + *
    + * @method removeFilterBlocks
    + * @param start {FilterBlock}
    + * @param end {FilterBlock}
    + * @private
    + */
     PIXI.WebGLRenderGroup.prototype.removeFilterBlocks = function(start, end)
     {
     	this.removeObject(start);
     	this.removeObject(end);
     }
     
    +/**
    + * Adds a display object and children to the webgl context
    + *
    + * @method addDisplayObjectAndChildren
    + * @param displayObject {DisplayObject}
    + * @private
    + */
     PIXI.WebGLRenderGroup.prototype.addDisplayObjectAndChildren = function(displayObject)
     {
     	if(displayObject.__renderGroup)displayObject.__renderGroup.removeDisplayObjectAndChildren(displayObject);
     	
    -	/*
    +	/*
     	 *  LOOK FOR THE PREVIOUS RENDERABLE
     	 *  This part looks for the closest previous sprite that can go into a batch
     	 *  It keeps going back until it finds a sprite or the stage
    -	 */
    +	 */
     	
     	var previousRenderable = displayObject.first;
    -	while(previousRenderable != this.root)
    +	while(previousRenderable != this.root.first)
     	{
     		previousRenderable = previousRenderable._iPrev;
     		if(previousRenderable.renderable && previousRenderable.__renderGroup)break;
     	}
     	
    -	/*
    +	/*
     	 *  LOOK FOR THE NEXT SPRITE
     	 *  This part looks for the closest next sprite that can go into a batch
     	 *  it keeps looking until it finds a sprite or gets to the end of the display
     	 *  scene graph
    -	 */
    +	 */
     	var nextRenderable = displayObject.last;
     	while(nextRenderable._iNext)
     	{
    @@ -583,7 +636,7 @@ PIXI.WebGLRenderGroup.prototype.addDisplayObjectAndChildren = function(displayOb
     		if(nextRenderable.renderable && nextRenderable.__renderGroup)break;
     	}
     	
    -	// one the display object hits this. we can break the loop	
    +	// one the display object hits this. we can break the loop	
     	
     	var tempObject = displayObject.first;
     	var testObject = displayObject.last._iNext;
    @@ -603,11 +656,18 @@ PIXI.WebGLRenderGroup.prototype.addDisplayObjectAndChildren = function(displayOb
     	while(tempObject != testObject)
     }
     
    +/**
    + * Removes a display object and children to the webgl context
    + *
    + * @method removeDisplayObjectAndChildren
    + * @param displayObject {DisplayObject}
    + * @private
    + */
     PIXI.WebGLRenderGroup.prototype.removeDisplayObjectAndChildren = function(displayObject)
     {
     	if(displayObject.__renderGroup != this)return;
     	
    -//	var displayObject = displayObject.first;
    +//	var displayObject = displayObject.first;
     	var lastObject = displayObject.last;
     	do	
     	{
    @@ -618,18 +678,25 @@ PIXI.WebGLRenderGroup.prototype.removeDisplayObjectAndChildren = function(displa
     	while(displayObject)
     }
     
    -	
    -
    +/**
    + * Inserts a displayObject into the linked list
    + *
    + * @method insertObject
    + * @param displayObject {DisplayObject}
    + * @param previousObject {DisplayObject}
    + * @param nextObject {DisplayObject}
    + * @private
    + */
     PIXI.WebGLRenderGroup.prototype.insertObject = function(displayObject, previousObject, nextObject)
     {
    -	// while looping below THE OBJECT MAY NOT HAVE BEEN ADDED
    +	// while looping below THE OBJECT MAY NOT HAVE BEEN ADDED
     	var previousSprite = previousObject;
     	var nextSprite = nextObject;
     	
    -	/*
    +	/*
     	 * so now we have the next renderable and the previous renderable
     	 * 
    -	 */
    +	 */
     	if(displayObject instanceof PIXI.Sprite)
     	{
     		var previousBatch
    @@ -649,7 +716,7 @@ PIXI.WebGLRenderGroup.prototype.insertObject = function(displayObject, previousO
     		}
     		else
     		{
    -			// TODO reword!
    +			// TODO reword!
     			previousBatch = previousSprite;
     		}
     	
    @@ -659,7 +726,7 @@ PIXI.WebGLRenderGroup.prototype.insertObject = function(displayObject, previousO
     			{
     				nextBatch = nextSprite.batch;
     			
    -				//batch may not exist if item was added to the display list but not to the webGL
    +				//batch may not exist if item was added to the display list but not to the webGL
     				if(nextBatch)
     				{
     					if(nextBatch.texture == displayObject.texture.baseTexture && nextBatch.blendMode == displayObject.blendMode)
    @@ -671,15 +738,15 @@ PIXI.WebGLRenderGroup.prototype.insertObject = function(displayObject, previousO
     					{
     						if(nextBatch == previousBatch)
     						{
    -							// THERE IS A SPLIT IN THIS BATCH! //
    +							// THERE IS A SPLIT IN THIS BATCH! //
     							var splitBatch = previousBatch.split(nextSprite);
    -							// COOL!
    -							// add it back into the array	
    -							/*
    +							// COOL!
    +							// add it back into the array	
    +							/*
     							 * OOPS!
     							 * seems the new sprite is in the middle of a batch
     							 * lets split it.. 
    -							 */
    +							 */
     							var batch = PIXI.WebGLRenderer.getBatch();
     
     							var index = this.batchs.indexOf( previousBatch );
    @@ -693,22 +760,22 @@ PIXI.WebGLRenderGroup.prototype.insertObject = function(displayObject, previousO
     			}
     			else
     			{
    -				// TODO re-word!
    +				// TODO re-word!
     				
     				nextBatch = nextSprite;
     			}
     		}
     		
    -		/*
    +		/*
     		 * looks like it does not belong to any batch!
     		 * but is also not intersecting one..
     		 * time to create anew one!
    -		 */
    +		 */
     		
     		var batch =  PIXI.WebGLRenderer.getBatch();
     		batch.init(displayObject);
     
    -		if(previousBatch) // if this is invalid it means 
    +		if(previousBatch) // if this is invalid it means 
     		{
     			var index = this.batchs.indexOf( previousBatch );
     			this.batchs.splice(index+1, 0, batch);
    @@ -723,34 +790,40 @@ PIXI.WebGLRenderGroup.prototype.insertObject = function(displayObject, previousO
     	else if(displayObject instanceof PIXI.TilingSprite)
     	{
     		
    -		// add to a batch!!
    +		// add to a batch!!
     		this.initTilingSprite(displayObject);
    -	//	this.batchs.push(displayObject);
    +	//	this.batchs.push(displayObject);
     		
     	}
     	else if(displayObject instanceof PIXI.Strip)
     	{
    -		// add to a batch!!
    +		// add to a batch!!
     		this.initStrip(displayObject);
    -	//	this.batchs.push(displayObject);
    +	//	this.batchs.push(displayObject);
     	}
    -	else if(displayObject)// instanceof PIXI.Graphics)
    +	else if(displayObject)// instanceof PIXI.Graphics)
     	{
    -		//displayObject.initWebGL(this);
    +		//displayObject.initWebGL(this);
     		
    -		// add to a batch!!
    -		//this.initStrip(displayObject);
    -		//this.batchs.push(displayObject);
    +		// add to a batch!!
    +		//this.initStrip(displayObject);
    +		//this.batchs.push(displayObject);
     	}
     	
     	this.insertAfter(displayObject, previousSprite);
     			
    -	// insert and SPLIT!
    +	// insert and SPLIT!
     
     }
     
    -				
    -			
    +/**
    + * Inserts a displayObject into the linked list
    + *
    + * @method insertAfter
    + * @param item {DisplayObject}
    + * @param displayObject {DisplayObject} The object to insert
    + * @private
    + */
     PIXI.WebGLRenderGroup.prototype.insertAfter = function(item, displayObject)
     {
     	if(displayObject instanceof PIXI.Sprite)
    @@ -759,29 +832,29 @@ PIXI.WebGLRenderGroup.prototype.insertAfter = function(item, displayObject)
     		
     		if(previousBatch)
     		{
    -			// so this object is in a batch!
    +			// so this object is in a batch!
     			
    -			// is it not? need to split the batch
    +			// is it not? need to split the batch
     			if(previousBatch.tail == displayObject)
     			{
    -				// is it tail? insert in to batchs	
    +				// is it tail? insert in to batchs	
     				var index = this.batchs.indexOf( previousBatch );
     				this.batchs.splice(index+1, 0, item);
     			}
     			else
     			{
    -				// TODO MODIFY ADD / REMOVE CHILD TO ACCOUNT FOR FILTERS (also get prev and next) //
    +				// TODO MODIFY ADD / REMOVE CHILD TO ACCOUNT FOR FILTERS (also get prev and next) //
     				
    -				// THERE IS A SPLIT IN THIS BATCH! //
    +				// THERE IS A SPLIT IN THIS BATCH! //
     				var splitBatch = previousBatch.split(displayObject.__next);
     				
    -				// COOL!
    -				// add it back into the array	
    -				/*
    +				// COOL!
    +				// add it back into the array	
    +				/*
     				 * OOPS!
     				 * seems the new sprite is in the middle of a batch
     				 * lets split it.. 
    -				 */
    +				 */
     				var index = this.batchs.indexOf( previousBatch );
     				this.batchs.splice(index+1, 0, item, splitBatch);
     			}
    @@ -798,26 +871,33 @@ PIXI.WebGLRenderGroup.prototype.insertAfter = function(item, displayObject)
     	}
     }
     
    +/**
    + * Removes a displayObject from the linked list
    + *
    + * @method removeObject
    + * @param displayObject {DisplayObject} The object to remove
    + * @private
    + */
     PIXI.WebGLRenderGroup.prototype.removeObject = function(displayObject)
     {
    -	// loop through children..
    -	// display object //
    +	// loop through children..
    +	// display object //
     	
    -	// add a child from the render group..
    -	// remove it and all its children!
    -	//displayObject.cacheVisible = false;//displayObject.visible;
    +	// add a child from the render group..
    +	// remove it and all its children!
    +	//displayObject.cacheVisible = false;//displayObject.visible;
     
    -	/*
    +	/*
     	 * removing is a lot quicker..
     	 * 
    -	 */
    +	 */
     	var batchToRemove;
     	
     	if(displayObject instanceof PIXI.Sprite)
     	{
    -		// should always have a batch!
    +		// should always have a batch!
     		var batch = displayObject.batch;
    -		if(!batch)return; // this means the display list has been altered befre rendering
    +		if(!batch)return; // this means the display list has been altered befre rendering
     		
     		batch.remove(displayObject);
     		
    @@ -831,19 +911,19 @@ PIXI.WebGLRenderGroup.prototype.removeObject = function(displayObject)
     		batchToRemove = displayObject;
     	}
     	
    -	/*
    +	/*
     	 * Looks like there is somthing that needs removing!
    -	 */
    +	 */
     	if(batchToRemove)	
     	{
     		var index = this.batchs.indexOf( batchToRemove );
    -		if(index == -1)return;// this means it was added then removed before rendered
    +		if(index == -1)return;// this means it was added then removed before rendered
     		
    -		// ok so.. check to see if you adjacent batchs should be joined.
    -		// TODO may optimise?
    +		// ok so.. check to see if you adjacent batchs should be joined.
    +		// TODO may optimise?
     		if(index == 0 || index == this.batchs.length-1)
     		{
    -			// wha - eva! just get of the empty batch!
    +			// wha - eva! just get of the empty batch!
     			this.batchs.splice(index, 1);
     			if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove);
     		
    @@ -854,7 +934,7 @@ PIXI.WebGLRenderGroup.prototype.removeObject = function(displayObject)
     		{
     			if(this.batchs[index-1].texture == this.batchs[index+1].texture && this.batchs[index-1].blendMode == this.batchs[index+1].blendMode)
     			{
    -				//console.log("MERGE")
    +				//console.log("MERGE")
     				this.batchs[index-1].merge(this.batchs[index+1]);
     				
     				if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove);
    @@ -870,21 +950,18 @@ PIXI.WebGLRenderGroup.prototype.removeObject = function(displayObject)
     }
     
     
    -/**
    +/**
    + * Initializes a tiling sprite
    + *
    + * @method initTilingSprite
    + * @param sprite {TilingSprite} The tiling sprite to initialize
      * @private
    - */
    -
    -
    -
    -
    -/**
    - * @private
    - */
    + */
     PIXI.WebGLRenderGroup.prototype.initTilingSprite = function(sprite)
     {
     	var gl = this.gl;
     
    -	// make the texture tilable..
    +	// make the texture tilable..
     			
     	sprite.verticies = new Float32Array([0, 0,
     										  sprite.width, 0,
    @@ -898,7 +975,7 @@ PIXI.WebGLRenderGroup.prototype.initTilingSprite = function(sprite)
     				
     	sprite.colors = new Float32Array([1,1,1,1]);
     	
    -	sprite.indices =  new Uint16Array([0, 1, 3,2])//, 2]);
    +	sprite.indices =  new Uint16Array([0, 1, 3,2])//, 2]);
     	
     	sprite._vertexBuffer = gl.createBuffer();
     	sprite._indexBuffer = gl.createBuffer();
    @@ -917,7 +994,7 @@ PIXI.WebGLRenderGroup.prototype.initTilingSprite = function(sprite)
         gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, sprite._indexBuffer);
         gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, sprite.indices, gl.STATIC_DRAW);
         
    -//    return ( (x > 0) && ((x & (x - 1)) == 0) );
    +//    return ( (x > 0) && ((x & (x - 1)) == 0) );
     
     	if(sprite.texture.baseTexture._glTexture)
     	{
    @@ -932,31 +1009,37 @@ PIXI.WebGLRenderGroup.prototype.initTilingSprite = function(sprite)
     	}
     }
     
    -/**
    +/**
    + * Renders a Strip
    + *
    + * @method renderStrip
    + * @param strip {Strip} The strip to render
    + * @param projection {Object}
      * @private
    - */
    + */
     PIXI.WebGLRenderGroup.prototype.renderStrip = function(strip, projection)
     {
     	var gl = this.gl;
    -	var shaderProgram = PIXI.shaderProgram;
    -//	mat
    -	//var mat4Real = PIXI.mat3.toMat4(strip.worldTransform);
    -	//PIXI.mat4.transpose(mat4Real);
    -	//PIXI.mat4.multiply(projectionMatrix, mat4Real, mat4Real )
     
    +	PIXI.activateStripShader();
    +
    +	var shader = PIXI.stripShader;
    +
    +	var program = shader.program;
     	
    -	gl.useProgram(PIXI.stripShaderProgram);
    -
     	var m = PIXI.mat3.clone(strip.worldTransform);
     	
     	PIXI.mat3.transpose(m);
     	
    -	// set the matrix transform for the 
    - 	gl.uniformMatrix3fv(PIXI.stripShaderProgram.translationMatrix, false, m);
    -	gl.uniform2f(PIXI.stripShaderProgram.projectionVector, projection.x, projection.y);
    -	gl.uniform1f(PIXI.stripShaderProgram.alpha, strip.worldAlpha);
    +//	console.log(projection)
    +	// set the matrix transform for the 
    + 	gl.uniformMatrix3fv(shader.translationMatrix, false, m);
    +	gl.uniform2f(shader.projectionVector, projection.x, projection.y);
    +	gl.uniform2f(shader.offsetVector, -PIXI.offset.x, -PIXI.offset.y);
    +	
    +	gl.uniform1f(shader.alpha, strip.worldAlpha);
     
    -/*
    +	/*
     	if(strip.blendMode == PIXI.blendModes.NORMAL)
     	{
     		gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
    @@ -965,27 +1048,26 @@ PIXI.WebGLRenderGroup.prototype.renderStrip = function(strip, projection)
     	{
     		gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR);
     	}
    -	*/
    -	
    +	*/
     	
    +	//console.log("!!")
     	if(!strip.dirty)
    -	{
    -		
    +	{	
     		gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer);
     		gl.bufferSubData(gl.ARRAY_BUFFER, 0, strip.verticies)
    -	    gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
    +	    gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, 0, 0);
     		
    -		// update the uvs
    +		// update the uvs
     	   	gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer);
    -	    gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0);
    +	    gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
     			
     	    gl.activeTexture(gl.TEXTURE0);
     	    gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture);
     		
     		gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer);
    -	    gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0);
    +	    gl.vertexAttribPointer(shader.colorAttribute, 1, gl.FLOAT, false, 0, 0);
     		
    -		// dont need to upload!
    +		// dont need to upload!
     	    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer);
     	}
     	else
    @@ -993,49 +1075,55 @@ PIXI.WebGLRenderGroup.prototype.renderStrip = function(strip, projection)
     		strip.dirty = false;
     		gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer);
     		gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.STATIC_DRAW)
    -	    gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0);
    +	    gl.vertexAttribPointer(shader.aVertexPosition, 2, gl.FLOAT, false, 0, 0);
     		
    -		// update the uvs
    +		// update the uvs
     	   	gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer);
     	   	gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW)
    -	    gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0);
    +	    gl.vertexAttribPointer(shader.aTextureCoord, 2, gl.FLOAT, false, 0, 0);
     			
     	    gl.activeTexture(gl.TEXTURE0);
     	    gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture);
    -		
    +	//	console.log(strip.texture.baseTexture._glTexture)
     		gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer);
     		gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW)
    -	    gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0);
    +	    gl.vertexAttribPointer(shader.colorAttribute, 1, gl.FLOAT, false, 0, 0);
     		
    -		// dont need to upload!
    +		// dont need to upload!
     	    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer);
     	    gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW);
     	    
     	}
    -	//console.log(gl.TRIANGLE_STRIP);
     	
     	gl.drawElements(gl.TRIANGLE_STRIP, strip.indices.length, gl.UNSIGNED_SHORT, 0);
         
    -  	gl.useProgram(PIXI.shaderProgram);
    +    PIXI.deactivateStripShader();
    +  	//gl.useProgram(PIXI.currentProgram);
     }
     
    -
    -/**
    +/**
    + * Renders a TilingSprite
    + *
    + * @method renderTilingSprite
    + * @param sprite {TilingSprite} The tiling sprite to render
    + * @param projectionMatrix {Object}
      * @private
    - */
    + */
     PIXI.WebGLRenderGroup.prototype.renderTilingSprite = function(sprite, projectionMatrix)
     {
     	var gl = this.gl;
    +
    +
     	var shaderProgram = PIXI.shaderProgram;
     	
     	var tilePosition = sprite.tilePosition;
     	var tileScale = sprite.tileScale;
     	
    -	var offsetX =  tilePosition.x/sprite.texture.baseTexture.width;
    -	var offsetY =  tilePosition.y/sprite.texture.baseTexture.height;
    +	var offsetX =  tilePosition.x/sprite.texture.baseTexture.width;
    +	var offsetY =  tilePosition.y/sprite.texture.baseTexture.height;
     	
    -	var scaleX =  (sprite.width / sprite.texture.baseTexture.width)  / tileScale.x;
    -	var scaleY =  (sprite.height / sprite.texture.baseTexture.height) / tileScale.y;
    +	var scaleX =  (sprite.width / sprite.texture.baseTexture.width)  / tileScale.x;
    +	var scaleY =  (sprite.height / sprite.texture.baseTexture.height) / tileScale.y;
     
     	sprite.uvs[0] = 0 - offsetX;
     	sprite.uvs[1] = 0 - offsetY;
    @@ -1055,14 +1143,16 @@ PIXI.WebGLRenderGroup.prototype.renderTilingSprite = function(sprite, projection
     	this.renderStrip(sprite, projectionMatrix);
     }
     
    -
    -
    -/**
    +/**
    + * Initializes a strip to be rendered
    + *
    + * @method initStrip
    + * @param strip {Strip} The strip to initialize
      * @private
    - */
    + */
     PIXI.WebGLRenderGroup.prototype.initStrip = function(strip)
     {
    -	// build the strip!
    +	// build the strip!
     	var gl = this.gl;
     	var shaderProgram = this.shaderProgram;
     	
    @@ -1095,13 +1185,13 @@ PIXI.WebGLRenderGroup.prototype.initStrip = function(strip)
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_renderers_webgl_WebGLRenderer.js.html b/docs/files/src_pixi_renderers_webgl_WebGLRenderer.js.html index eb6aae6..df7b30e 100644 --- a/docs/files/src_pixi_renderers_webgl_WebGLRenderer.js.html +++ b/docs/files/src_pixi_renderers_webgl_WebGLRenderer.js.html @@ -2,12 +2,12 @@ - src/pixi/renderers/webgl/WebGLRenderer.js - Pixi.JS - - - - - + src/pixi/renderers/webgl/WebGLRenderer.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,102 +166,121 @@
    -

    File: src/pixi/renderers/webgl/WebGLRenderer.js

    +

    File: src/pixi/renderers/webgl/WebGLRenderer.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
     PIXI._defaultFrame = new PIXI.Rectangle(0,0,1,1);
     
    -// an instance of the gl context..
    -// only one at the moment :/
    +// an instance of the gl context..
    +// only one at the moment :/
     PIXI.gl;
     
    -/**
    - * the WebGLRenderer is draws the stage and all its content onto a webGL enabled canvas. This renderer should be used for browsers support webGL. This Render works by automatically managing webGLBatchs. So no need for Sprite Batch's or Sprite Cloud's
    +/**
    + * the WebGLRenderer is draws the stage and all its content onto a webGL enabled canvas. This renderer
    + * should be used for browsers support webGL. This Render works by automatically managing webGLBatchs.
    + * So no need for Sprite Batch's or Sprite Cloud's
      * Dont forget to add the view to your DOM or you will not see anything :)
    + *
      * @class WebGLRenderer
      * @constructor
    - * @param width {Number} the width of the canvas view
    - * @default 0
    - * @param height {Number} the height of the canvas view
    - * @default 0
    + * @param width=0 {Number} the width of the canvas view
    + * @param height=0 {Number} the height of the canvas view
      * @param view {Canvas} the canvas to use as a view, optional
    - * @param transparent {Boolean} the transparency of the render view, default false
    - * @default false
    + * @param transparent=false {Boolean} the transparency of the render view, default false
    + * @param antialias=false {Boolean} sets antialias (only applicable in chrome at the moment)
      * 
    - */
    -PIXI.WebGLRenderer = function(width, height, view, transparent)
    + */
    +PIXI.WebGLRenderer = function(width, height, view, transparent, antialias)
     {
    -	// do a catch.. only 1 webGL renderer..
    +	// do a catch.. only 1 webGL renderer..
     
    -	//console.log(transparent)
     	this.transparent = !!transparent;
    -	
    +
     	this.width = width || 800;
     	this.height = height || 600;
    -	
    +
     	this.view = view || document.createElement( 'canvas' ); 
         this.view.width = this.width;
     	this.view.height = this.height;
    -	
    -	// deal with losing context..	
    +
    +	// deal with losing context..	
         var scope = this;
     	this.view.addEventListener('webglcontextlost', function(event) { scope.handleContextLost(event); }, false)
     	this.view.addEventListener('webglcontextrestored', function(event) { scope.handleContextRestored(event); }, false)
     
     	this.batchs = [];
    +
    +	var options = {
    +		alpha: this.transparent,
    +		antialias:!!antialias, // SPEED UP??
    +		premultipliedAlpha:false,
    +		stencil:true
    +	}
    +
    +	//try 'experimental-webgl'
    +	try {
    +		PIXI.gl = this.gl = this.view.getContext("experimental-webgl",  options);
    +	} catch (e) {
    +		//try 'webgl'
    +		try {
    +			PIXI.gl = this.gl = this.view.getContext("webgl",  options);
    +		} catch (e) {
    +			// fail, not able to get a context
    +			throw new Error(" This browser does not support webGL. Try using the canvas renderer" + this);
    +		}
    +	}
    +
    +    PIXI.initDefaultShaders();
    + 
    +
     	
    -	try 
    - 	{
    -        PIXI.gl = this.gl = this.view.getContext("experimental-webgl",  {  	
    -    		 alpha: this.transparent,
    -    		 antialias:true, // SPEED UP??
    -    		 premultipliedAlpha:false,
    -    		 stencil:true
    -        });
    -    } 
    -    catch (e) 
    -    {
    -    	throw new Error(" This browser does not support webGL. Try using the canvas renderer" + this);
    -    }
    -    
    -    PIXI.initPrimitiveShader();
    -    PIXI.initDefaultShader();
    -    PIXI.initDefaultStripShader();
    -    
    -    PIXI.activateDefaultShader();
    -    
    +
    +   // PIXI.activateDefaultShader();
    +
         var gl = this.gl;
    -    PIXI.WebGLRenderer.gl = gl;
         
    +    gl.useProgram(PIXI.defaultShader.program);
    +
    +
    +    PIXI.WebGLRenderer.gl = gl;
    +
         this.batch = new PIXI.WebGLBatch(gl);
        	gl.disable(gl.DEPTH_TEST);
        	gl.disable(gl.CULL_FACE);
    -   	
    -   	//
    -   	 
    -   	 
    +
         gl.enable(gl.BLEND);
         gl.colorMask(true, true, true, this.transparent); 
    -    
    +
         PIXI.projection = new PIXI.Point(400, 300);
    -    
    +    PIXI.offset = new PIXI.Point(0, 0);
    +
    +    // TODO remove thease globals..
    +
         this.resize(this.width, this.height);
         this.contextLost = false;
    -    
    +
    +	//PIXI.pushShader(PIXI.defaultShader);
    +
         this.stageRenderGroup = new PIXI.WebGLRenderGroup(this.gl);
    +    
     }
     
    -// constructor
    -PIXI.WebGLRenderer.constructor = PIXI.WebGLRenderer;
    +// constructor
    +PIXI.WebGLRenderer.prototype.constructor = PIXI.WebGLRenderer;
     
    -/**
    +/**
    + * Gets a new WebGLBatch from the pool
    + *
    + * @static
    + * @method getBatch
    + * @return {WebGLBatch}
      * @private 
    - */
    + */
     PIXI.WebGLRenderer.getBatch = function()
     {
     	if(PIXI._batchs.length == 0)
    @@ -250,86 +293,72 @@ PIXI.WebGLRenderer.getBatch = function()
     	}
     }
     
    -/**
    +/**
    + * Puts a batch back into the pool
    + *
    + * @static
    + * @method returnBatch
    + * @param batch {WebGLBatch} The batch to return
      * @private
    - */
    + */
     PIXI.WebGLRenderer.returnBatch = function(batch)
     {
     	batch.clean();	
     	PIXI._batchs.push(batch);
     }
     
    -
    -/**
    - * @private
    - */
    -
    -
    -
    -/**
    +/**
      * Renders the stage to its webGL view
    + *
      * @method render
    - * @param stage {Stage} the PIXI.Stage element to be rendered
    - */
    + * @param stage {Stage} the Stage element to be rendered
    + */
     PIXI.WebGLRenderer.prototype.render = function(stage)
     {
     	if(this.contextLost)return;
     	
     	
    -	// if rendering a new stage clear the batchs..
    +	// if rendering a new stage clear the batchs..
     	if(this.__stage !== stage)
     	{
    -		// TODO make this work
    -		// dont think this is needed any more?
    -		//if(this.__stage)this.checkVisibility(this.__stage, false)
    -		
    +		// TODO make this work
    +		// dont think this is needed any more?
     		this.__stage = stage;
     		this.stageRenderGroup.setRenderable(stage);
     	}
    -	
    -	// TODO not needed now... 
    -	// update children if need be
    -	// best to remove first!
    -	/*for (var i=0; i < stage.__childrenRemoved.length; i++)
    -	{
    -		var group = stage.__childrenRemoved[i].__renderGroup
    -		if(group)group.removeDisplayObject(stage.__childrenRemoved[i]);
    -	}*/
     
    -	// update any textures	
    +	// update any textures	
     	PIXI.WebGLRenderer.updateTextures();
     		
    -	// recursivly loop through all items!
    -	//this.checkVisibility(stage, true);
    -	
    -	// update the scene graph	
    +	// update the scene graph	
    +	PIXI.visibleCount++;
     	stage.updateTransform();
     	
     	var gl = this.gl;
     	
    -	// -- Does this need to be set every frame? -- //
    +	// -- Does this need to be set every frame? -- //
     	gl.colorMask(true, true, true, this.transparent); 
     	gl.viewport(0, 0, this.width, this.height);	
     	
    -	// set the correct matrix..	
    -   //	gl.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform, false, this.projectionMatrix);
    -   
        	gl.bindFramebuffer(gl.FRAMEBUFFER, null);
     		
     	gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent);     
     	gl.clear(gl.COLOR_BUFFER_BIT);
     
    -	// HACK TO TEST
    -	//PIXI.projectionMatrix = this.projectionMatrix;
    +	// HACK TO TEST
     	
     	this.stageRenderGroup.backgroundColor = stage.backgroundColorSplit;
    +	
    +	PIXI.projection.x =  this.width/2;
    +	PIXI.projection.y =  -this.height/2;
    +	
     	this.stageRenderGroup.render(PIXI.projection);
     	
    -	// interaction
    -	// run interaction!
    +	// interaction
    +	// run interaction!
     	if(stage.interactive)
     	{
    -		//need to add some events!
    +		//need to add some events!
     		if(!stage._interactiveEventsAdded)
     		{
     			stage._interactiveEventsAdded = true;
    @@ -337,7 +366,7 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
     		}
     	}
     	
    -	// after rendering lets confirm all frames that have been uodated..
    +	// after rendering lets confirm all frames that have been uodated..
     	if(PIXI.Texture.frameUpdates.length > 0)
     	{
     		for (var i=0; i < PIXI.Texture.frameUpdates.length; i++) 
    @@ -349,38 +378,51 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
     	}
     }
     
    -/**
    +/**
    + * Updates the textures loaded into this webgl renderer
    + *
    + * @static
    + * @method updateTextures
      * @private
    - */
    -
    + */
     PIXI.WebGLRenderer.updateTextures = function()
     {
    -	for (var i=0; i < PIXI.texturesToUpdate.length; i++) this.updateTexture(PIXI.texturesToUpdate[i]);
    -	for (var i=0; i < PIXI.texturesToDestroy.length; i++) this.destroyTexture(PIXI.texturesToDestroy[i]);
    +	//TODO break this out into a texture manager...
    +	for (var i=0; i < PIXI.texturesToUpdate.length; i++) PIXI.WebGLRenderer.updateTexture(PIXI.texturesToUpdate[i]);
    +	for (var i=0; i < PIXI.texturesToDestroy.length; i++) PIXI.WebGLRenderer.destroyTexture(PIXI.texturesToDestroy[i]);
     	PIXI.texturesToUpdate = [];
     	PIXI.texturesToDestroy = [];
     }
     
    +/**
    + * Updates a loaded webgl texture
    + *
    + * @static
    + * @method updateTexture
    + * @param texture {Texture} The texture to update
    + * @private
    + */
     PIXI.WebGLRenderer.updateTexture = function(texture)
     {
    +	//TODO break this out into a texture manager...
     	var gl = PIXI.gl;
     	
     	if(!texture._glTexture)
     	{
     		texture._glTexture = gl.createTexture();
     	}
    -	
    +
     	if(texture.hasLoaded)
     	{
     		gl.bindTexture(gl.TEXTURE_2D, texture._glTexture);
     	 	gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
    -	 	
    +
     		gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source);
     		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
     		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
    -		
    -		// reguler...
    -		
    +
    +		// reguler...
    +
     		if(!texture._powerOf2)
     		{
     			gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
    @@ -391,16 +433,23 @@ PIXI.WebGLRenderer.updateTexture = function(texture)
     			gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
     			gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
     		}
    -		
    +
     		gl.bindTexture(gl.TEXTURE_2D, null);
     	}
    -	
     }
     
    -PIXI.WebGLRenderer.prototype.destroyTexture = function(texture)
    +/**
    + * Destroys a loaded webgl texture
    + *
    + * @method destroyTexture
    + * @param texture {Texture} The texture to update
    + * @private
    + */
    +PIXI.WebGLRenderer.destroyTexture = function(texture)
     {
    -	var gl = this.gl;
    -	
    +	//TODO break this out into a texture manager...
    +	var gl = PIXI.gl;
    +
     	if(texture._glTexture)
     	{
     		texture._glTexture = gl.createTexture();
    @@ -408,72 +457,83 @@ PIXI.WebGLRenderer.prototype.destroyTexture = function(texture)
     	}
     }
     
    -/**
    +/**
      * resizes the webGL view to the specified width and height
    + *
      * @method resize
      * @param width {Number} the new width of the webGL view
      * @param height {Number} the new height of the webGL view
    - */
    + */
     PIXI.WebGLRenderer.prototype.resize = function(width, height)
     {
     	this.width = width;
     	this.height = height;
    -	
    +
     	this.view.width = width;
     	this.view.height = height;
    -	
    +
     	this.gl.viewport(0, 0, this.width, this.height);	
    +
    +	//var projectionMatrix = this.projectionMatrix;
    +
    +	PIXI.projection.x =  this.width/2;
    +	PIXI.projection.y =  -this.height/2;
     	
    -	//var projectionMatrix = this.projectionMatrix;
    -	
    -	PIXI.projection.x =  this.width/2;
    -	PIXI.projection.y =  this.height/2;
    -	
    -//	projectionMatrix[0] = 2/this.width;
    -//	projectionMatrix[5] = -2/this.height;
    -//	projectionMatrix[12] = -1;
    -//	projectionMatrix[13] = 1;
    +	//PIXI.size.x =  this.width/2;
    +	//PIXI.size.y =  -this.height/2;
    +
    +//	projectionMatrix[0] = 2/this.width;
    +//	projectionMatrix[5] = -2/this.height;
    +//	projectionMatrix[12] = -1;
    +//	projectionMatrix[13] = 1;
     }
     
    -/**
    +/**
    + * Handles a lost webgl context
    + *
    + * @method handleContextLost
    + * @param event {Event}
      * @private
    - */
    + */
     PIXI.WebGLRenderer.prototype.handleContextLost = function(event)
     {
     	event.preventDefault();
     	this.contextLost = true;
     }
     
    -/**
    +/**
    + * Handles a restored webgl context
    + *
    + * @method handleContextRestored
    + * @param event {Event}
      * @private
    - */
    + */
     PIXI.WebGLRenderer.prototype.handleContextRestored = function(event)
     {
     	this.gl = this.view.getContext("experimental-webgl",  {  	
     		alpha: true
         });
    -        
    +
     	this.initShaders();	
    -	
    +
     	for(var key in PIXI.TextureCache) 
     	{
             	var texture = PIXI.TextureCache[key].baseTexture;
             	texture._glTexture = null;
             	PIXI.WebGLRenderer.updateTexture(texture);
     	};
    -	
    +
     	for (var i=0; i <  this.batchs.length; i++) 
     	{
    -		this.batchs[i].restoreLostContext(this.gl)//
    +		this.batchs[i].restoreLostContext(this.gl)//
     		this.batchs[i].dirty = true;
     	};
    -	
    +
     	PIXI._restoreBatchs(this.gl);
    -	
    +
     	this.contextLost = false;
     }
     
    -
         
    @@ -483,13 +543,13 @@ PIXI.WebGLRenderer.prototype.handleContextRestored = function(event)
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_renderers_webgl_WebGLShaders.js.html b/docs/files/src_pixi_renderers_webgl_WebGLShaders.js.html index 1dff6c3..085bec1 100644 --- a/docs/files/src_pixi_renderers_webgl_WebGLShaders.js.html +++ b/docs/files/src_pixi_renderers_webgl_WebGLShaders.js.html @@ -2,12 +2,12 @@ - src/pixi/renderers/webgl/WebGLShaders.js - Pixi.JS - - - - - + src/pixi/renderers/webgl/WebGLShaders.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,167 +166,74 @@
    -

    File: src/pixi/renderers/webgl/WebGLShaders.js

    +

    File: src/pixi/renderers/webgl/WebGLShaders.js

    -
    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
     
    -/*
    - * the default suoer fast shader!
    - */
    +PIXI.initDefaultShaders = function() 
    +{
    +	PIXI.primitiveShader = new PIXI.PrimitiveShader();
    +  PIXI.primitiveShader.init();
     
    -PIXI.shaderFragmentSrc = [
    -  "precision mediump float;",
    -  "varying vec2 vTextureCoord;",
    -  "varying float vColor;",
    -  "uniform sampler2D uSampler;",
    -  "void main(void) {",
    -    "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));",
    -    "gl_FragColor = gl_FragColor * vColor;",
    -  "}"
    -];
    +  PIXI.stripShader = new PIXI.StripShader();
    +  PIXI.stripShader.init();
     
    -PIXI.shaderVertexSrc = [
    -  "attribute vec2 aVertexPosition;",
    -  "attribute vec2 aTextureCoord;",
    -  "attribute float aColor;",
    -  //"uniform mat4 uMVMatrix;",
    +	PIXI.defaultShader = new PIXI.PixiShader();
    +	PIXI.defaultShader.init();
    +
    +  var gl = PIXI.gl; 
    +  var shaderProgram = PIXI.defaultShader.program;
    + 
    +
    +  gl.useProgram(shaderProgram);
       
    -  "uniform vec2 projectionVector;",
    -  "varying vec2 vTextureCoord;",
    -  "varying float vColor;",
    -  "void main(void) {",
    -   // "gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0, 1.0);",
    -    "gl_Position = vec4( aVertexPosition.x / projectionVector.x -1.0, aVertexPosition.y / -projectionVector.y + 1.0 , 0.0, 1.0);",
    -    "vTextureCoord = aTextureCoord;",
    -    "vColor = aColor;",
    -  "}"
    -];
    -
    -/*
    - * the triangle strip shader..
    - */
    -
    -PIXI.stripShaderFragmentSrc = [
    -  "precision mediump float;",
    -  "varying vec2 vTextureCoord;",
    -  "varying float vColor;",
    -  "uniform float alpha;",
    -  "uniform sampler2D uSampler;",
    -  "void main(void) {",
    -    "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));",
    -    "gl_FragColor = gl_FragColor * alpha;",
    -  "}"
    -];
    -
    -
    -PIXI.stripShaderVertexSrc = [
    -  "attribute vec2 aVertexPosition;",
    -  "attribute vec2 aTextureCoord;",
    -  "attribute float aColor;",
    -  "uniform mat3 translationMatrix;",
    -  "uniform vec2 projectionVector;",
    -  "varying vec2 vTextureCoord;",
    -  "varying float vColor;",
    -  "void main(void) {",
    -	"vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);",
    -    "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);",
    -    "vTextureCoord = aTextureCoord;",
    -    "vColor = aColor;",
    -  "}"
    -];
    -
    -
    -/*
    - * primitive shader..
    - */
    -
    -PIXI.primitiveShaderFragmentSrc = [
    -  "precision mediump float;",
    -  "varying vec4 vColor;",
    -  "void main(void) {",
    -    "gl_FragColor = vColor;",
    -  "}"
    -];
    -
    -PIXI.primitiveShaderVertexSrc = [
    -  "attribute vec2 aVertexPosition;",
    -  "attribute vec4 aColor;",
    -  "uniform mat3 translationMatrix;",
    -  "uniform vec2 projectionVector;",
    -  "uniform float alpha;",
    -  "varying vec4 vColor;",
    -  "void main(void) {",
    -  	"vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);",
    -    "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);",
    -    "vColor = aColor  * alpha;",
    -  "}"
    -];
    -
    -PIXI.initPrimitiveShader = function() 
    -{
    -	var gl = PIXI.gl;
    -
    -	var shaderProgram = PIXI.compileProgram(PIXI.primitiveShaderVertexSrc, PIXI.primitiveShaderFragmentSrc)
    -	
    -    gl.useProgram(shaderProgram);
    -
    -    shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
    -    shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor");
    -    
    -    shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector");
    -    shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, "translationMatrix");
    -    
    -	shaderProgram.alpha = gl.getUniformLocation(shaderProgram, "alpha");
    -
    -	PIXI.primitiveProgram = shaderProgram;
    +  gl.enableVertexAttribArray(PIXI.defaultShader.aVertexPosition);
    +  gl.enableVertexAttribArray(PIXI.defaultShader.colorAttribute);
    +  gl.enableVertexAttribArray(PIXI.defaultShader.aTextureCoord);
     }
     
    -PIXI.initDefaultShader = function() 
    +PIXI.activatePrimitiveShader = function()
     {
    -	var gl = this.gl;
    -	var shaderProgram = PIXI.compileProgram(PIXI.shaderVertexSrc, PIXI.shaderFragmentSrc)
    -	
    -    gl.useProgram(shaderProgram);
    +  var gl = PIXI.gl;
    +  
    +  gl.useProgram(PIXI.primitiveShader.program);
    +  gl.disableVertexAttribArray(PIXI.defaultShader.aTextureCoord);
    +} 
     
    -    shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
    -    shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector");
    -    shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord");
    -	shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor");
    +PIXI.deactivatePrimitiveShader = function()
    +{
    +  var gl = PIXI.gl;
     
    -   // shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
    -    shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler");
    -    
    -	PIXI.shaderProgram = shaderProgram;
    +  gl.useProgram(PIXI.defaultShader.program);
    +  gl.enableVertexAttribArray(PIXI.defaultShader.aTextureCoord);
     }
     
    -PIXI.initDefaultStripShader = function() 
    +PIXI.activateStripShader = function()
     {
    -	var gl = this.gl;
    -	var shaderProgram = PIXI.compileProgram(PIXI.stripShaderVertexSrc, PIXI.stripShaderFragmentSrc)
    -	
    -    gl.useProgram(shaderProgram);
    +  var gl = PIXI.gl;
    +  
    +  gl.useProgram(PIXI.stripShader.program);
    + // gl.disableVertexAttribArray(PIXI.defaultShader.aTextureCoord);
    +} 
     
    -    shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
    -    shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector");
    -    shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord");
    -	shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, "translationMatrix");
    -	shaderProgram.alpha = gl.getUniformLocation(shaderProgram, "alpha");
    +PIXI.deactivateStripShader = function()
    +{
    +  var gl = PIXI.gl;
     
    -	shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor");
    -
    -    shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector");
    -    
    -    shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler");
    -    
    -	PIXI.stripShaderProgram = shaderProgram;
    +  gl.useProgram(PIXI.defaultShader.program);
    +  //gl.enableVertexAttribArray(PIXI.defaultShader.aTextureCoord);
     }
     
    +/*
    +
    +SHADER COMPILER HELPERS
    +*/
    +
     PIXI.CompileVertexShader = function(gl, shaderSrc)
     {
       return PIXI._CompileShader(gl, shaderSrc, gl.VERTEX_SHADER);
    @@ -321,7 +252,7 @@ PIXI._CompileShader = function(gl, shaderSrc, shaderType)
       gl.compileShader(shader);
     
       if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
    -    alert(gl.getShaderInfoLog(shader));
    +    console.log(gl.getShaderInfoLog(shader));
         return null;
       }
     
    @@ -342,42 +273,12 @@ PIXI.compileProgram = function(vertexSrc, fragmentSrc)
         gl.linkProgram(shaderProgram);
     
         if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
    -        alert("Could not initialise shaders");
    +        console.log("Could not initialise shaders");
         }
     
     	return shaderProgram;
     } 
     
    -
    -PIXI.activateDefaultShader = function()
    -{
    -	var gl = PIXI.gl;
    -	var shaderProgram = PIXI.shaderProgram;
    -	
    -	gl.useProgram(shaderProgram);
    -	
    -	
    -	gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);
    -    gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute);
    -    gl.enableVertexAttribArray(shaderProgram.colorAttribute);
    -}
    -
    -	
    -
    -PIXI.activatePrimitiveShader = function()
    -{
    -	var gl = PIXI.gl;
    -	
    -	gl.disableVertexAttribArray(PIXI.shaderProgram.textureCoordAttribute);
    -    gl.disableVertexAttribArray(PIXI.shaderProgram.colorAttribute);
    -    
    -	gl.useProgram(PIXI.primitiveProgram);
    -	
    -	gl.enableVertexAttribArray(PIXI.primitiveProgram.vertexPositionAttribute);
    -	gl.enableVertexAttribArray(PIXI.primitiveProgram.colorAttribute);
    -} 
    -
    -
         
    @@ -387,13 +288,13 @@ PIXI.activatePrimitiveShader = function()
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_text_BitmapText.js.html b/docs/files/src_pixi_text_BitmapText.js.html index 5e9bbc2..8c436af 100644 --- a/docs/files/src_pixi_text_BitmapText.js.html +++ b/docs/files/src_pixi_text_BitmapText.js.html @@ -2,12 +2,12 @@ - src/pixi/text/BitmapText.js - Pixi.JS - - - - - + src/pixi/text/BitmapText.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,27 +166,28 @@
    -

    File: src/pixi/text/BitmapText.js

    +

    File: src/pixi/text/BitmapText.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -/**
    +/**
      * A Text Object will create a line(s) of text using bitmap font. To split a line you can use "\n", "\r" or "\r\n"
    - * You can generate the fnt files using 
    - * http://www.angelcode.com/products/bmfont/ for windows or
    - * http://www.bmglyph.com/ for mac.
    + * You can generate the fnt files using
    + * http://www.angelcode.com/products/bmfont/ for windows or
    + * http://www.bmglyph.com/ for mac.
    + *
      * @class BitmapText
      * @extends DisplayObjectContainer
      * @constructor
    - * @param {String} text The copy that you would like the text to display
    - * @param {Object} style The style parameters
    - * @param {String} style.font The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously)
    - * @param {String} [style.align="left"] An alignment of the multiline text ("left", "center" or "right")
    - */
    + * @param text {String} The copy that you would like the text to display
    + * @param style {Object} The style parameters
    + * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously)
    + * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right")
    + */
     PIXI.BitmapText = function(text, style)
     {
         PIXI.DisplayObjectContainer.call(this);
    @@ -174,28 +199,30 @@ PIXI.BitmapText = function(text, style)
     
     };
     
    -// constructor
    -PIXI.BitmapText.constructor = PIXI.BitmapText;
    +// constructor
     PIXI.BitmapText.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
    +PIXI.BitmapText.prototype.constructor = PIXI.BitmapText;
     
    -/**
    +/**
      * Set the copy for the text object
    + *
      * @method setText
    - * @param {String} text The copy that you would like the text to display
    - */
    + * @param text {String} The copy that you would like the text to display
    + */
     PIXI.BitmapText.prototype.setText = function(text)
     {
         this.text = text || " ";
         this.dirty = true;
     };
     
    -/**
    +/**
      * Set the style of the text
    + *
      * @method setStyle
    - * @param {Object} style The style parameters
    - * @param {String} style.font The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously)
    - * @param {String} [style.align="left"] An alignment of the multiline text ("left", "center" or "right")
    - */
    + * @param style {Object} The style parameters
    + * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously)
    + * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right")
    + */
     PIXI.BitmapText.prototype.setStyle = function(style)
     {
         style = style || {};
    @@ -209,10 +236,12 @@ PIXI.BitmapText.prototype.setStyle = function(style)
         this.dirty = true;
     };
     
    -/**
    +/**
      * Renders text
    + *
    + * @method updateText
      * @private
    - */
    + */
     PIXI.BitmapText.prototype.updateText = function()
     {
         var data = PIXI.BitmapText.fonts[this.fontName];
    @@ -222,11 +251,11 @@ PIXI.BitmapText.prototype.updateText = function()
         var maxLineWidth = 0;
         var lineWidths = [];
         var line = 0;
    -    var scale = this.fontSize / data.size;
    +    var scale = this.fontSize / data.size;
         for(var i = 0; i < this.text.length; i++)
         {
             var charCode = this.text.charCodeAt(i);
    -        if(/(?:\r\n|\r|\n)/.test(this.text.charAt(i)))
    +        if(/(?:\r\n|\r|\n)/.test(this.text.charAt(i)))
             {
                 lineWidths.push(pos.x);
                 maxLineWidth = Math.max(maxLineWidth, pos.x);
    @@ -237,7 +266,7 @@ PIXI.BitmapText.prototype.updateText = function()
                 prevCharCode = null;
                 continue;
             }
    -        
    +
             var charData = data.chars[charCode];
             if(!charData) continue;
     
    @@ -264,14 +293,14 @@ PIXI.BitmapText.prototype.updateText = function()
             }
             else if(this.style.align == "center")
             {
    -            alignOffset = (maxLineWidth - lineWidths[i]) / 2;
    +            alignOffset = (maxLineWidth - lineWidths[i]) / 2;
             }
             lineAlignOffsets.push(alignOffset);
         }
     
         for(i = 0; i < chars.length; i++)
         {
    -        var c = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
    +        var c = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
             c.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
             c.position.y = chars[i].position.y * scale;
             c.scale.x = c.scale.y = scale;
    @@ -282,9 +311,12 @@ PIXI.BitmapText.prototype.updateText = function()
         this.height = (pos.y + data.lineHeight) * scale;
     };
     
    -/**
    +/**
    + * Updates the transfor of this object
    + *
    + * @method updateTransform
      * @private
    - */
    + */
     PIXI.BitmapText.prototype.updateTransform = function()
     {
     	if(this.dirty)
    @@ -297,11 +329,12 @@ PIXI.BitmapText.prototype.updateTransform = function()
     
             this.dirty = false;
     	}
    -	
    +
     	PIXI.DisplayObjectContainer.prototype.updateTransform.call(this);
     };
     
     PIXI.BitmapText.fonts = {};
    +
         
    @@ -311,13 +344,13 @@ PIXI.BitmapText.fonts = {};
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_text_Text.js.html b/docs/files/src_pixi_text_Text.js.html index 0ad9379..8702980 100644 --- a/docs/files/src_pixi_text_Text.js.html +++ b/docs/files/src_pixi_text_Text.js.html @@ -2,12 +2,12 @@ - src/pixi/text/Text.js - Pixi.JS - - - - - + src/pixi/text/Text.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,29 +166,30 @@
    -

    File: src/pixi/text/Text.js

    +

    File: src/pixi/text/Text.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -/**
    +/**
      * A Text Object will create a line(s) of text to split a line you can use "\n"
    + *
      * @class Text
      * @extends Sprite
      * @constructor
    - * @param {String} text The copy that you would like the text to display
    - * @param {Object} [style] The style parameters
    - * @param {String} [style.font] default "bold 20pt Arial" The style and size of the font
    - * @param {Object} [style.fill="black"] A canvas fillstyle that will be used on the text eg "red", "#00FF00"
    - * @param {String} [style.align="left"] An alignment of the multiline text ("left", "center" or "right")
    - * @param {String} [style.stroke] A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00"
    - * @param {Number} [style.strokeThickness=0] A number that represents the thickness of the stroke. Default is 0 (no stroke)
    - * @param {Boolean} [style.wordWrap=false] Indicates if word wrap should be used
    - * @param {Number} [style.wordWrapWidth=100] The width at which text will wrap
    - */
    + * @param text {String} The copy that you would like the text to display
    + * @param [style] {Object} The style parameters
    + * @param [style.font] {String} default "bold 20pt Arial" The style and size of the font
    + * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00"
    + * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right")
    + * @param [style.stroke] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00"
    + * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke)
    + * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used
    + * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap
    + */
     PIXI.Text = function(text, style)
     {
         this.canvas = document.createElement("canvas");
    @@ -173,34 +198,35 @@ PIXI.Text = function(text, style)
     
         this.setText(text);
         this.setStyle(style);
    -    
    -     this.updateText();
    +
    +    this.updateText();
         this.dirty = false;
     };
     
    -// constructor
    -PIXI.Text.constructor = PIXI.Text;
    +// constructor
     PIXI.Text.prototype = Object.create(PIXI.Sprite.prototype);
    +PIXI.Text.prototype.constructor = PIXI.Text;
     
    -/**
    +/**
      * Set the style of the text
    + *
      * @method setStyle
    - * @param {Object} [style] The style parameters
    - * @param {String} [style.font="bold 20pt Arial"] The style and size of the font
    - * @param {Object} [style.fill="black"] A canvas fillstyle that will be used on the text eg "red", "#00FF00"
    - * @param {String} [style.align="left"] An alignment of the multiline text ("left", "center" or "right")
    - * @param {String} [style.stroke="black"] A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00"
    - * @param {Number} [style.strokeThickness=0] A number that represents the thickness of the stroke. Default is 0 (no stroke)
    - * @param {Boolean} [style.wordWrap=false] Indicates if word wrap should be used
    - * @param {Number} [style.wordWrapWidth=100] The width at which text will wrap
    - */
    + * @param [style] {Object} The style parameters
    + * @param [style.font="bold 20pt Arial"] {String} The style and size of the font
    + * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00"
    + * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right")
    + * @param [style.stroke="black"] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00"
    + * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke)
    + * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used
    + * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap
    + */
     PIXI.Text.prototype.setStyle = function(style)
     {
         style = style || {};
         style.font = style.font || "bold 20pt Arial";
         style.fill = style.fill || "black";
         style.align = style.align || "left";
    -    style.stroke = style.stroke || "black"; //provide a default, see: https://github.com/GoodBoyDigital/pixi.js/issues/136
    +    style.stroke = style.stroke || "black"; //provide a default, see: https://github.com/GoodBoyDigital/pixi.js/issues/136
         style.strokeThickness = style.strokeThickness || 0;
         style.wordWrap = style.wordWrap || false;
         style.wordWrapWidth = style.wordWrapWidth || 100;
    @@ -208,35 +234,38 @@ PIXI.Text.prototype.setStyle = function(style)
         this.dirty = true;
     };
     
    -/**
    +/**
      * Set the copy for the text object. To split a line you can use "\n"
    + *
      * @methos setText
      * @param {String} text The copy that you would like the text to display
    - */
    -PIXI.Sprite.prototype.setText = function(text)
    + */
    +PIXI.Text.prototype.setText = function(text)
     {
         this.text = text.toString() || " ";
         this.dirty = true;
     };
     
    -/**
    +/**
      * Renders text
    + *
    + * @method updateText
      * @private
    - */
    + */
     PIXI.Text.prototype.updateText = function()
     {
     	this.context.font = this.style.font;
    -	
    +
     	var outputText = this.text;
    -	
    -	// word wrap
    -	// preserve original text
    +
    +	// word wrap
    +	// preserve original text
     	if(this.style.wordWrap)outputText = this.wordWrap(this.text);
     
    -	//split text into lines
    -	var lines = outputText.split(/(?:\r\n|\r|\n)/);
    +	//split text into lines
    +	var lines = outputText.split(/(?:\r\n|\r|\n)/);
     
    -	//calculate text width
    +	//calculate text width
     	var lineWidths = [];
     	var maxLineWidth = 0;
     	for (var i = 0; i < lines.length; i++)
    @@ -246,32 +275,32 @@ PIXI.Text.prototype.updateText = function()
     		maxLineWidth = Math.max(maxLineWidth, lineWidth);
     	}
     	this.canvas.width = maxLineWidth + this.style.strokeThickness;
    -	
    -	//calculate text height
    +
    +	//calculate text height
     	var lineHeight = this.determineFontHeight("font: " + this.style.font  + ";") + this.style.strokeThickness;
     	this.canvas.height = lineHeight * lines.length;
     
    -	//set canvas text styles
    +	//set canvas text styles
     	this.context.fillStyle = this.style.fill;
     	this.context.font = this.style.font;
    -	
    +
     	this.context.strokeStyle = this.style.stroke;
     	this.context.lineWidth = this.style.strokeThickness;
     
     	this.context.textBaseline = "top";
     
    -	//draw lines line by line
    +	//draw lines line by line
     	for (i = 0; i < lines.length; i++)
     	{
    -		var linePosition = new PIXI.Point(this.style.strokeThickness / 2, this.style.strokeThickness / 2 + i * lineHeight);
    -	
    +		var linePosition = new PIXI.Point(this.style.strokeThickness / 2, this.style.strokeThickness / 2 + i * lineHeight);
    +
     		if(this.style.align == "right")
     		{
     			linePosition.x += maxLineWidth - lineWidths[i];
     		}
     		else if(this.style.align == "center")
     		{
    -			linePosition.x += (maxLineWidth - lineWidths[i]) / 2;
    +			linePosition.x += (maxLineWidth - lineWidths[i]) / 2;
     		}
     
     		if(this.style.stroke && this.style.strokeThickness)
    @@ -284,52 +313,60 @@ PIXI.Text.prototype.updateText = function()
     			this.context.fillText(lines[i], linePosition.x, linePosition.y);
     		}
     	}
    -	
    +
         this.updateTexture();
     };
     
    -/**
    +/**
      * Updates texture size based on canvas size
    + *
    + * @method updateTexture
      * @private
    - */
    + */
     PIXI.Text.prototype.updateTexture = function()
     {
    -
         this.texture.baseTexture.width = this.canvas.width;
         this.texture.baseTexture.height = this.canvas.height;
         this.texture.frame.width = this.canvas.width;
         this.texture.frame.height = this.canvas.height;
    -    
    +
       	this._width = this.canvas.width;
         this._height = this.canvas.height;
    -	
    +
         PIXI.texturesToUpdate.push(this.texture.baseTexture);
     };
     
    -/**
    +/**
    + * Updates the transfor of this object
    + *
    + * @method updateTransform
      * @private
    - */
    + */
     PIXI.Text.prototype.updateTransform = function()
     {
     	if(this.dirty)
     	{
    -		this.updateText();	
    +		this.updateText();
     		this.dirty = false;
     	}
    -	
    +
     	PIXI.Sprite.prototype.updateTransform.call(this);
     };
     
    -/*
    - * http://stackoverflow.com/users/34441/ellisbben
    +/*
    + * http://stackoverflow.com/users/34441/ellisbben
      * great solution to the problem!
    - */
    -PIXI.Text.prototype.determineFontHeight = function(fontStyle) 
    + *
    + * @method determineFontHeight
    + * @param fontStyle {Object}
    + * @private
    + */
    +PIXI.Text.prototype.determineFontHeight = function(fontStyle)
     {
    -	// build a little reference dictionary so if the font style has been used return a
    -	// cached version...
    +	// build a little reference dictionary so if the font style has been used return a
    +	// cached version...
     	var result = PIXI.Text.heightCache[fontStyle];
    -	
    +
     	if(!result)
     	{
     		var body = document.getElementsByTagName("body")[0];
    @@ -338,30 +375,33 @@ PIXI.Text.prototype.determineFontHeight = function(fontStyle)
     		dummy.appendChild(dummyText);
     		dummy.setAttribute("style", fontStyle + ';position:absolute;top:0;left:0');
     		body.appendChild(dummy);
    -		
    +
     		result = dummy.offsetHeight;
     		PIXI.Text.heightCache[fontStyle] = result;
    -		
    +
     		body.removeChild(dummy);
     	}
    -	
    +
     	return result;
     };
     
    -/**
    +/**
      * A Text Object will apply wordwrap
    + *
    + * @method wordWrap
    + * @param text {String}
      * @private
    - */
    + */
     PIXI.Text.prototype.wordWrap = function(text)
     {
    -	// search good wrap position
    +	// search good wrap position
     	var searchWrapPos = function(ctx, text, start, end, wrapWidth)
     	{
    -		var p = Math.floor((end-start) / 2) + start;
    +		var p = Math.floor((end-start) / 2) + start;
     		if(p == start) {
     			return 1;
     		}
    -		
    +
     		if(ctx.measureText(text.substring(0,p)).width <= wrapWidth)
     		{
     			if(ctx.measureText(text.substring(0,p+1)).width > wrapWidth)
    @@ -378,7 +418,7 @@ PIXI.Text.prototype.wordWrap = function(text)
     			return arguments.callee(ctx, text, start, p, wrapWidth);
     		}
     	};
    -	 
    +
     	var lineWrap = function(ctx, text, wrapWidth)
     	{
     		if(ctx.measureText(text).width <= wrapWidth || text.length < 1)
    @@ -388,24 +428,30 @@ PIXI.Text.prototype.wordWrap = function(text)
     		var pos = searchWrapPos(ctx, text, 0, text.length, wrapWidth);
     		return text.substring(0, pos) + "\n" + arguments.callee(ctx, text.substring(pos), wrapWidth);
     	};
    -	
    +
     	var result = "";
     	var lines = text.split("\n");
     	for (var i = 0; i < lines.length; i++)
     	{
     		result += lineWrap(this.context, lines[i], this.style.wordWrapWidth) + "\n";
     	}
    -	
    +
     	return result;
     };
     
    +/**
    + * Destroys this text object
    + *
    + * @method destroy
    + * @param destroyTexture {Boolean}
    + */
     PIXI.Text.prototype.destroy = function(destroyTexture)
     {
     	if(destroyTexture)
     	{
     		this.texture.destroy();
     	}
    -		
    +
     };
     
     PIXI.Text.heightCache = {};
    @@ -419,13 +465,13 @@ PIXI.Text.heightCache = {};
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_textures_BaseTexture.js.html b/docs/files/src_pixi_textures_BaseTexture.js.html index 98f2ff6..b4888f2 100644 --- a/docs/files/src_pixi_textures_BaseTexture.js.html +++ b/docs/files/src_pixi_textures_BaseTexture.js.html @@ -2,12 +2,12 @@ - src/pixi/textures/BaseTexture.js - Pixi.JS - - - - - + src/pixi/textures/BaseTexture.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,83 +166,92 @@
    -

    File: src/pixi/textures/BaseTexture.js

    +

    File: src/pixi/textures/BaseTexture.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
     PIXI.BaseTextureCache = {};
     PIXI.texturesToUpdate = [];
     PIXI.texturesToDestroy = [];
     
    -/**
    +/**
      * A texture stores the information that represents an image. All textures have a base texture
    + *
      * @class BaseTexture
    - * @extends EventTarget
    + * @uses EventTarget
      * @constructor
      * @param source {String} the source object (image or canvas)
    - */
    + */
     PIXI.BaseTexture = function(source)
     {
     	PIXI.EventTarget.call( this );
    -	
    -	/*
    -	 * The url of the texture
    -	 * @property imageUrl
    -	 * @type String
    -	 */
    -	//this.imageUrl = source.src;
    -	
    -	/**
    -	 * [read only] The width of the base texture set when the image has loaded
    +
    +	/**
    +	 * [read-only] The width of the base texture set when the image has loaded
    +	 *
     	 * @property width
     	 * @type Number
    -	 */
    +	 * @readOnly
    +	 */
     	this.width = 100;
    -	/**
    -	 * [read only] The height of the base texture set when the image has loaded
    +
    +	/**
    +	 * [read-only] The height of the base texture set when the image has loaded
    +	 *
     	 * @property height
     	 * @type Number
    -	 */
    +	 * @readOnly
    +	 */
     	this.height = 100;
    -	
    -	/**
    +
    +	/**
    +	 * [read-only] Describes if the base texture has loaded or not
    +	 *
    +	 * @property hasLoaded
    +	 * @type Boolean
    +	 * @readOnly
    +	 */
    +	this.hasLoaded = false;
    +
    +	/**
     	 * The source that is loaded to create the texture
    +	 *
     	 * @property source
     	 * @type Image
    -	 */
    -	this.source = source//new Image();
    -	
    +	 */
    +	this.source = source;
    +
     	if(!source)return;
    -	
    -	if(this.source instanceof Image)
    +
    +	if(this.source instanceof Image || this.source instanceof HTMLImageElement)
     	{
     		if(this.source.complete)
     		{
     			this.hasLoaded = true;
     			this.width = this.source.width;
     			this.height = this.source.height;
    -			
    +
     			PIXI.texturesToUpdate.push(this);
     		}
     		else
     		{
    -			
    +
     			var scope = this;
     			this.source.onload = function(){
    -				
    +
     				scope.hasLoaded = true;
     				scope.width = scope.source.width;
     				scope.height = scope.source.height;
    -			
    -				// add it to somewhere...
    +
    +				// add it to somewhere...
     				PIXI.texturesToUpdate.push(scope);
     				scope.dispatchEvent( { type: 'loaded', content: scope } );
     			}
    -			//	this.image.src = imageUrl;
    +			//	this.image.src = imageUrl;
     		}
     	}
     	else
    @@ -226,16 +259,20 @@ PIXI.BaseTexture = function(source)
     		this.hasLoaded = true;
     		this.width = this.source.width;
     		this.height = this.source.height;
    -			
    +
     		PIXI.texturesToUpdate.push(this);
     	}
    -	
    +
     	this._powerOf2 = false;
    -	
     }
     
    -PIXI.BaseTexture.constructor = PIXI.BaseTexture;
    +PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture;
     
    +/**
    + * Destroys this base texture
    + *
    + * @method destroy
    + */
     PIXI.BaseTexture.prototype.destroy = function()
     {
     	if(this.source instanceof Image)
    @@ -246,23 +283,23 @@ PIXI.BaseTexture.prototype.destroy = function()
     	PIXI.texturesToDestroy.push(this);
     }
     
    -/**
    - * 
    +/**
      * Helper function that returns a base texture based on an image url
      * If the image is not in the base texture cache it will be  created and loaded
    + *
      * @static
      * @method fromImage
      * @param imageUrl {String} The image url of the texture
      * @return BaseTexture
    - */
    + */
     PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin)
     {
     	var baseTexture = PIXI.BaseTextureCache[imageUrl];
     	if(!baseTexture)
     	{
    -		// new Image() breaks tex loading in some versions of Chrome.
    -		// See https://code.google.com/p/chromium/issues/detail?id=238071
    -		var image = new Image();//document.createElement('img'); 
    +		// new Image() breaks tex loading in some versions of Chrome.
    +		// See https://code.google.com/p/chromium/issues/detail?id=238071
    +		var image = new Image();//document.createElement('img');
     		if (crossorigin)
     		{
     			image.crossOrigin = '';
    @@ -284,13 +321,13 @@ PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin)
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_textures_RenderTexture.js.html b/docs/files/src_pixi_textures_RenderTexture.js.html index 0c25c6d..9fbba1c 100644 --- a/docs/files/src_pixi_textures_RenderTexture.js.html +++ b/docs/files/src_pixi_textures_RenderTexture.js.html @@ -2,12 +2,12 @@ - src/pixi/textures/RenderTexture.js - Pixi.JS - - - - - + src/pixi/textures/RenderTexture.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,15 +166,15 @@
    -

    File: src/pixi/textures/RenderTexture.js

    +

    File: src/pixi/textures/RenderTexture.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -/**
    +/**
      A RenderTexture is a special texture that allows any pixi displayObject to be rendered to it.
     
      __Hint__: All DisplayObjects (exmpl. Sprites) that renders on RenderTexture should be preloaded. 
    @@ -160,8 +184,8 @@
      
     	var renderTexture = new PIXI.RenderTexture(800, 600);
     	var sprite = PIXI.Sprite.fromImage("spinObj_01.png");
    -	sprite.position.x = 800/2;
    -	sprite.position.y = 600/2;
    +	sprite.position.x = 800/2;
    +	sprite.position.y = 600/2;
     	sprite.anchor.x = 0.5;
     	sprite.anchor.y = 0.5;
     	renderTexture.render(sprite);
    @@ -170,25 +194,25 @@
     
     	var doc = new PIXI.DisplayObjectContainer();
     	doc.addChild(sprite);
    -	renderTexture.render(doc);  // Renders to center of renderTexture
    +	renderTexture.render(doc);  // Renders to center of renderTexture
     
      @class RenderTexture
      @extends Texture
      @constructor
    - @param width {Number}
    - @param height {Number}
    - **/
    + @param width {Number} The width of the render texture
    + @param height {Number} The height of the render texture
    + */
     PIXI.RenderTexture = function(width, height)
     {
     	PIXI.EventTarget.call( this );
    -	
    +
     	this.width = width || 100;
     	this.height = height || 100;
     
     	this.indetityMatrix = PIXI.mat3.create();
    -	
    +
     	this.frame = new PIXI.Rectangle(0, 0, this.width, this.height);	
    -	
    +
     	if(PIXI.gl)
     	{
     		this.initWebGL();
    @@ -199,19 +223,25 @@ PIXI.RenderTexture = function(width, height)
     	}
     }
     
    -PIXI.RenderTexture.constructor = PIXI.RenderTexture;
     PIXI.RenderTexture.prototype = Object.create( PIXI.Texture.prototype );
    +PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture;
     
    +/**
    + * Initializes the webgl data for this texture
    + *
    + * @method initWebGL
    + * @private
    + */
     PIXI.RenderTexture.prototype.initWebGL = function()
     {
     	var gl = PIXI.gl;
     	this.glFramebuffer = gl.createFramebuffer();
    -	
    +
        	gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer );
     
         this.glFramebuffer.width = this.width;
         this.glFramebuffer.height = this.height;	
    -  
    +
     	this.baseTexture = new PIXI.BaseTexture();
     
     	this.baseTexture.width = this.width;
    @@ -219,120 +249,175 @@ PIXI.RenderTexture.prototype.initWebGL = function()
     
         this.baseTexture._glTexture = gl.createTexture();
         gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture);
    -	 	
    +
     	gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA,  this.width,  this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
    -	
    +
         gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
     	gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
     	gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
     	gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
    -	
    +
     	this.baseTexture.isRender = true;
    -	
    +
     	gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer );
     	gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0);
    -	
    -	// create a projection matrix..
    -	this.projection = new PIXI.Point(this.width/2 , this.height/2);
    -	
    -	this.projectionMatrix =  PIXI.mat4.create();
    -	
    -	this.projectionMatrix[5] = 2/this.height// * 0.5;
    -	this.projectionMatrix[13] = -1;
    -	
    -	this.projectionMatrix[0] = 2/this.width;
    -	this.projectionMatrix[12] = -1;
     
    -	// set the correct render function..
    +	// create a projection matrix..
    +	this.projection = new PIXI.Point(this.width/2 , -this.height/2);
    +
    +	// set the correct render function..
     	this.render = this.renderWebGL;
     }
     
    +
    +PIXI.RenderTexture.prototype.resize = function(width, height)
    +{
    +
    +	this.width = width;
    +	this.height = height;
    +	
    +	if(PIXI.gl)
    +	{
    +		this.projection.x = this.width/2
    +		this.projection.y = -this.height/2;
    +	
    +		var gl = PIXI.gl;
    +		gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture);
    +		gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA,  this.width,  this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
    +	}
    +	else
    +	{
    +		
    +		this.frame.width = this.width
    +		this.frame.height = this.height;
    +		this.renderer.resize(this.width, this.height);
    +	}
    +}
    +
    +/**
    + * Initializes the canvas data for this texture
    + *
    + * @method initCanvas
    + * @private
    + */
     PIXI.RenderTexture.prototype.initCanvas = function()
     {
     	this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, 0);
    -	
    +
     	this.baseTexture = new PIXI.BaseTexture(this.renderer.view);
     	this.frame = new PIXI.Rectangle(0, 0, this.width, this.height);
    -	
    +
     	this.render = this.renderCanvas;
     }
     
    -/**
    +/**
      * This function will draw the display object to the texture.
    - * @method render
    - * @param displayObject {DisplayObject}
    + *
    + * @method renderWebGL
    + * @param displayObject {DisplayObject} The display object to render this texture on
      * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
    - */
    -PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear)
    + * @private
    + */
    +PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear)
     {
     	var gl = PIXI.gl;
    -	
    -	// enable the alpha color mask..
    +
    +	// enable the alpha color mask..
     	gl.colorMask(true, true, true, true); 
    -	
    +
     	gl.viewport(0, 0, this.width, this.height);	
    -	
    +
     	gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer );
    -	
    +
     	if(clear)
     	{
     		gl.clearColor(0,0,0, 0);     
     		gl.clear(gl.COLOR_BUFFER_BIT);
     	}
    -	
    -	// THIS WILL MESS WITH HIT TESTING!
    +
    +	// THIS WILL MESS WITH HIT TESTING!
     	var children = displayObject.children;
    -	
    -	//TODO -? create a new one??? dont think so!
    -	displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix;
    -	// modify to flip...
    +
    +	//TODO -? create a new one??? dont think so!
    +	var originalWorldTransform = displayObject.worldTransform;
    +	displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix;
    +	// modify to flip...
     	displayObject.worldTransform[4] = -1;
    -	displayObject.worldTransform[5] = this.projection.y * 2;
    +	displayObject.worldTransform[5] = this.projection.y * -2;
    +
    +	if(position)
    +	{
    +		displayObject.worldTransform[2] = position.x;
    +		displayObject.worldTransform[5] -= position.y;
    +	}
    +	
    +	PIXI.visibleCount++;
    +	displayObject.vcount = PIXI.visibleCount;
     	
     	for(var i=0,j=children.length; i<j; i++)
     	{
     		children[i].updateTransform();	
     	}
    -	
    +
     	var renderGroup = displayObject.__renderGroup;
     
     	if(renderGroup)
     	{
     		if(displayObject == renderGroup.root)
     		{
    -			renderGroup.render(this.projection);
    +			renderGroup.render(this.projection, this.glFramebuffer);
     		}
     		else
     		{
    -			renderGroup.renderSpecific(displayObject, this.projection);
    +			renderGroup.renderSpecific(displayObject, this.projection, this.glFramebuffer);
     		}
     	}
     	else
     	{
     		if(!this.renderGroup)this.renderGroup = new PIXI.WebGLRenderGroup(gl);
     		this.renderGroup.setRenderable(displayObject);
    -		this.renderGroup.render(this.projection);
    +		this.renderGroup.render(this.projection, this.glFramebuffer);
     	}
     	
    +	displayObject.worldTransform = originalWorldTransform;
     }
     
    -PIXI.RenderTexture.prototype.renderCanvas = function(displayObject, clear)
    +
    +/**
    + * This function will draw the display object to the texture.
    + *
    + * @method renderCanvas
    + * @param displayObject {DisplayObject} The display object to render this texture on
    + * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
    + * @private
    + */
    +PIXI.RenderTexture.prototype.renderCanvas = function(displayObject, position, clear)
     {
     	var children = displayObject.children;
    -	
    +
     	displayObject.worldTransform = PIXI.mat3.create();
     	
    +	if(position)
    +	{
    +		displayObject.worldTransform[2] = position.x;
    +		displayObject.worldTransform[5] = position.y;
    +	}
    +	
    +
     	for(var i=0,j=children.length; i<j; i++)
     	{
     		children[i].updateTransform();	
     	}
     
     	if(clear)this.renderer.context.clearRect(0,0, this.width, this.height);
    +	
         this.renderer.renderDisplayObject(displayObject);
         
    -    PIXI.texturesToUpdate.push(this.baseTexture);
    -}
    +    this.renderer.context.setTransform(1,0,0,1,0,0); 
    +    
     
    +  //  PIXI.texturesToUpdate.push(this.baseTexture);
    +}
     
         
    @@ -343,13 +428,13 @@ PIXI.RenderTexture.prototype.renderCanvas = function(displayObject, clear)
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_textures_Texture.js.html b/docs/files/src_pixi_textures_Texture.js.html index ac3027a..c60354b 100644 --- a/docs/files/src_pixi_textures_Texture.js.html +++ b/docs/files/src_pixi_textures_Texture.js.html @@ -2,12 +2,12 @@ - src/pixi/textures/Texture.js - Pixi.JS - - - - - + src/pixi/textures/Texture.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,63 +166,71 @@
    -

    File: src/pixi/textures/Texture.js

    +

    File: src/pixi/textures/Texture.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
     PIXI.TextureCache = {};
     PIXI.FrameCache = {};
     
    -/**
    - * A texture stores the information that represents an image or part of an image. It cannot be added to the display list directly. To do this use PIXI.Sprite. If no frame is provided then the whole image is used
    +/**
    + * A texture stores the information that represents an image or part of an image. It cannot be added
    + * to the display list directly. To do this use PIXI.Sprite. If no frame is provided then the whole image is used
    + *
      * @class Texture
    - * @extends EventTarget
    + * @uses EventTarget
      * @constructor
    - * @param baseTexture {BaseTexture}
    - * @param frmae {Rectangle}
    - */
    + * @param baseTexture {BaseTexture} The base texture source to create the texture from
    + * @param frame {Rectangle} The rectangle frame of the texture to show
    + */
     PIXI.Texture = function(baseTexture, frame)
     {
     	PIXI.EventTarget.call( this );
    -	
    +
     	if(!frame)
     	{
     		this.noFrame = true;
     		frame = new PIXI.Rectangle(0,0,1,1);
     	}
    -	
    -	this.trim = new PIXI.Point();
     
     	if(baseTexture instanceof PIXI.Texture)
     		baseTexture = baseTexture.baseTexture;
    -	
    -	/**
    +
    +	/**
     	 * The base texture of this texture
    +	 *
     	 * @property baseTexture
     	 * @type BaseTexture
    -	 */
    +	 */
     	this.baseTexture = baseTexture;
    -	
    -	
    -	
    -	/**
    +
    +	/**
     	 * The frame specifies the region of the base texture that this texture uses
    +	 *
     	 * @property frame
    -	 * @type #Rectangle
    -	 */
    +	 * @type Rectangle
    +	 */
     	this.frame = frame;
    -	
    +
    +	/**
    +	 * The trim point
    +	 *
    +	 * @property trim
    +	 * @type Point
    +	 */
    +	this.trim = new PIXI.Point();
    +
     	this.scope = this;
    -	
    +
     	if(baseTexture.hasLoaded)
     	{
     		if(this.noFrame)frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height);
    -		//console.log(frame)
    -		
    +		//console.log(frame)
    +
     		this.setFrame(frame);
     	}
     	else
    @@ -208,78 +240,94 @@ PIXI.Texture = function(baseTexture, frame)
     	}
     }
     
    -PIXI.Texture.constructor = PIXI.Texture;
    +PIXI.Texture.prototype.constructor = PIXI.Texture;
     
    +/**
    + * Called when the base texture is loaded
    + *
    + * @method onBaseTextureLoaded
    + * @param event
    + * @private
    + */
     PIXI.Texture.prototype.onBaseTextureLoaded = function(event)
     {
     	var baseTexture = this.baseTexture;
     	baseTexture.removeEventListener( 'loaded', this.onLoaded );
    -	
    +
     	if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height);
     	this.noFrame = false;
     	this.width = this.frame.width;
     	this.height = this.frame.height;
    -	
    +
     	this.scope.dispatchEvent( { type: 'update', content: this } );
     }
     
    +/**
    + * Destroys this texture
    + *
    + * @method destroy
    + * @param destroyBase {Boolean} Whether to destroy the base texture as well
    + */
     PIXI.Texture.prototype.destroy = function(destroyBase)
     {
     	if(destroyBase)this.baseTexture.destroy();
     }
     
    -/**
    +/**
      * Specifies the rectangle region of the baseTexture
    + *
      * @method setFrame
    - * @param frame {Rectangle}
    - */
    + * @param frame {Rectangle} The frame of the texture to set it to
    + */
     PIXI.Texture.prototype.setFrame = function(frame)
     {
     	this.frame = frame;
     	this.width = frame.width;
     	this.height = frame.height;
    -	
    +
     	if(frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height)
     	{
     		throw new Error("Texture Error: frame does not fit inside the base Texture dimensions " + this);
     	}
    -	
    +
     	this.updateFrame = true;
    -	
    +
     	PIXI.Texture.frameUpdates.push(this);
    -	//this.dispatchEvent( { type: 'update', content: this } );
    +	//this.dispatchEvent( { type: 'update', content: this } );
     }
     
    -/**
    - * 
    +/**
      * Helper function that returns a texture based on an image url
      * If the image is not in the texture cache it will be  created and loaded
    + *
      * @static
      * @method fromImage
      * @param imageUrl {String} The image url of the texture
    + * @param crossorigin {Boolean} Whether requests should be treated as crossorigin
      * @return Texture
    - */
    + */
     PIXI.Texture.fromImage = function(imageUrl, crossorigin)
     {
     	var texture = PIXI.TextureCache[imageUrl];
    -	
    +
     	if(!texture)
     	{
     		texture = new PIXI.Texture(PIXI.BaseTexture.fromImage(imageUrl, crossorigin));
     		PIXI.TextureCache[imageUrl] = texture;
     	}
    -	
    +
     	return texture;
     }
     
    -/**
    - * 
    +/**
      * Helper function that returns a texture based on a frame id
      * If the frame id is not in the texture cache an error will be thrown
    + *
    + * @static
      * @method fromFrame
      * @param frameId {String} The frame id of the texture
      * @return Texture
    - */
    + */
     PIXI.Texture.fromFrame = function(frameId)
     {
     	var texture = PIXI.TextureCache[frameId];
    @@ -287,15 +335,15 @@ PIXI.Texture.fromFrame = function(frameId)
     	return texture;
     }
     
    -/**
    - * 
    +/**
      * Helper function that returns a texture based on a canvas element
      * If the canvas is not in the texture cache it will be  created and loaded
    + *
      * @static
      * @method fromCanvas
      * @param canvas {Canvas} The canvas element source of the texture
      * @return Texture
    - */
    + */
     PIXI.Texture.fromCanvas = function(canvas)
     {
     	var	baseTexture = new PIXI.BaseTexture(canvas);
    @@ -303,27 +351,27 @@ PIXI.Texture.fromCanvas = function(canvas)
     }
     
     
    -/**
    - * 
    - * Adds a texture to the textureCache. 
    +/**
    + * Adds a texture to the textureCache.
    + *
      * @static
      * @method addTextureToCache
      * @param texture {Texture}
      * @param id {String} the id that the texture will be stored against.
    - */
    + */
     PIXI.Texture.addTextureToCache = function(texture, id)
     {
     	PIXI.TextureCache[id] = texture;
     }
     
    -/**
    - * 
    - * Remove a texture from the textureCache. 
    +/**
    + * Remove a texture from the textureCache.
    + *
      * @static
      * @method removeTextureFromCache
      * @param id {String} the id of the texture to be removed
      * @return {Texture} the texture that was removed
    - */
    + */
     PIXI.Texture.removeTextureFromCache = function(id)
     {
     	var texture = PIXI.TextureCache[id]
    @@ -331,7 +379,7 @@ PIXI.Texture.removeTextureFromCache = function(id)
     	return texture;
     }
     
    -// this is more for webGL.. it contains updated frames..
    +// this is more for webGL.. it contains updated frames..
     PIXI.Texture.frameUpdates = [];
     
     
    @@ -344,13 +392,13 @@ PIXI.Texture.frameUpdates = [];
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_utils_Detector.js.html b/docs/files/src_pixi_utils_Detector.js.html index 7dbe0d9..34e1f5a 100644 --- a/docs/files/src_pixi_utils_Detector.js.html +++ b/docs/files/src_pixi_utils_Detector.js.html @@ -2,12 +2,12 @@ - src/pixi/utils/Detector.js - Pixi.JS - - - - - + src/pixi/utils/Detector.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,37 +166,47 @@
    -

    File: src/pixi/utils/Detector.js

    +

    File: src/pixi/utils/Detector.js

    -/**
    - * @author Mat Groves http://matgroves.com/ @Doormat23
    - */
    +/**
    + * @author Mat Groves http://matgroves.com/ @Doormat23
    + */
     
    -/**
    +/**
      * This helper function will automatically detect which renderer you should be using.
    - * WebGL is the preferred renderer as it is a lot fastest. If webGL is not supported by the browser then this function will return a canvas renderer
    + * WebGL is the preferred renderer as it is a lot fastest. If webGL is not supported by
    + * the browser then this function will return a canvas renderer
    + *
      * @method autoDetectRenderer
      * @static
      * @param width {Number} the width of the renderers view
      * @param height {Number} the height of the renderers view
      * @param view {Canvas} the canvas to use as a view, optional
    - * @param transparent {Boolean} the transparency of the render view, default false
    - * @default false
    - */
    -PIXI.autoDetectRenderer = function(width, height, view, transparent)
    + * @param transparent=false {Boolean} the transparency of the render view, default false
    + * @param antialias=false {Boolean} sets antialias (only applicable in webGL chrome at the moment)
    + *
    + * antialias
    + */
    +PIXI.autoDetectRenderer = function(width, height, view, transparent, antialias)
     {
     	if(!width)width = 800;
     	if(!height)height = 600;
     
    -	// BORROWED from Mr Doob (mrdoob.com)
    -	var webgl = ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )();
    +	// BORROWED from Mr Doob (mrdoob.com)
    +	var webgl = ( function () { try { var canvas = document.createElement( 'canvas' ); return !! window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ); } catch( e ) { return false; } } )();
     
    -	//console.log(webgl);
    +	if(webgl)
    +	{
    +		var ie =  (navigator.userAgent.toLowerCase().indexOf('msie') != -1);
    +		 webgl = !ie;
    +	}
    +	
    +	//console.log(webgl);
     	if( webgl )
     	{
    -		return new PIXI.WebGLRenderer(width, height, view, transparent);
    +		return new PIXI.WebGLRenderer(width, height, view, transparent, antialias);
     	}
     
     	return	new PIXI.CanvasRenderer(width, height, view, transparent);
    @@ -189,13 +223,13 @@ PIXI.autoDetectRenderer = function(width, height, view, transparent)
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_utils_EventTarget.js.html b/docs/files/src_pixi_utils_EventTarget.js.html index e49f174..63cb9dd 100644 --- a/docs/files/src_pixi_utils_EventTarget.js.html +++ b/docs/files/src_pixi_utils_EventTarget.js.html @@ -2,12 +2,12 @@ - src/pixi/utils/EventTarget.js - Pixi.JS - - - - - + src/pixi/utils/EventTarget.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,26 +166,38 @@
    -

    File: src/pixi/utils/EventTarget.js

    +

    File: src/pixi/utils/EventTarget.js

    -/**
    - * https://github.com/mrdoob/eventtarget.js/
    +/**
    + * https://github.com/mrdoob/eventtarget.js/
      * THankS mr DOob!
    - */
    + */
     
    +/**
    + * Adds event emitter functionality to a class
    + *
    + * @class EventTarget
    + * @example
    + *		function MyEmitter() {
    + *			PIXI.EventTarget.call(this); //mixes in event target stuff
    + *		}
    + *
    + *		var em = new MyEmitter();
    + *		em.emit({ type: 'eventName', data: 'some data' });
    + */
     PIXI.EventTarget = function () {
     
     	var listeners = {};
    -	
    +
     	this.addEventListener = this.on = function ( type, listener ) {
    -		
    -		
    +
    +
     		if ( listeners[ type ] === undefined ) {
     
     			listeners[ type ] = [];
    -			
    +
     		}
     
     		if ( listeners[ type ].indexOf( listener ) === - 1 ) {
    @@ -172,11 +208,17 @@ PIXI.EventTarget = function () {
     	};
     
     	this.dispatchEvent = this.emit = function ( event ) {
    -		
    -		for ( var listener in listeners[ event.type ] ) {
     
    -			listeners[ event.type ][ listener ]( event );
    -			
    +		if ( !listeners[ event.type ] || !listeners[ event.type ].length ) {
    +
    +			return;
    +
    +		}
    +
    +		for(var i = 0, l = listeners[ event.type ].length; i < l; i++) {
    +
    +			listeners[ event.type ][ i ]( event );
    +
     		}
     
     	};
    @@ -204,13 +246,13 @@ PIXI.EventTarget = function () {
             
    - + - - - - - - + + + + + + diff --git a/docs/files/src_pixi_utils_Polyk.js.html b/docs/files/src_pixi_utils_Polyk.js.html new file mode 100644 index 0000000..00d055c --- /dev/null +++ b/docs/files/src_pixi_utils_Polyk.js.html @@ -0,0 +1,341 @@ + + + + + src/pixi/utils/Polyk.js - Pixi.JS + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.3.0 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: src/pixi/utils/Polyk.js

    + +
    +
    +/*
    +	PolyK library
    +	url: http://polyk.ivank.net
    +	Released under MIT licence.
    +
    +	Copyright (c) 2012 Ivan Kuckir
    +
    +	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.
    +
    +	This is an amazing lib!
    +
    +	slightly modified by mat groves (matgroves.com);
    +*/
    +
    +PIXI.PolyK = {};
    +
    +/**
    + * Triangulates shapes for webGL graphic fills
    + *
    + * @method Triangulate
    + * @namespace PolyK
    + * @constructor
    + */
    +PIXI.PolyK.Triangulate = function(p)
    +{
    +	var sign = true;
    +
    +	var n = p.length>>1;
    +	if(n<3) return [];
    +	var tgs = [];
    +	var avl = [];
    +	for(var i=0; i<n; i++) avl.push(i);
    +
    +	var i = 0;
    +	var al = n;
    +	while(al > 3)
    +	{
    +		var i0 = avl[(i+0)%al];
    +		var i1 = avl[(i+1)%al];
    +		var i2 = avl[(i+2)%al];
    +
    +		var ax = p[2*i0],  ay = p[2*i0+1];
    +		var bx = p[2*i1],  by = p[2*i1+1];
    +		var cx = p[2*i2],  cy = p[2*i2+1];
    +
    +		var earFound = false;
    +		if(PIXI.PolyK._convex(ax, ay, bx, by, cx, cy, sign))
    +		{
    +			earFound = true;
    +			for(var j=0; j<al; j++)
    +			{
    +				var vi = avl[j];
    +				if(vi==i0 || vi==i1 || vi==i2) continue;
    +				if(PIXI.PolyK._PointInTriangle(p[2*vi], p[2*vi+1], ax, ay, bx, by, cx, cy)) {earFound = false; break;}
    +			}
    +		}
    +		if(earFound)
    +		{
    +			tgs.push(i0, i1, i2);
    +			avl.splice((i+1)%al, 1);
    +			al--;
    +			i = 0;
    +		}
    +		else if(i++ > 3*al)
    +		{
    +			// need to flip flip reverse it!
    +			// reset!
    +			if(sign)
    +			{
    +				var tgs = [];
    +				avl = [];
    +				for(var i=0; i<n; i++) avl.push(i);
    +
    +				i = 0;
    +				al = n;
    +
    +				sign = false;
    +			}
    +			else
    +			{
    +				console.log("PIXI Warning: shape too complex to fill")
    +				return [];
    +			}
    +		}
    +	}
    +	tgs.push(avl[0], avl[1], avl[2]);
    +	return tgs;
    +}
    +
    +/**
    + * Checks if a point is within a triangle
    + *
    + * @class _PointInTriangle
    + * @namespace PolyK
    + * @private
    + */
    +PIXI.PolyK._PointInTriangle = function(px, py, ax, ay, bx, by, cx, cy)
    +{
    +	var v0x = cx-ax;
    +	var v0y = cy-ay;
    +	var v1x = bx-ax;
    +	var v1y = by-ay;
    +	var v2x = px-ax;
    +	var v2y = py-ay;
    +
    +	var dot00 = v0x*v0x+v0y*v0y;
    +	var dot01 = v0x*v1x+v0y*v1y;
    +	var dot02 = v0x*v2x+v0y*v2y;
    +	var dot11 = v1x*v1x+v1y*v1y;
    +	var dot12 = v1x*v2x+v1y*v2y;
    +
    +	var invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
    +	var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
    +	var v = (dot00 * dot12 - dot01 * dot02) * invDenom;
    +
    +	// Check if point is in triangle
    +	return (u >= 0) && (v >= 0) && (u + v < 1);
    +}
    +
    +/**
    + * Checks if a shape is convex
    + *
    + * @class _convex
    + * @namespace PolyK
    + * @private
    + */
    +PIXI.PolyK._convex = function(ax, ay, bx, by, cx, cy, sign)
    +{
    +	return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) == sign;
    +}
    +
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_pixi_utils_Utils.js.html b/docs/files/src_pixi_utils_Utils.js.html index 0e7d63a..15fcb57 100644 --- a/docs/files/src_pixi_utils_Utils.js.html +++ b/docs/files/src_pixi_utils_Utils.js.html @@ -2,12 +2,12 @@ - src/pixi/utils/Utils.js - Pixi.JS - - - - - + src/pixi/utils/Utils.js - Pixi.JS + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -142,90 +166,113 @@
    -

    File: src/pixi/utils/Utils.js

    +

    File: src/pixi/utils/Utils.js

    -// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
    -// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
    +// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
    +// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
     
    -// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
    +// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
     
    -// MIT license
    +// MIT license
     
    +/**
    + * A polyfill for requestAnimationFrame
    + *
    + * @method requestAnimationFrame
    + */
    +/**
    + * A polyfill for cancelAnimationFrame
    + *
    + * @method cancelAnimationFrame
    + */
    +var lastTime = 0;
    +var vendors = ['ms', 'moz', 'webkit', 'o'];
    +for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
    +    window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
    +    window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
    +                               || window[vendors[x]+'CancelRequestAnimationFrame'];
    +}
     
    -    var lastTime = 0;
    -    var vendors = ['ms', 'moz', 'webkit', 'o'];
    -    for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
    -        window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
    -        window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] 
    -                                   || window[vendors[x]+'CancelRequestAnimationFrame'];
    -    }
    +if (!window.requestAnimationFrame)
    +    window.requestAnimationFrame = function(callback, element) {
    +        var currTime = new Date().getTime();
    +        var timeToCall = Math.max(0, 16 - (currTime - lastTime));
    +        var id = window.setTimeout(function() { callback(currTime + timeToCall); },
    +          timeToCall);
    +        lastTime = currTime + timeToCall;
    +        return id;
    +    };
     
    -    if (!window.requestAnimationFrame)
    -        window.requestAnimationFrame = function(callback, element) {
    -            var currTime = new Date().getTime();
    -            var timeToCall = Math.max(0, 16 - (currTime - lastTime));
    -            var id = window.setTimeout(function() { callback(currTime + timeToCall); }, 
    -              timeToCall);
    -            lastTime = currTime + timeToCall;
    -            return id;
    -        };
    -
    -    if (!window.cancelAnimationFrame)
    -        window.cancelAnimationFrame = function(id) {
    -            clearTimeout(id);
    -        };
    +if (!window.cancelAnimationFrame)
    +    window.cancelAnimationFrame = function(id) {
    +        clearTimeout(id);
    +    };
     
     window.requestAnimFrame = window.requestAnimationFrame;
     
    +/**
    + * Converts a hex color number to an [R, G, B] array
    + *
    + * @method HEXtoRGB
    + * @param hex {Number}
    + */
     function HEXtoRGB(hex) {
    -	return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
    +	return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
     }
     
    -/**
    - * Provides bind in a cross browser way.
    - */
    +/**
    + * A polyfill for Function.prototype.bind
    + *
    + * @method bind
    + */
     if (typeof Function.prototype.bind != 'function') {
       Function.prototype.bind = (function () {
         var slice = Array.prototype.slice;
         return function (thisArg) {
           var target = this, boundArgs = slice.call(arguments, 1);
    - 
    +
           if (typeof target != 'function') throw new TypeError();
    - 
    +
           function bound() {
     	var args = boundArgs.concat(slice.call(arguments));
     	target.apply(this instanceof bound ? this : thisArg, args);
           }
    - 
    +
           bound.prototype = (function F(proto) {
               proto && (F.prototype = proto);
    -          if (!(this instanceof F)) return new F;          
    +          if (!(this instanceof F)) return new F;
     	})(target.prototype);
    - 
    +
           return bound;
         };
       })();
     }
     
    +/**
    + * A wrapper for ajax requests to be handled cross browser
    + *
    + * @class AjaxRequest
    + * @constructor
    + */
     var AjaxRequest = PIXI.AjaxRequest = function()
     {
    -	var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
    -	
    +	var activexmodes = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.3.0", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
    +
     	if (window.ActiveXObject)
    -	{ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
    +	{ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
     		for (var i=0; i<activexmodes.length; i++)
     		{
     			try{
     				return new ActiveXObject(activexmodes[i])
     			}
        			catch(e){
    -    			//suppress error
    +    			//suppress error
        			}
     		}
     	}
    -	else if (window.XMLHttpRequest) // if Mozilla, Safari etc
    +	else if (window.XMLHttpRequest) // if Mozilla, Safari etc
       	{
       		return new XMLHttpRequest()
      	}
    @@ -235,9 +282,9 @@ var AjaxRequest = PIXI.AjaxRequest = function()
      	}
     }
     
    -/*
    +/*
      * DEBUGGING ONLY
    - */
    + */
     PIXI.runList = function(item)
     {
     	console.log(">>>>>>>>>")
    @@ -245,21 +292,20 @@ PIXI.runList = function(item)
     	var safe = 0;
     	var tmp = item.first;
     	console.log(tmp);
    -	
    +
     	while(tmp._iNext)
     	{
     		safe++;
    -//		console.log(tmp.childIndex + tmp);
     		tmp = tmp._iNext;
    -		console.log(tmp);//.childIndex);
    -	//	console.log(tmp);
    -	
    +		console.log(tmp);
    +	//	console.log(tmp);
    +
     		if(safe > 100)
     		{
     			console.log("BREAK")
     			break
     		}
    -	}	
    +	}
     }
     
     
    @@ -276,13 +322,13 @@ PIXI.runList = function(item)
             
    - + - - - - - - + + + + + + diff --git a/docs/index.html b/docs/index.html index 6de3004..1b0f5e0 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3,11 +3,11 @@ Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    - + - - - - - - + + + + + + diff --git a/docs/modules/PIXI.html b/docs/modules/PIXI.html index 52f88e4..9a9e653 100644 --- a/docs/modules/PIXI.html +++ b/docs/modules/PIXI.html @@ -3,11 +3,11 @@ PIXI - Pixi.JS - - - - - + + + + + @@ -15,7 +15,7 @@
    -

    +

    @@ -41,71 +41,95 @@ @@ -150,7 +174,7 @@ @@ -173,181 +197,253 @@
    - + - - - - - - + + + + + + diff --git a/examples/example 1 - Basics/index.html b/examples/example 1 - Basics/index.html index 543a6db..be99acc 100644 --- a/examples/example 1 - Basics/index.html +++ b/examples/example 1 - Basics/index.html @@ -9,46 +9,46 @@ background-color: #000000; } - + + + + diff --git a/examples/example 10 - Text/pixi.js b/examples/example 10 - Text/pixi.js deleted file mode 100644 index a6e7055..0000000 --- a/examples/example 10 - Text/pixi.js +++ /dev/null @@ -1,10438 +0,0 @@ -/** - * @license - * Pixi.JS - v1.3.0 - * Copyright (c) 2012, Mat Groves - * http://goodboydigital.com/ - * - * Compiled: 2013-07-24 - * - * Pixi.JS is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license.php - */ -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -(function(){ - - var root = this; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * @module PIXI - */ -var PIXI = PIXI || {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis. - * - * @class Point - * @constructor - * @param x {Number} position of the point - * @param y {Number} position of the point - */ -PIXI.Point = function(x, y) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; -} - -/** - * Creates a clone of this point - * - * @method clone - * @return {Point} a copy of the point - */ -PIXI.Point.prototype.clone = function() -{ - return new PIXI.Point(this.x, this.y); -} - -// constructor -PIXI.Point.prototype.constructor = PIXI.Point; - - -/** - * @author Mat Groves http://matgroves.com/ - */ - -/** - * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. - * - * @class Rectangle - * @constructor - * @param x {Number} The X coord of the upper-left corner of the rectangle - * @param y {Number} The Y coord of the upper-left corner of the rectangle - * @param width {Number} The overall wisth of this rectangle - * @param height {Number} The overall height of this rectangle - */ -PIXI.Rectangle = function(x, y, width, height) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property width - * @type Number - * @default 0 - */ - this.width = width || 0; - - /** - * @property height - * @type Number - * @default 0 - */ - this.height = height || 0; -} - -/** - * Creates a clone of this Rectangle - * - * @method clone - * @return {Rectangle} a copy of the rectangle - */ -PIXI.Rectangle.prototype.clone = function() -{ - return new PIXI.Rectangle(this.x, this.y, this.width, this.height); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this Rectangle - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this Rectangle - */ -PIXI.Rectangle.prototype.contains = function(x, y) -{ - if(this.width <= 0 || this.height <= 0) - return false; - - var x1 = this.x; - if(x > x1 && x < x1 + this.width) - { - var y1 = this.y; - - if(y > y1 && y < y1 + this.height) - { - return true; - } - } - - return false; -} - -// constructor -PIXI.Rectangle.prototype.constructor = PIXI.Rectangle; - - -/** - * @author Adrien Brault - */ - -/** - * @class Polygon - * @constructor - * @param points* {Array|Array|Point...|Number...} This can be an array of Points that form the polygon, - * a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arugments passed can be - * all the points of the polygon e.g. `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the - * arguments passed can be flat x,y values e.g. `new PIXI.Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are - * Numbers. - */ -PIXI.Polygon = function(points) -{ - //if points isn't an array, use arguments as the array - if(!(points instanceof Array)) - points = Array.prototype.slice.call(arguments); - - //if this is a flat array of numbers, convert it to points - if(typeof points[0] === 'number') { - var p = []; - for(var i = 0, il = points.length; i < il; i+=2) { - p.push( - new PIXI.Point(points[i], points[i + 1]) - ); - } - - points = p; - } - - this.points = points; -} - -/** - * Creates a clone of this polygon - * - * @method clone - * @return {Polygon} a copy of the polygon - */ -PIXI.Polygon.prototype.clone = function() -{ - var points = []; - for (var i=0; i y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi); - - if(intersect) inside = !inside; - } - - return inside; -} - -PIXI.Polygon.prototype.constructor = PIXI.Polygon; - - -/** - * @author Chad Engler - */ - -/** - * The Circle object can be used to specify a hit area for displayobjects - * - * @class Circle - * @constructor - * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this circle - * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this circle - * @param radius {Number} The radius of the circle - */ -PIXI.Circle = function(x, y, radius) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property radius - * @type Number - * @default 0 - */ - this.radius = radius || 0; -} - -/** - * Creates a clone of this Circle instance - * - * @method clone - * @return {Circle} a copy of the polygon - */ -PIXI.Circle.prototype.clone = function() -{ - return new PIXI.Circle(this.x, this.y, this.radius); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this circle - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this polygon - */ -PIXI.Circle.prototype.contains = function(x, y) -{ - if(this.radius <= 0) - return false; - - var dx = (this.x - x), - dy = (this.y - y), - r2 = this.radius * this.radius; - - dx *= dx; - dy *= dy; - - return (dx + dy <= r2); -} - -PIXI.Circle.prototype.constructor = PIXI.Circle; - - -/** - * @author Chad Engler - */ - -/** - * The Ellipse object can be used to specify a hit area for displayobjects - * - * @class Ellipse - * @constructor - * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this ellipse - * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this ellipse - * @param width {Number} The overall height of this ellipse - * @param height {Number} The overall width of this ellipse - */ -PIXI.Ellipse = function(x, y, width, height) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property width - * @type Number - * @default 0 - */ - this.width = width || 0; - - /** - * @property height - * @type Number - * @default 0 - */ - this.height = height || 0; -} - -/** - * Creates a clone of this Ellipse instance - * - * @method clone - * @return {Ellipse} a copy of the ellipse - */ -PIXI.Ellipse.prototype.clone = function() -{ - return new PIXI.Ellipse(this.x, this.y, this.width, this.height); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this ellipse - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this ellipse - */ -PIXI.Ellipse.prototype.contains = function(x, y) -{ - if(this.width <= 0 || this.height <= 0) - return false; - - //normalize the coords to an ellipse with center 0,0 - //and a radius of 0.5 - var normx = ((x - this.x) / this.width) - 0.5, - normy = ((y - this.y) / this.height) - 0.5; - - normx *= normx; - normy *= normy; - - return (normx + normy < 0.25); -} - -PIXI.Ellipse.getBounds = function() -{ - return new PIXI.Rectangle(this.x, this.y, this.width, this.height); -} - -PIXI.Ellipse.prototype.constructor = PIXI.Ellipse; - - - - -/* - * A lighter version of the rad gl-matrix created by Brandon Jones, Colin MacKenzie IV - * you both rock! - */ - -function determineMatrixArrayType() { - PIXI.Matrix = (typeof Float32Array !== 'undefined') ? Float32Array : Array; - return PIXI.Matrix; -} - -determineMatrixArrayType(); - -PIXI.mat3 = {}; - -PIXI.mat3.create = function() -{ - var matrix = new PIXI.Matrix(9); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 1; - matrix[5] = 0; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 1; - - return matrix; -} - - -PIXI.mat3.identity = function(matrix) -{ - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 1; - matrix[5] = 0; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 1; - - return matrix; -} - - -PIXI.mat4 = {}; - -PIXI.mat4.create = function() -{ - var matrix = new PIXI.Matrix(16); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 0; - matrix[5] = 1; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 0; - matrix[9] = 0; - matrix[10] = 1; - matrix[11] = 0; - matrix[12] = 0; - matrix[13] = 0; - matrix[14] = 0; - matrix[15] = 1; - - return matrix; -} - -PIXI.mat3.multiply = function (mat, mat2, dest) -{ - if (!dest) { dest = mat; } - - // Cache the matrix values (makes for huge speed increases!) - var a00 = mat[0], a01 = mat[1], a02 = mat[2], - a10 = mat[3], a11 = mat[4], a12 = mat[5], - a20 = mat[6], a21 = mat[7], a22 = mat[8], - - b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], - b10 = mat2[3], b11 = mat2[4], b12 = mat2[5], - b20 = mat2[6], b21 = mat2[7], b22 = mat2[8]; - - dest[0] = b00 * a00 + b01 * a10 + b02 * a20; - dest[1] = b00 * a01 + b01 * a11 + b02 * a21; - dest[2] = b00 * a02 + b01 * a12 + b02 * a22; - - dest[3] = b10 * a00 + b11 * a10 + b12 * a20; - dest[4] = b10 * a01 + b11 * a11 + b12 * a21; - dest[5] = b10 * a02 + b11 * a12 + b12 * a22; - - dest[6] = b20 * a00 + b21 * a10 + b22 * a20; - dest[7] = b20 * a01 + b21 * a11 + b22 * a21; - dest[8] = b20 * a02 + b21 * a12 + b22 * a22; - - return dest; -} - -PIXI.mat3.clone = function(mat) -{ - var matrix = new PIXI.Matrix(9); - - matrix[0] = mat[0]; - matrix[1] = mat[1]; - matrix[2] = mat[2]; - matrix[3] = mat[3]; - matrix[4] = mat[4]; - matrix[5] = mat[5]; - matrix[6] = mat[6]; - matrix[7] = mat[7]; - matrix[8] = mat[8]; - - return matrix; -} - -PIXI.mat3.transpose = function (mat, dest) -{ - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (!dest || mat === dest) { - var a01 = mat[1], a02 = mat[2], - a12 = mat[5]; - - mat[1] = mat[3]; - mat[2] = mat[6]; - mat[3] = a01; - mat[5] = mat[7]; - mat[6] = a02; - mat[7] = a12; - return mat; - } - - dest[0] = mat[0]; - dest[1] = mat[3]; - dest[2] = mat[6]; - dest[3] = mat[1]; - dest[4] = mat[4]; - dest[5] = mat[7]; - dest[6] = mat[2]; - dest[7] = mat[5]; - dest[8] = mat[8]; - return dest; -} - -PIXI.mat3.toMat4 = function (mat, dest) -{ - if (!dest) { dest = PIXI.mat4.create(); } - - dest[15] = 1; - dest[14] = 0; - dest[13] = 0; - dest[12] = 0; - - dest[11] = 0; - dest[10] = mat[8]; - dest[9] = mat[7]; - dest[8] = mat[6]; - - dest[7] = 0; - dest[6] = mat[5]; - dest[5] = mat[4]; - dest[4] = mat[3]; - - dest[3] = 0; - dest[2] = mat[2]; - dest[1] = mat[1]; - dest[0] = mat[0]; - - return dest; -} - - -///// - - -PIXI.mat4.create = function() -{ - var matrix = new PIXI.Matrix(16); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 0; - matrix[5] = 1; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 0; - matrix[9] = 0; - matrix[10] = 1; - matrix[11] = 0; - matrix[12] = 0; - matrix[13] = 0; - matrix[14] = 0; - matrix[15] = 1; - - return matrix; -} - -PIXI.mat4.transpose = function (mat, dest) -{ - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (!dest || mat === dest) - { - var a01 = mat[1], a02 = mat[2], a03 = mat[3], - a12 = mat[6], a13 = mat[7], - a23 = mat[11]; - - mat[1] = mat[4]; - mat[2] = mat[8]; - mat[3] = mat[12]; - mat[4] = a01; - mat[6] = mat[9]; - mat[7] = mat[13]; - mat[8] = a02; - mat[9] = a12; - mat[11] = mat[14]; - mat[12] = a03; - mat[13] = a13; - mat[14] = a23; - return mat; - } - - dest[0] = mat[0]; - dest[1] = mat[4]; - dest[2] = mat[8]; - dest[3] = mat[12]; - dest[4] = mat[1]; - dest[5] = mat[5]; - dest[6] = mat[9]; - dest[7] = mat[13]; - dest[8] = mat[2]; - dest[9] = mat[6]; - dest[10] = mat[10]; - dest[11] = mat[14]; - dest[12] = mat[3]; - dest[13] = mat[7]; - dest[14] = mat[11]; - dest[15] = mat[15]; - return dest; -} - -PIXI.mat4.multiply = function (mat, mat2, dest) -{ - if (!dest) { dest = mat; } - - // Cache the matrix values (makes for huge speed increases!) - var a00 = mat[ 0], a01 = mat[ 1], a02 = mat[ 2], a03 = mat[3]; - var a10 = mat[ 4], a11 = mat[ 5], a12 = mat[ 6], a13 = mat[7]; - var a20 = mat[ 8], a21 = mat[ 9], a22 = mat[10], a23 = mat[11]; - var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15]; - - // Cache only the current line of the second matrix - var b0 = mat2[0], b1 = mat2[1], b2 = mat2[2], b3 = mat2[3]; - dest[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[4]; - b1 = mat2[5]; - b2 = mat2[6]; - b3 = mat2[7]; - dest[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[8]; - b1 = mat2[9]; - b2 = mat2[10]; - b3 = mat2[11]; - dest[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[12]; - b1 = mat2[13]; - b2 = mat2[14]; - b3 = mat2[15]; - dest[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - return dest; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The base class for all objects that are rendered on the screen. - * - * @class DisplayObject - * @constructor - */ -PIXI.DisplayObject = function() -{ - this.last = this; - this.first = this; - - /** - * The coordinate of the object relative to the local coordinates of the parent. - * - * @property position - * @type Point - */ - this.position = new PIXI.Point(); - - /** - * The scale factor of the object. - * - * @property scale - * @type Point - */ - this.scale = new PIXI.Point(1,1);//{x:1, y:1}; - - /** - * The pivot point of the displayObject that it rotates around - * - * @property pivot - * @type Point - */ - this.pivot = new PIXI.Point(0,0); - - /** - * The rotation of the object in radians. - * - * @property rotation - * @type Number - */ - this.rotation = 0; - - /** - * The opacity of the object. - * - * @property alpha - * @type Number - */ - this.alpha = 1; - - /** - * The visibility of the object. - * - * @property visible - * @type Boolean - */ - this.visible = true; - - /** - * This is the defined area that will pick up mouse / touch events. It is null by default. - * Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children) - * - * @property hitArea - * @type Rectangle|Circle|Ellipse|Polygon - */ - this.hitArea = null; - - /** - * This is used to indicate if the displayObject should display a mouse hand cursor on rollover - * - * @property buttonMode - * @type Boolean - */ - this.buttonMode = false; - - /** - * Can this object be rendered - * - * @property renderable - * @type Boolean - */ - this.renderable = false; - - /** - * [read-only] The visibility of the object based on world (parent) factors. - * - * @property worldVisible - * @type Boolean - * @readOnly - */ - this.worldVisible = false; - - /** - * [read-only] The display object container that contains this display object. - * - * @property parent - * @type DisplayObjectContainer - * @readOnly - */ - this.parent = null; - - /** - * [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage. - * - * @property stage - * @type Stage - * @readOnly - */ - this.stage = null; - - /** - * [read-only] The index of this object in the parent's `children` array - * - * @property childIndex - * @type Number - * @readOnly - */ - this.childIndex = 0; - - /** - * [read-only] The multiplied alpha of the displayobject - * - * @property worldAlpha - * @type Number - * @readOnly - */ - this.worldAlpha = 1; - - /** - * [read-only] Whether or not the object is interactive, do not toggle directly! use the `interactive` property - * - * @property _interactive - * @type Boolean - * @readOnly - * @private - */ - this._interactive = false; - - /** - * [read-only] Current transform of the object based on world (parent) factors - * - * @property worldTransform - * @type Mat3 - * @readOnly - * @private - */ - this.worldTransform = PIXI.mat3.create()//mat3.identity(); - - /** - * [read-only] Current transform of the object locally - * - * @property localTransform - * @type Mat3 - * @readOnly - * @private - */ - this.localTransform = PIXI.mat3.create()//mat3.identity(); - - /** - * [NYI] Unkown - * - * @property color - * @type Array<> - * @private - */ - this.color = []; - - /** - * [NYI] Holds whether or not this object is dynamic, for rendering optimization - * - * @property dynamic - * @type Boolean - * @private - */ - this.dynamic = true; - - // chach that puppy! - this._sr = 0; - this._cr = 1; - - /* - * MOUSE Callbacks - */ - - /** - * A callback that is used when the users clicks on the displayObject with their mouse - * @method click - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user clicks the mouse down over the sprite - * @method mousedown - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the mouse that was over the displayObject - * for this callback to be fired the mouse must have been pressed down over the displayObject - * @method mouseup - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject - * for this callback to be fired, The touch must have started over the displayObject - * @method mouseupoutside - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the users mouse rolls over the displayObject - * @method mouseover - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the users mouse leaves the displayObject - * @method mouseout - * @param interactionData {InteractionData} - */ - - - /* - * TOUCH Callbacks - */ - - /** - * A callback that is used when the users taps on the sprite with their finger - * basically a touch version of click - * @method tap - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user touch's over the displayObject - * @method touchstart - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases a touch over the displayObject - * @method touchend - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the touch that was over the displayObject - * for this callback to be fired, The touch must have started over the sprite - * @method touchendoutside - * @param interactionData {InteractionData} - */ -} - -// constructor -PIXI.DisplayObject.prototype.constructor = PIXI.DisplayObject; - -//TODO make visible a getter setter -/* -Object.defineProperty(PIXI.DisplayObject.prototype, 'visible', { - get: function() { - return this._visible; - }, - set: function(value) { - this._visible = value; - } -});*/ - -/** - * [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default - * Instead of using this function you can now simply set the interactive property to true or false - * - * @method setInteractive - * @param interactive {Boolean} - * @deprecated Simply set the `interactive` property directly - */ -PIXI.DisplayObject.prototype.setInteractive = function(interactive) -{ - this.interactive = interactive; -} - -/** - * Indicates if the sprite will have touch and mouse interactivity. It is false by default - * - * @property interactive - * @type Boolean - * @default false - */ -Object.defineProperty(PIXI.DisplayObject.prototype, 'interactive', { - get: function() { - return this._interactive; - }, - set: function(value) { - this._interactive = value; - - // TODO more to be done here.. - // need to sort out a re-crawl! - if(this.stage)this.stage.dirty = true; - } -}); - -/** - * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. - * In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. - * To remove a mask, set this property to null. - * - * @property mask - * @type Graphics - */ -Object.defineProperty(PIXI.DisplayObject.prototype, 'mask', { - get: function() { - return this._mask; - }, - set: function(value) { - - this._mask = value; - - if(value) - { - this.addFilter(value) - } - else - { - this.removeFilter(); - } - } -}); - -/* - * Adds a filter to this displayObject - * - * @method addFilter - * @param mask {Graphics} the graphics object to use as a filter - * @private - */ -PIXI.DisplayObject.prototype.addFilter = function(mask) -{ - if(this.filter)return; - this.filter = true; - - - // insert a filter block.. - var start = new PIXI.FilterBlock(); - var end = new PIXI.FilterBlock(); - - - start.mask = mask; - end.mask = mask; - - start.first = start.last = this; - end.first = end.last = this; - - start.open = true; - - /* - * - * insert start - * - */ - - var childFirst = start - var childLast = start - var nextObject; - var previousObject; - - previousObject = this.first._iPrev; - - if(previousObject) - { - nextObject = previousObject._iNext; - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - } - else - { - nextObject = this; - } - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - - // now insert the end filter block.. - - /* - * - * insert end filter - * - */ - var childFirst = end - var childLast = end - var nextObject = null; - var previousObject = null; - - previousObject = this.last; - nextObject = previousObject._iNext; - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - var updateLast = this; - - var prevLast = this.last; - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = end; - } - updateLast = updateLast.parent; - } - - this.first = start; - - // if webGL... - if(this.__renderGroup) - { - this.__renderGroup.addFilterBlocks(start, end); - } - - mask.renderable = false; - -} - -/* - * Removes the filter to this displayObject - * - * @method removeFilter - * @private - */ -PIXI.DisplayObject.prototype.removeFilter = function() -{ - if(!this.filter)return; - this.filter = false; - - // modify the list.. - var startBlock = this.first; - - var nextObject = startBlock._iNext; - var previousObject = startBlock._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - if(previousObject)previousObject._iNext = nextObject; - - this.first = startBlock._iNext; - - - // remove the end filter - var lastBlock = this.last; - - var nextObject = lastBlock._iNext; - var previousObject = lastBlock._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - previousObject._iNext = nextObject; - - // this is always true too! -// if(this.last == lastBlock) - //{ - var tempLast = lastBlock._iPrev; - // need to make sure the parents last is updated too - var updateLast = this; - while(updateLast.last == lastBlock) - { - updateLast.last = tempLast; - updateLast = updateLast.parent; - if(!updateLast)break; - } - - var mask = startBlock.mask - mask.renderable = true; - - // if webGL... - if(this.__renderGroup) - { - this.__renderGroup.removeFilterBlocks(startBlock, lastBlock); - } - //} -} - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.DisplayObject.prototype.updateTransform = function() -{ - // TODO OPTIMIZE THIS!! with dirty - if(this.rotation != this.rotationCache) - { - this.rotationCache = this.rotation; - this._sr = Math.sin(this.rotation); - this._cr = Math.cos(this.rotation); - } - - var localTransform = this.localTransform; - var parentTransform = this.parent.worldTransform; - var worldTransform = this.worldTransform; - //console.log(localTransform) - localTransform[0] = this._cr * this.scale.x; - localTransform[1] = -this._sr * this.scale.y - localTransform[3] = this._sr * this.scale.x; - localTransform[4] = this._cr * this.scale.y; - - // TODO --> do we even need a local matrix??? - - var px = this.pivot.x; - var py = this.pivot.y; - - // Cache the matrix values (makes for huge speed increases!) - var a00 = localTransform[0], a01 = localTransform[1], a02 = this.position.x - localTransform[0] * px - py * localTransform[1], - a10 = localTransform[3], a11 = localTransform[4], a12 = this.position.y - localTransform[4] * py - px * localTransform[3], - - b00 = parentTransform[0], b01 = parentTransform[1], b02 = parentTransform[2], - b10 = parentTransform[3], b11 = parentTransform[4], b12 = parentTransform[5]; - - localTransform[2] = a02 - localTransform[5] = a12 - - worldTransform[0] = b00 * a00 + b01 * a10; - worldTransform[1] = b00 * a01 + b01 * a11; - worldTransform[2] = b00 * a02 + b01 * a12 + b02; - - worldTransform[3] = b10 * a00 + b11 * a10; - worldTransform[4] = b10 * a01 + b11 * a11; - worldTransform[5] = b10 * a02 + b11 * a12 + b12; - - // because we are using affine transformation, we can optimise the matrix concatenation process.. wooo! - // mat3.multiply(this.localTransform, this.parent.worldTransform, this.worldTransform); - this.worldAlpha = this.alpha * this.parent.worldAlpha; - -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * A DisplayObjectContainer represents a collection of display objects. - * It is the base class of all display objects that act as a container for other objects. - * - * @class DisplayObjectContainer - * @extends DisplayObject - * @constructor - */ -PIXI.DisplayObjectContainer = function() -{ - PIXI.DisplayObject.call( this ); - - /** - * [read-only] The of children of this container. - * - * @property children - * @type Array - * @readOnly - */ - this.children = []; -} - -// constructor -PIXI.DisplayObjectContainer.prototype = Object.create( PIXI.DisplayObject.prototype ); -PIXI.DisplayObjectContainer.prototype.constructor = PIXI.DisplayObjectContainer; - -//TODO make visible a getter setter -/* -Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'visible', { - get: function() { - return this._visible; - }, - set: function(value) { - this._visible = value; - - } -});*/ - -/** - * Adds a child to the container. - * - * @method addChild - * @param child {DisplayObject} The DisplayObject to add to the container - */ -PIXI.DisplayObjectContainer.prototype.addChild = function(child) -{ - if(child.parent != undefined) - { - - //// COULD BE THIS??? - child.parent.removeChild(child); - // return; - } - - child.parent = this; - child.childIndex = this.children.length; - - this.children.push(child); - - // updae the stage refference.. - - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = this.stage; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // LINKED LIST // - - // modify the list.. - var childFirst = child.first - var childLast = child.last; - var nextObject; - var previousObject; - - // this could be wrong if there is a filter?? - if(this.filter) - { - previousObject = this.last._iPrev; - } - else - { - previousObject = this.last; - } - - nextObject = previousObject._iNext; - - // always true in this case - //this.last = child.last; - // need to make sure the parents last is updated too - var updateLast = this; - var prevLast = previousObject; - - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = child.last; - } - updateLast = updateLast.parent; - } - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - // need to remove any render groups.. - if(this.__renderGroup) - { - // being used by a renderTexture.. if it exists then it must be from a render texture; - if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child); - // add them to the new render group.. - this.__renderGroup.addDisplayObjectAndChildren(child); - } - -} - -/** - * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown - * - * @method addChildAt - * @param child {DisplayObject} The child to add - * @param index {Number} The index to place the child in - */ -PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index) -{ - if(index >= 0 && index <= this.children.length) - { - if(child.parent != undefined) - { - child.parent.removeChild(child); - } - child.parent = this; - - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = this.stage; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // modify the list.. - var childFirst = child.first - var childLast = child.last; - var nextObject; - var previousObject; - - if(index == this.children.length) - { - previousObject = this.last; - var updateLast = this;//.parent; - var prevLast = this.last; - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = child.last; - } - updateLast = updateLast.parent; - } - } - else if(index == 0) - { - previousObject = this; - } - else - { - previousObject = this.children[index-1].last; - } - - nextObject = previousObject._iNext; - - // always true in this case - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - this.children.splice(index, 0, child); - // need to remove any render groups.. - if(this.__renderGroup) - { - // being used by a renderTexture.. if it exists then it must be from a render texture; - if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child); - // add them to the new render group.. - this.__renderGroup.addDisplayObjectAndChildren(child); - } - - } - else - { - throw new Error(child + " The index "+ index +" supplied is out of bounds " + this.children.length); - } -} - -/** - * [NYI] Swaps the depth of 2 displayObjects - * - * @method swapChildren - * @param child {DisplayObject} - * @param child2 {DisplayObject} - * @private - */ -PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2) -{ - /* - * this funtion needs to be recoded.. - * can be done a lot faster.. - */ - return; - - // need to fix this function :/ - /* - // TODO I already know this?? - var index = this.children.indexOf( child ); - var index2 = this.children.indexOf( child2 ); - - if ( index !== -1 && index2 !== -1 ) - { - // cool - - /* - if(this.stage) - { - // this is to satisfy the webGL batching.. - // TODO sure there is a nicer way to achieve this! - this.stage.__removeChild(child); - this.stage.__removeChild(child2); - - this.stage.__addChild(child); - this.stage.__addChild(child2); - } - - // swap the positions.. - this.children[index] = child2; - this.children[index2] = child; - - } - else - { - throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this); - }*/ -} - -/** - * Returns the Child at the specified index - * - * @method getChildAt - * @param index {Number} The index to get the child from - */ -PIXI.DisplayObjectContainer.prototype.getChildAt = function(index) -{ - if(index >= 0 && index < this.children.length) - { - return this.children[index]; - } - else - { - throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this); - } -} - -/** - * Removes a child from the container. - * - * @method removeChild - * @param child {DisplayObject} The DisplayObject to remove - */ -PIXI.DisplayObjectContainer.prototype.removeChild = function(child) -{ - var index = this.children.indexOf( child ); - if ( index !== -1 ) - { - // unlink // - // modify the list.. - var childFirst = child.first - var childLast = child.last; - - var nextObject = childLast._iNext; - var previousObject = childFirst._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - previousObject._iNext = nextObject; - - if(this.last == childLast) - { - var tempLast = childFirst._iPrev; - // need to make sure the parents last is updated too - var updateLast = this; - while(updateLast.last == childLast.last) - { - updateLast.last = tempLast; - updateLast = updateLast.parent; - if(!updateLast)break; - } - } - - childLast._iNext = null; - childFirst._iPrev = null; - - // update the stage reference.. - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = null; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // webGL trim - if(child.__renderGroup) - { - child.__renderGroup.removeDisplayObjectAndChildren(child); - } - - child.parent = undefined; - this.children.splice( index, 1 ); - } - else - { - throw new Error(child + " The supplied DisplayObject must be a child of the caller " + this); - } -} - -/* - * Updates the container's children's transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.DisplayObjectContainer.prototype.updateTransform = function() -{ - if(!this.visible)return; - - PIXI.DisplayObject.prototype.updateTransform.call( this ); - - for(var i=0,j=this.children.length; i} an array of {Texture} objects that make up the animation - */ -PIXI.MovieClip = function(textures) -{ - PIXI.Sprite.call(this, textures[0]); - - /** - * The array of textures that make up the animation - * - * @property textures - * @type Array - */ - this.textures = textures; - - /** - * The speed that the MovieClip will play at. Higher is faster, lower is slower - * - * @property animationSpeed - * @type Number - * @default 1 - */ - this.animationSpeed = 1; - - /** - * Whether or not the movie clip repeats after playing. - * - * @property loop - * @type Boolean - * @default true - */ - this.loop = true; - - /** - * Function to call when a MovieClip finishes playing - * - * @property onComplete - * @type Function - */ - this.onComplete = null; - - /** - * [read-only] The index MovieClips current frame (this may not have to be a whole number) - * - * @property currentFrame - * @type Number - * @default 0 - * @readOnly - */ - this.currentFrame = 0; - - /** - * [read-only] Indicates if the MovieClip is currently playing - * - * @property playing - * @type Boolean - * @readOnly - */ - this.playing = false; -} - -// constructor -PIXI.MovieClip.prototype = Object.create( PIXI.Sprite.prototype ); -PIXI.MovieClip.prototype.constructor = PIXI.MovieClip; - -/** - * Stops the MovieClip - * - * @method stop - */ -PIXI.MovieClip.prototype.stop = function() -{ - this.playing = false; -} - -/** - * Plays the MovieClip - * - * @method play - */ -PIXI.MovieClip.prototype.play = function() -{ - this.playing = true; -} - -/** - * Stops the MovieClip and goes to a specific frame - * - * @method gotoAndStop - * @param frameNumber {Number} frame index to stop at - */ -PIXI.MovieClip.prototype.gotoAndStop = function(frameNumber) -{ - this.playing = false; - this.currentFrame = frameNumber; - var round = (this.currentFrame + 0.5) | 0; - this.setTexture(this.textures[round % this.textures.length]); -} - -/** - * Goes to a specific frame and begins playing the MovieClip - * - * @method gotoAndPlay - * @param frameNumber {Number} frame index to start at - */ -PIXI.MovieClip.prototype.gotoAndPlay = function(frameNumber) -{ - this.currentFrame = frameNumber; - this.playing = true; -} - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.MovieClip.prototype.updateTransform = function() -{ - PIXI.Sprite.prototype.updateTransform.call(this); - - if(!this.playing)return; - - this.currentFrame += this.animationSpeed; - var round = (this.currentFrame + 0.5) | 0; - if(this.loop || round < this.textures.length) - { - this.setTexture(this.textures[round % this.textures.length]); - } - else if(round >= this.textures.length) - { - this.gotoAndStop(this.textures.length - 1); - if(this.onComplete) - { - this.onComplete(); - } - } -} -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - - -PIXI.FilterBlock = function(mask) -{ - this.graphics = mask - this.visible = true; - this.renderable = true; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Text Object will create a line(s) of text to split a line you can use "\n" - * - * @class Text - * @extends Sprite - * @constructor - * @param text {String} The copy that you would like the text to display - * @param [style] {Object} The style parameters - * @param [style.font] {String} default "bold 20pt Arial" The style and size of the font - * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00" - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - * @param [style.stroke] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00" - * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke) - * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used - * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap - */ -PIXI.Text = function(text, style) -{ - this.canvas = document.createElement("canvas"); - this.context = this.canvas.getContext("2d"); - PIXI.Sprite.call(this, PIXI.Texture.fromCanvas(this.canvas)); - - this.setText(text); - this.setStyle(style); - - this.updateText(); - this.dirty = false; -}; - -// constructor -PIXI.Text.prototype = Object.create(PIXI.Sprite.prototype); -PIXI.Text.prototype.constructor = PIXI.Text; - -/** - * Set the style of the text - * - * @method setStyle - * @param [style] {Object} The style parameters - * @param [style.font="bold 20pt Arial"] {String} The style and size of the font - * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00" - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - * @param [style.stroke="black"] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00" - * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke) - * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used - * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap - */ -PIXI.Text.prototype.setStyle = function(style) -{ - style = style || {}; - style.font = style.font || "bold 20pt Arial"; - style.fill = style.fill || "black"; - style.align = style.align || "left"; - style.stroke = style.stroke || "black"; //provide a default, see: https://github.com/GoodBoyDigital/pixi.js/issues/136 - style.strokeThickness = style.strokeThickness || 0; - style.wordWrap = style.wordWrap || false; - style.wordWrapWidth = style.wordWrapWidth || 100; - this.style = style; - this.dirty = true; -}; - -/** - * Set the copy for the text object. To split a line you can use "\n" - * - * @methos setText - * @param {String} text The copy that you would like the text to display - */ -PIXI.Sprite.prototype.setText = function(text) -{ - this.text = text.toString() || " "; - this.dirty = true; -}; - -/** - * Renders text - * - * @method updateText - * @private - */ -PIXI.Text.prototype.updateText = function() -{ - this.context.font = this.style.font; - - var outputText = this.text; - - // word wrap - // preserve original text - if(this.style.wordWrap)outputText = this.wordWrap(this.text); - - //split text into lines - var lines = outputText.split(/(?:\r\n|\r|\n)/); - - //calculate text width - var lineWidths = []; - var maxLineWidth = 0; - for (var i = 0; i < lines.length; i++) - { - var lineWidth = this.context.measureText(lines[i]).width; - lineWidths[i] = lineWidth; - maxLineWidth = Math.max(maxLineWidth, lineWidth); - } - this.canvas.width = maxLineWidth + this.style.strokeThickness; - - //calculate text height - var lineHeight = this.determineFontHeight("font: " + this.style.font + ";") + this.style.strokeThickness; - this.canvas.height = lineHeight * lines.length; - - //set canvas text styles - this.context.fillStyle = this.style.fill; - this.context.font = this.style.font; - - this.context.strokeStyle = this.style.stroke; - this.context.lineWidth = this.style.strokeThickness; - - this.context.textBaseline = "top"; - - //draw lines line by line - for (i = 0; i < lines.length; i++) - { - var linePosition = new PIXI.Point(this.style.strokeThickness / 2, this.style.strokeThickness / 2 + i * lineHeight); - - if(this.style.align == "right") - { - linePosition.x += maxLineWidth - lineWidths[i]; - } - else if(this.style.align == "center") - { - linePosition.x += (maxLineWidth - lineWidths[i]) / 2; - } - - if(this.style.stroke && this.style.strokeThickness) - { - this.context.strokeText(lines[i], linePosition.x, linePosition.y); - } - - if(this.style.fill) - { - this.context.fillText(lines[i], linePosition.x, linePosition.y); - } - } - - this.updateTexture(); -}; - -/** - * Updates texture size based on canvas size - * - * @method updateTexture - * @private - */ -PIXI.Text.prototype.updateTexture = function() -{ - this.texture.baseTexture.width = this.canvas.width; - this.texture.baseTexture.height = this.canvas.height; - this.texture.frame.width = this.canvas.width; - this.texture.frame.height = this.canvas.height; - - this._width = this.canvas.width; - this._height = this.canvas.height; - - PIXI.texturesToUpdate.push(this.texture.baseTexture); -}; - -/** - * Updates the transfor of this object - * - * @method updateTransform - * @private - */ -PIXI.Text.prototype.updateTransform = function() -{ - if(this.dirty) - { - this.updateText(); - this.dirty = false; - } - - PIXI.Sprite.prototype.updateTransform.call(this); -}; - -/* - * http://stackoverflow.com/users/34441/ellisbben - * great solution to the problem! - * - * @method determineFontHeight - * @param fontStyle {Object} - * @private - */ -PIXI.Text.prototype.determineFontHeight = function(fontStyle) -{ - // build a little reference dictionary so if the font style has been used return a - // cached version... - var result = PIXI.Text.heightCache[fontStyle]; - - if(!result) - { - var body = document.getElementsByTagName("body")[0]; - var dummy = document.createElement("div"); - var dummyText = document.createTextNode("M"); - dummy.appendChild(dummyText); - dummy.setAttribute("style", fontStyle + ';position:absolute;top:0;left:0'); - body.appendChild(dummy); - - result = dummy.offsetHeight; - PIXI.Text.heightCache[fontStyle] = result; - - body.removeChild(dummy); - } - - return result; -}; - -/** - * A Text Object will apply wordwrap - * - * @method wordWrap - * @param text {String} - * @private - */ -PIXI.Text.prototype.wordWrap = function(text) -{ - // search good wrap position - var searchWrapPos = function(ctx, text, start, end, wrapWidth) - { - var p = Math.floor((end-start) / 2) + start; - if(p == start) { - return 1; - } - - if(ctx.measureText(text.substring(0,p)).width <= wrapWidth) - { - if(ctx.measureText(text.substring(0,p+1)).width > wrapWidth) - { - return p; - } - else - { - return arguments.callee(ctx, text, p, end, wrapWidth); - } - } - else - { - return arguments.callee(ctx, text, start, p, wrapWidth); - } - }; - - var lineWrap = function(ctx, text, wrapWidth) - { - if(ctx.measureText(text).width <= wrapWidth || text.length < 1) - { - return text; - } - var pos = searchWrapPos(ctx, text, 0, text.length, wrapWidth); - return text.substring(0, pos) + "\n" + arguments.callee(ctx, text.substring(pos), wrapWidth); - }; - - var result = ""; - var lines = text.split("\n"); - for (var i = 0; i < lines.length; i++) - { - result += lineWrap(this.context, lines[i], this.style.wordWrapWidth) + "\n"; - } - - return result; -}; - -/** - * Destroys this text object - * - * @method destroy - * @param destroyTexture {Boolean} - */ -PIXI.Text.prototype.destroy = function(destroyTexture) -{ - if(destroyTexture) - { - this.texture.destroy(); - } - -}; - -PIXI.Text.heightCache = {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Text Object will create a line(s) of text using bitmap font. To split a line you can use "\n", "\r" or "\r\n" - * You can generate the fnt files using - * http://www.angelcode.com/products/bmfont/ for windows or - * http://www.bmglyph.com/ for mac. - * - * @class BitmapText - * @extends DisplayObjectContainer - * @constructor - * @param text {String} The copy that you would like the text to display - * @param style {Object} The style parameters - * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously) - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - */ -PIXI.BitmapText = function(text, style) -{ - PIXI.DisplayObjectContainer.call(this); - - this.setText(text); - this.setStyle(style); - this.updateText(); - this.dirty = false - -}; - -// constructor -PIXI.BitmapText.prototype = Object.create(PIXI.DisplayObjectContainer.prototype); -PIXI.BitmapText.prototype.constructor = PIXI.BitmapText; - -/** - * Set the copy for the text object - * - * @method setText - * @param text {String} The copy that you would like the text to display - */ -PIXI.BitmapText.prototype.setText = function(text) -{ - this.text = text || " "; - this.dirty = true; -}; - -/** - * Set the style of the text - * - * @method setStyle - * @param style {Object} The style parameters - * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously) - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - */ -PIXI.BitmapText.prototype.setStyle = function(style) -{ - style = style || {}; - style.align = style.align || "left"; - this.style = style; - - var font = style.font.split(" "); - this.fontName = font[font.length - 1]; - this.fontSize = font.length >= 2 ? parseInt(font[font.length - 2], 10) : PIXI.BitmapText.fonts[this.fontName].size; - - this.dirty = true; -}; - -/** - * Renders text - * - * @method updateText - * @private - */ -PIXI.BitmapText.prototype.updateText = function() -{ - var data = PIXI.BitmapText.fonts[this.fontName]; - var pos = new PIXI.Point(); - var prevCharCode = null; - var chars = []; - var maxLineWidth = 0; - var lineWidths = []; - var line = 0; - var scale = this.fontSize / data.size; - for(var i = 0; i < this.text.length; i++) - { - var charCode = this.text.charCodeAt(i); - if(/(?:\r\n|\r|\n)/.test(this.text.charAt(i))) - { - lineWidths.push(pos.x); - maxLineWidth = Math.max(maxLineWidth, pos.x); - line++; - - pos.x = 0; - pos.y += data.lineHeight; - prevCharCode = null; - continue; - } - - var charData = data.chars[charCode]; - if(!charData) continue; - - if(prevCharCode && charData[prevCharCode]) - { - pos.x += charData.kerning[prevCharCode]; - } - chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); - pos.x += charData.xAdvance; - - prevCharCode = charCode; - } - - lineWidths.push(pos.x); - maxLineWidth = Math.max(maxLineWidth, pos.x); - - var lineAlignOffsets = []; - for(i = 0; i <= line; i++) - { - var alignOffset = 0; - if(this.style.align == "right") - { - alignOffset = maxLineWidth - lineWidths[i]; - } - else if(this.style.align == "center") - { - alignOffset = (maxLineWidth - lineWidths[i]) / 2; - } - lineAlignOffsets.push(alignOffset); - } - - for(i = 0; i < chars.length; i++) - { - var c = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode); - c.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; - c.position.y = chars[i].position.y * scale; - c.scale.x = c.scale.y = scale; - this.addChild(c); - } - - this.width = pos.x * scale; - this.height = (pos.y + data.lineHeight) * scale; -}; - -/** - * Updates the transfor of this object - * - * @method updateTransform - * @private - */ -PIXI.BitmapText.prototype.updateTransform = function() -{ - if(this.dirty) - { - while(this.children.length > 0) - { - this.removeChild(this.getChildAt(0)); - } - this.updateText(); - - this.dirty = false; - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call(this); -}; - -PIXI.BitmapText.fonts = {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - - -/** - * The interaction manager deals with mouse and touch events. Any DisplayObject can be interactive - * This manager also supports multitouch. - * - * @class InteractionManager - * @constructor - * @param stage {Stage} The stage to handle interactions - */ -PIXI.InteractionManager = function(stage) -{ - /** - * a refference to the stage - * - * @property stage - * @type Stage - */ - this.stage = stage; - - /** - * the mouse data - * - * @property mouse - * @type InteractionData - */ - this.mouse = new PIXI.InteractionData(); - - /** - * an object that stores current touches (InteractionData) by id reference - * - * @property touchs - * @type Object - */ - this.touchs = {}; - - // helpers - this.tempPoint = new PIXI.Point(); - //this.tempMatrix = mat3.create(); - - this.mouseoverEnabled = true; - - //tiny little interactiveData pool! - this.pool = []; - - this.interactiveItems = []; - - this.last = 0; -} - -// constructor -PIXI.InteractionManager.prototype.constructor = PIXI.InteractionManager; - -/** - * Collects an interactive sprite recursively to have their interactions managed - * - * @method collectInteractiveSprite - * @param displayObject {DisplayObject} the displayObject to collect - * @param iParent {DisplayObject} - * @private - */ -PIXI.InteractionManager.prototype.collectInteractiveSprite = function(displayObject, iParent) -{ - var children = displayObject.children; - var length = children.length; - - /// make an interaction tree... {item.__interactiveParent} - for (var i = length-1; i >= 0; i--) - { - var child = children[i]; - - if(child.visible) { - // push all interactive bits - if(child.interactive) - { - iParent.interactiveChildren = true; - //child.__iParent = iParent; - this.interactiveItems.push(child); - - if(child.children.length > 0) - { - this.collectInteractiveSprite(child, child); - } - } - else - { - child.__iParent = null; - - if(child.children.length > 0) - { - this.collectInteractiveSprite(child, iParent); - } - } - } - } -} - -/** - * Sets the target for event delegation - * - * @method setTarget - * @param target {WebGLRenderer|CanvasRenderer} the renderer to bind events to - * @private - */ -PIXI.InteractionManager.prototype.setTarget = function(target) -{ - if (window.navigator.msPointerEnabled) - { - // time to remove some of that zoom in ja.. - target.view.style["-ms-content-zooming"] = "none"; - target.view.style["-ms-touch-action"] = "none" - - // DO some window specific touch! - } - - this.target = target; - target.view.addEventListener('mousemove', this.onMouseMove.bind(this), true); - target.view.addEventListener('mousedown', this.onMouseDown.bind(this), true); - document.body.addEventListener('mouseup', this.onMouseUp.bind(this), true); - target.view.addEventListener('mouseout', this.onMouseUp.bind(this), true); - - // aint no multi touch just yet! - target.view.addEventListener("touchstart", this.onTouchStart.bind(this), true); - target.view.addEventListener("touchend", this.onTouchEnd.bind(this), true); - target.view.addEventListener("touchmove", this.onTouchMove.bind(this), true); -} - -/** - * updates the state of interactive objects - * - * @method update - * @private - */ -PIXI.InteractionManager.prototype.update = function() -{ - if(!this.target)return; - - // frequency of 30fps?? - var now = Date.now(); - var diff = now - this.last; - diff = (diff * 30) / 1000; - if(diff < 1)return; - this.last = now; - // - - // ok.. so mouse events?? - // yes for now :) - // OPTIMSE - how often to check?? - if(this.dirty) - { - this.dirty = false; - - var len = this.interactiveItems.length; - - for (var i=0; i < len; i++) { - this.interactiveItems[i].interactiveChildren = false; - } - - this.interactiveItems = []; - - if(this.stage.interactive)this.interactiveItems.push(this.stage); - // go through and collect all the objects that are interactive.. - this.collectInteractiveSprite(this.stage, this.stage); - } - - // loop through interactive objects! - var length = this.interactiveItems.length; - - this.target.view.style.cursor = "default"; - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - if(!item.visible)continue; - - // OPTIMISATION - only calculate every time if the mousemove function exists.. - // OK so.. does the object have any other interactive functions? - // hit-test the clip! - - - if(item.mouseover || item.mouseout || item.buttonMode) - { - // ok so there are some functions so lets hit test it.. - item.__hit = this.hitTest(item, this.mouse); - this.mouse.target = item; - // ok so deal with interactions.. - // loks like there was a hit! - if(item.__hit) - { - if(item.buttonMode)this.target.view.style.cursor = "pointer"; - - if(!item.__isOver) - { - - if(item.mouseover)item.mouseover(this.mouse); - item.__isOver = true; - } - } - else - { - if(item.__isOver) - { - // roll out! - if(item.mouseout)item.mouseout(this.mouse); - item.__isOver = false; - } - } - } - - // ---> - } -} - -/** - * Is called when the mouse moves accross the renderer element - * - * @method onMouseMove - * @param event {Event} The DOM event of the mouse moving - * @private - */ -PIXI.InteractionManager.prototype.onMouseMove = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - // TODO optimize by not check EVERY TIME! maybe half as often? // - var rect = this.target.view.getBoundingClientRect(); - - this.mouse.global.x = (event.clientX - rect.left) * (this.target.width / rect.width); - this.mouse.global.y = (event.clientY - rect.top) * ( this.target.height / rect.height); - - var length = this.interactiveItems.length; - var global = this.mouse.global; - - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mousemove) - { - //call the function! - item.mousemove(this.mouse); - } - } -} - -/** - * Is called when the mouse button is pressed down on the renderer element - * - * @method onMouseDown - * @param event {Event} The DOM event of a mouse button being pressed down - * @private - */ -PIXI.InteractionManager.prototype.onMouseDown = function(event) -{ - event.preventDefault(); - this.mouse.originalEvent = event || window.event; //IE uses window.event - - // loop through inteaction tree... - // hit test each item! -> - // get interactive items under point?? - //stage.__i - var length = this.interactiveItems.length; - var global = this.mouse.global; - - var index = 0; - var parent = this.stage; - - // while - // hit test - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mousedown || item.click) - { - item.__mouseIsDown = true; - item.__hit = this.hitTest(item, this.mouse); - - if(item.__hit) - { - //call the function! - if(item.mousedown)item.mousedown(this.mouse); - item.__isDown = true; - - // just the one! - if(!item.interactiveChildren)break; - } - } - } -} - -/** - * Is called when the mouse button is released on the renderer element - * - * @method onMouseUp - * @param event {Event} The DOM event of a mouse button being released - * @private - */ -PIXI.InteractionManager.prototype.onMouseUp = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - - var global = this.mouse.global; - - - var length = this.interactiveItems.length; - var up = false; - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mouseup || item.mouseupoutside || item.click) - { - item.__hit = this.hitTest(item, this.mouse); - - if(item.__hit && !up) - { - //call the function! - if(item.mouseup) - { - item.mouseup(this.mouse); - } - if(item.__isDown) - { - if(item.click)item.click(this.mouse); - } - - if(!item.interactiveChildren)up = true; - } - else - { - if(item.__isDown) - { - if(item.mouseupoutside)item.mouseupoutside(this.mouse); - } - } - - item.__isDown = false; - } - } -} - -/** - * Tests if the current mouse coords hit a sprite - * - * @method hitTest - * @param item {DisplayObject} The displayObject to test for a hit - * @param interactionData {InteractionData} The interactiondata object to update in the case of a hit - * @private - */ -PIXI.InteractionManager.prototype.hitTest = function(item, interactionData) -{ - var global = interactionData.global; - - if(!item.visible)return false; - - var isSprite = (item instanceof PIXI.Sprite), - worldTransform = item.worldTransform, - a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2], - a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5], - id = 1 / (a00 * a11 + a01 * -a10), - x = a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id, - y = a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id; - - interactionData.target = item; - - //a sprite or display object with a hit area defined - if(item.hitArea && item.hitArea.contains) { - if(item.hitArea.contains(x, y)) { - //if(isSprite) - interactionData.target = item; - - return true; - } - - return false; - } - // a sprite with no hitarea defined - else if(isSprite) - { - var width = item.texture.frame.width, - height = item.texture.frame.height, - x1 = -width * item.anchor.x, - y1; - - if(x > x1 && x < x1 + width) - { - y1 = -height * item.anchor.y; - - if(y > y1 && y < y1 + height) - { - // set the target property if a hit is true! - interactionData.target = item - return true; - } - } - } - - var length = item.children.length; - - for (var i = 0; i < length; i++) - { - var tempItem = item.children[i]; - var hit = this.hitTest(tempItem, interactionData); - if(hit) - { - // hmm.. TODO SET CORRECT TARGET? - interactionData.target = item - return true; - } - } - - return false; -} - -/** - * Is called when a touch is moved accross the renderer element - * - * @method onTouchMove - * @param event {Event} The DOM event of a touch moving accross the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchMove = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - var rect = this.target.view.getBoundingClientRect(); - var changedTouches = event.changedTouches; - - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - var touchData = this.touchs[touchEvent.identifier]; - - // update the touch position - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - } - - var length = this.interactiveItems.length; - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - if(item.touchmove)item.touchmove(touchData); - } -} - -/** - * Is called when a touch is started on the renderer element - * - * @method onTouchStart - * @param event {Event} The DOM event of a touch starting on the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchStart = function(event) -{ - event.preventDefault(); - this.mouse.originalEvent = event || window.event; //IE uses window.event - - var rect = this.target.view.getBoundingClientRect(); - - var changedTouches = event.changedTouches; - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - - var touchData = this.pool.pop(); - if(!touchData)touchData = new PIXI.InteractionData(); - - this.touchs[touchEvent.identifier] = touchData; - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - - var length = this.interactiveItems.length; - - for (var j = 0; j < length; j++) - { - var item = this.interactiveItems[j]; - - if(item.touchstart || item.tap) - { - item.__hit = this.hitTest(item, touchData); - - if(item.__hit) - { - //call the function! - if(item.touchstart)item.touchstart(touchData); - item.__isDown = true; - item.__touchData = touchData; - - if(!item.interactiveChildren)break; - } - } - } - } -} - -/** - * Is called when a touch is ended on the renderer element - * - * @method onTouchEnd - * @param event {Event} The DOM event of a touch ending on the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchEnd = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - var rect = this.target.view.getBoundingClientRect(); - var changedTouches = event.changedTouches; - - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - var touchData = this.touchs[touchEvent.identifier]; - var up = false; - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - - var length = this.interactiveItems.length; - for (var j = 0; j < length; j++) - { - var item = this.interactiveItems[j]; - var itemTouchData = item.__touchData; // <-- Here! - item.__hit = this.hitTest(item, touchData); - - if(itemTouchData == touchData) - { - // so this one WAS down... - - // hitTest?? - - if(item.touchend || item.tap) - { - if(item.__hit && !up) - { - if(item.touchend)item.touchend(touchData); - if(item.__isDown) - { - if(item.tap)item.tap(touchData); - } - - if(!item.interactiveChildren)up = true; - } - else - { - if(item.__isDown) - { - if(item.touchendoutside)item.touchendoutside(touchData); - } - } - - item.__isDown = false; - } - - item.__touchData = null; - - } - else - { - - } - } - // remove the touch.. - this.pool.push(touchData); - this.touchs[touchEvent.identifier] = null; - } -} - -/** - * Holds all information related to an Interaction event - * - * @class InteractionData - * @constructor - */ -PIXI.InteractionData = function() -{ - /** - * This point stores the global coords of where the touch/mouse event happened - * - * @property global - * @type Point - */ - this.global = new PIXI.Point(); - - // this is here for legacy... but will remove - this.local = new PIXI.Point(); - - /** - * The target Sprite that was interacted with - * - * @property target - * @type Sprite - */ - this.target; - - /** - * When passed to an event handler, this will be the original DOM Event that was captured - * - * @property originalEvent - * @type Event - */ - this.originalEvent; -} - -/** - * This will return the local coords of the specified displayObject for this InteractionData - * - * @method getLocalPosition - * @param displayObject {DisplayObject} The DisplayObject that you would like the local coords off - * @return {Point} A point containing the coords of the InteractionData position relative to the DisplayObject - */ -PIXI.InteractionData.prototype.getLocalPosition = function(displayObject) -{ - var worldTransform = displayObject.worldTransform; - var global = this.global; - - // do a cheeky transform to get the mouse coords; - var a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2], - a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5], - id = 1 / (a00 * a11 + a01 * -a10); - // set the mouse coords... - return new PIXI.Point(a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id, - a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id) -} - -// constructor -PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Stage represents the root of the display tree. Everything connected to the stage is rendered - * - * @class Stage - * @extends DisplayObjectContainer - * @constructor - * @param backgroundColor {Number} the background color of the stage, easiest way to pass this in is in hex format - * like: 0xFFFFFF for white - * @param interactive {Boolean} enable / disable interaction (default is false) - */ -PIXI.Stage = function(backgroundColor, interactive) -{ - PIXI.DisplayObjectContainer.call( this ); - - /** - * [read-only] Current transform of the object based on world (parent) factors - * - * @property worldTransform - * @type Mat3 - * @readOnly - * @private - */ - this.worldTransform = PIXI.mat3.create(); - - /** - * Whether or not the stage is interactive - * - * @property interactive - * @type Boolean - */ - this.interactive = interactive; - - /** - * The interaction manage for this stage, manages all interactive activity on the stage - * - * @property interactive - * @type InteractionManager - */ - this.interactionManager = new PIXI.InteractionManager(this); - - /** - * Whether the stage is dirty and needs to have interactions updated - * - * @property dirty - * @type Boolean - * @private - */ - this.dirty = true; - - this.__childrenAdded = []; - this.__childrenRemoved = []; - - //the stage is it's own stage - this.stage = this; - - //optimize hit detection a bit - this.stage.hitArea = new PIXI.Rectangle(0,0,100000, 100000); - - this.setBackgroundColor(backgroundColor); - this.worldVisible = true; -} - -// constructor -PIXI.Stage.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Stage.prototype.constructor = PIXI.Stage; - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.Stage.prototype.updateTransform = function() -{ - this.worldAlpha = 1; - - for(var i=0,j=this.children.length; i> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; -} - -/** - * A polyfill for Function.prototype.bind - * - * @method bind - */ -if (typeof Function.prototype.bind != 'function') { - Function.prototype.bind = (function () { - var slice = Array.prototype.slice; - return function (thisArg) { - var target = this, boundArgs = slice.call(arguments, 1); - - if (typeof target != 'function') throw new TypeError(); - - function bound() { - var args = boundArgs.concat(slice.call(arguments)); - target.apply(this instanceof bound ? this : thisArg, args); - } - - bound.prototype = (function F(proto) { - proto && (F.prototype = proto); - if (!(this instanceof F)) return new F; - })(target.prototype); - - return bound; - }; - })(); -} - -/** - * A wrapper for ajax requests to be handled cross browser - * - * @class AjaxRequest - * @constructor - */ -var AjaxRequest = PIXI.AjaxRequest = function() -{ - var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE - - if (window.ActiveXObject) - { //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken) - for (var i=0; i>>>>>>>>") - console.log("_") - var safe = 0; - var tmp = item.first; - console.log(tmp); - - while(tmp._iNext) - { - safe++; -// console.log(tmp.childIndex + tmp); - tmp = tmp._iNext; - console.log(tmp);//.childIndex); - // console.log(tmp); - - if(safe > 100) - { - console.log("BREAK") - break - } - } -} - - - - - - -/** - * https://github.com/mrdoob/eventtarget.js/ - * THankS mr DOob! - */ - -/** - * Adds event emitter functionality to a class - * - * @class EventTarget - * @example - * function MyEmitter() { - * PIXI.EventTarget.call(this); //mixes in event target stuff - * } - * - * var em = new MyEmitter(); - * em.emit({ type: 'eventName', data: 'some data' }); - */ -PIXI.EventTarget = function () { - - var listeners = {}; - - this.addEventListener = this.on = function ( type, listener ) { - - - if ( listeners[ type ] === undefined ) { - - listeners[ type ] = []; - - } - - if ( listeners[ type ].indexOf( listener ) === - 1 ) { - - listeners[ type ].push( listener ); - } - - }; - - this.dispatchEvent = this.emit = function ( event ) { - - for ( var listener in listeners[ event.type ] ) { - - listeners[ event.type ][ listener ]( event ); - - } - - }; - - this.removeEventListener = this.off = function ( type, listener ) { - - var index = listeners[ type ].indexOf( listener ); - - if ( index !== - 1 ) { - - listeners[ type ].splice( index, 1 ); - - } - - }; - -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * This helper function will automatically detect which renderer you should be using. - * WebGL is the preferred renderer as it is a lot fastest. If webGL is not supported by - * the browser then this function will return a canvas renderer - * - * @method autoDetectRenderer - * @static - * @param width {Number} the width of the renderers view - * @param height {Number} the height of the renderers view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - */ -PIXI.autoDetectRenderer = function(width, height, view, transparent) -{ - if(!width)width = 800; - if(!height)height = 600; - - // BORROWED from Mr Doob (mrdoob.com) - var webgl = ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )(); - - //console.log(webgl); - if( webgl ) - { - return new PIXI.WebGLRenderer(width, height, view, transparent); - } - - return new PIXI.CanvasRenderer(width, height, view, transparent); -}; - - - -/* - PolyK library - url: http://polyk.ivank.net - Released under MIT licence. - - Copyright (c) 2012 Ivan Kuckir - - 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. - - This is an amazing lib! - - slightly modified by mat groves (matgroves.com); -*/ - -PIXI.PolyK = {}; - -/** - * Triangulates shapes for webGL graphic fills - * - * @method Triangulate - * @namespace PolyK - * @constructor - */ -PIXI.PolyK.Triangulate = function(p) -{ - var sign = true; - - var n = p.length>>1; - if(n<3) return []; - var tgs = []; - var avl = []; - for(var i=0; i 3) - { - var i0 = avl[(i+0)%al]; - var i1 = avl[(i+1)%al]; - var i2 = avl[(i+2)%al]; - - var ax = p[2*i0], ay = p[2*i0+1]; - var bx = p[2*i1], by = p[2*i1+1]; - var cx = p[2*i2], cy = p[2*i2+1]; - - var earFound = false; - if(PIXI.PolyK._convex(ax, ay, bx, by, cx, cy, sign)) - { - earFound = true; - for(var j=0; j 3*al) - { - // need to flip flip reverse it! - // reset! - if(sign) - { - var tgs = []; - avl = []; - for(var i=0; i= 0) && (v >= 0) && (u + v < 1); -} - -/** - * Checks if a shape is convex - * - * @class _convex - * @namespace PolyK - * @private - */ -PIXI.PolyK._convex = function(ax, ay, bx, by, cx, cy, sign) -{ - return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) == sign; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/* - * the default suoer fast shader! - */ - -PIXI.shaderFragmentSrc = [ - "precision mediump float;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "uniform sampler2D uSampler;", - "void main(void) {", - "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));", - "gl_FragColor = gl_FragColor * vColor;", - "}" -]; - -PIXI.shaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec2 aTextureCoord;", - "attribute float aColor;", - //"uniform mat4 uMVMatrix;", - - "uniform vec2 projectionVector;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "void main(void) {", - // "gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0, 1.0);", - "gl_Position = vec4( aVertexPosition.x / projectionVector.x -1.0, aVertexPosition.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vTextureCoord = aTextureCoord;", - "vColor = aColor;", - "}" -]; - -/* - * the triangle strip shader.. - */ - -PIXI.stripShaderFragmentSrc = [ - "precision mediump float;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "uniform float alpha;", - "uniform sampler2D uSampler;", - "void main(void) {", - "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));", - "gl_FragColor = gl_FragColor * alpha;", - "}" -]; - - -PIXI.stripShaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec2 aTextureCoord;", - "attribute float aColor;", - "uniform mat3 translationMatrix;", - "uniform vec2 projectionVector;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "void main(void) {", - "vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);", - "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vTextureCoord = aTextureCoord;", - "vColor = aColor;", - "}" -]; - - -/* - * primitive shader.. - */ - -PIXI.primitiveShaderFragmentSrc = [ - "precision mediump float;", - "varying vec4 vColor;", - "void main(void) {", - "gl_FragColor = vColor;", - "}" -]; - -PIXI.primitiveShaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec4 aColor;", - "uniform mat3 translationMatrix;", - "uniform vec2 projectionVector;", - "uniform float alpha;", - "varying vec4 vColor;", - "void main(void) {", - "vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);", - "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vColor = aColor * alpha;", - "}" -]; - -PIXI.initPrimitiveShader = function() -{ - var gl = PIXI.gl; - - var shaderProgram = PIXI.compileProgram(PIXI.primitiveShaderVertexSrc, PIXI.primitiveShaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, "translationMatrix"); - - shaderProgram.alpha = gl.getUniformLocation(shaderProgram, "alpha"); - - PIXI.primitiveProgram = shaderProgram; -} - -PIXI.initDefaultShader = function() -{ - var gl = this.gl; - var shaderProgram = PIXI.compileProgram(PIXI.shaderVertexSrc, PIXI.shaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord"); - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - // shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix"); - shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler"); - - PIXI.shaderProgram = shaderProgram; -} - -PIXI.initDefaultStripShader = function() -{ - var gl = this.gl; - var shaderProgram = PIXI.compileProgram(PIXI.stripShaderVertexSrc, PIXI.stripShaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord"); - shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, "translationMatrix"); - shaderProgram.alpha = gl.getUniformLocation(shaderProgram, "alpha"); - - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - - shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler"); - - PIXI.stripShaderProgram = shaderProgram; -} - -PIXI.CompileVertexShader = function(gl, shaderSrc) -{ - return PIXI._CompileShader(gl, shaderSrc, gl.VERTEX_SHADER); -} - -PIXI.CompileFragmentShader = function(gl, shaderSrc) -{ - return PIXI._CompileShader(gl, shaderSrc, gl.FRAGMENT_SHADER); -} - -PIXI._CompileShader = function(gl, shaderSrc, shaderType) -{ - var src = shaderSrc.join("\n"); - var shader = gl.createShader(shaderType); - gl.shaderSource(shader, src); - gl.compileShader(shader); - - if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { - alert(gl.getShaderInfoLog(shader)); - return null; - } - - return shader; -} - - -PIXI.compileProgram = function(vertexSrc, fragmentSrc) -{ - var gl = PIXI.gl; - var fragmentShader = PIXI.CompileFragmentShader(gl, fragmentSrc); - var vertexShader = PIXI.CompileVertexShader(gl, vertexSrc); - - var shaderProgram = gl.createProgram(); - - gl.attachShader(shaderProgram, vertexShader); - gl.attachShader(shaderProgram, fragmentShader); - gl.linkProgram(shaderProgram); - - if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) { - alert("Could not initialise shaders"); - } - - return shaderProgram; -} - - -PIXI.activateDefaultShader = function() -{ - var gl = PIXI.gl; - var shaderProgram = PIXI.shaderProgram; - - gl.useProgram(shaderProgram); - - - gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute); - gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute); - gl.enableVertexAttribArray(shaderProgram.colorAttribute); -} - - - -PIXI.activatePrimitiveShader = function() -{ - var gl = PIXI.gl; - - gl.disableVertexAttribArray(PIXI.shaderProgram.textureCoordAttribute); - gl.disableVertexAttribArray(PIXI.shaderProgram.colorAttribute); - - gl.useProgram(PIXI.primitiveProgram); - - gl.enableVertexAttribArray(PIXI.primitiveProgram.vertexPositionAttribute); - gl.enableVertexAttribArray(PIXI.primitiveProgram.colorAttribute); -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A set of functions used by the webGL renderer to draw the primitive graphics data - * - * @class CanvasGraphics - */ -PIXI.WebGLGraphics = function() -{ - -} - -/** - * Renders the graphics object - * - * @static - * @private - * @method renderGraphics - * @param graphics {Graphics} - * @param projection {Object} - */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) -{ - var gl = PIXI.gl; - - if(!graphics._webGL)graphics._webGL = {points:[], indices:[], lastIndex:0, - buffer:gl.createBuffer(), - indexBuffer:gl.createBuffer()}; - - if(graphics.dirty) - { - graphics.dirty = false; - - if(graphics.clearDirty) - { - graphics.clearDirty = false; - - graphics._webGL.lastIndex = 0; - graphics._webGL.points = []; - graphics._webGL.indices = []; - - } - - PIXI.WebGLGraphics.updateGraphics(graphics); - } - - - PIXI.activatePrimitiveShader(); - - // This could be speeded up fo sure! - var m = PIXI.mat3.clone(graphics.worldTransform); - - PIXI.mat3.transpose(m); - - // set the matrix transform for the - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - - gl.uniformMatrix3fv(PIXI.primitiveProgram.translationMatrix, false, m); - - gl.uniform2f(PIXI.primitiveProgram.projectionVector, projection.x, projection.y); - - gl.uniform1f(PIXI.primitiveProgram.alpha, graphics.worldAlpha); - - gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer); - - // WHY DOES THIS LINE NEED TO BE THERE??? - gl.vertexAttribPointer(PIXI.shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - // its not even used.. but need to be set or it breaks? - // only on pc though.. - - gl.vertexAttribPointer(PIXI.primitiveProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 4 * 6, 0); - gl.vertexAttribPointer(PIXI.primitiveProgram.colorAttribute, 4, gl.FLOAT, false,4 * 6, 2 * 4); - - // set the index buffer! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer); - - gl.drawElements(gl.TRIANGLE_STRIP, graphics._webGL.indices.length, gl.UNSIGNED_SHORT, 0 ); - - // return to default shader... - PIXI.activateDefaultShader(); -} - -/** - * Updates the graphics object - * - * @static - * @private - * @method updateGraphics - * @param graphics {Graphics} - */ -PIXI.WebGLGraphics.updateGraphics = function(graphics) -{ - for (var i=graphics._webGL.lastIndex; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - - if(data.type == PIXI.Graphics.POLY) - { - if(data.fill) - { - if(data.points.length>3) - PIXI.WebGLGraphics.buildPoly(data, graphics._webGL); - } - - if(data.lineWidth > 0) - { - PIXI.WebGLGraphics.buildLine(data, graphics._webGL); - } - } - else if(data.type == PIXI.Graphics.RECT) - { - PIXI.WebGLGraphics.buildRectangle(data, graphics._webGL); - } - else if(data.type == PIXI.Graphics.CIRC || data.type == PIXI.Graphics.ELIP) - { - PIXI.WebGLGraphics.buildCircle(data, graphics._webGL); - } - }; - - graphics._webGL.lastIndex = graphics.graphicsData.length; - - var gl = PIXI.gl; - - graphics._webGL.glPoints = new Float32Array(graphics._webGL.points); - - gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer); - gl.bufferData(gl.ARRAY_BUFFER, graphics._webGL.glPoints, gl.STATIC_DRAW); - - graphics._webGL.glIndicies = new Uint16Array(graphics._webGL.indices); - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.glIndicies, gl.STATIC_DRAW); -} - -/** - * Builds a rectangle to draw - * - * @static - * @private - * @method buildRectangle - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData) -{ - // --- // - // need to convert points to a nice regular data - // - var rectData = graphicsData.points; - var x = rectData[0]; - var y = rectData[1]; - var width = rectData[2]; - var height = rectData[3]; - - - if(graphicsData.fill) - { - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vertPos = verts.length/6; - - // start - verts.push(x, y); - verts.push(r, g, b, alpha); - - verts.push(x + width, y); - verts.push(r, g, b, alpha); - - verts.push(x , y + height); - verts.push(r, g, b, alpha); - - verts.push(x + width, y + height); - verts.push(r, g, b, alpha); - - // insert 2 dead triangles.. - indices.push(vertPos, vertPos, vertPos+1, vertPos+2, vertPos+3, vertPos+3) - } - - if(graphicsData.lineWidth) - { - graphicsData.points = [x, y, - x + width, y, - x + width, y + height, - x, y + height, - x, y]; - - PIXI.WebGLGraphics.buildLine(graphicsData, webGLData); - } - -} - -/** - * Builds a circle to draw - * - * @static - * @private - * @method buildCircle - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildCircle = function(graphicsData, webGLData) -{ - // --- // - // need to convert points to a nice regular data - // - var rectData = graphicsData.points; - var x = rectData[0]; - var y = rectData[1]; - var width = rectData[2]; - var height = rectData[3]; - - var totalSegs = 40; - var seg = (Math.PI * 2) / totalSegs ; - - if(graphicsData.fill) - { - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vecPos = verts.length/6; - - indices.push(vecPos); - - for (var i=0; i < totalSegs + 1 ; i++) - { - verts.push(x,y, r, g, b, alpha); - - verts.push(x + Math.sin(seg * i) * width, - y + Math.cos(seg * i) * height, - r, g, b, alpha); - - indices.push(vecPos++, vecPos++); - }; - - indices.push(vecPos-1); - } - - if(graphicsData.lineWidth) - { - graphicsData.points = []; - - for (var i=0; i < totalSegs + 1; i++) - { - graphicsData.points.push(x + Math.sin(seg * i) * width, - y + Math.cos(seg * i) * height) - }; - - PIXI.WebGLGraphics.buildLine(graphicsData, webGLData); - } - -} - -/** - * Builds a line to draw - * - * @static - * @private - * @method buildLine - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData) -{ - // TODO OPTIMISE! - - var wrap = true; - var points = graphicsData.points; - if(points.length == 0)return; - - // get first and last point.. figure out the middle! - var firstPoint = new PIXI.Point( points[0], points[1] ); - var lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] ); - - // if the first point is the last point - goona have issues :) - if(firstPoint.x == lastPoint.x && firstPoint.y == lastPoint.y) - { - points.pop(); - points.pop(); - - lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] ); - - var midPointX = lastPoint.x + (firstPoint.x - lastPoint.x) *0.5; - var midPointY = lastPoint.y + (firstPoint.y - lastPoint.y) *0.5; - - points.unshift(midPointX, midPointY); - points.push(midPointX, midPointY) - } - - var verts = webGLData.points; - var indices = webGLData.indices; - var length = points.length / 2; - var indexCount = points.length; - var indexStart = verts.length/6; - - // DRAW the Line - var width = graphicsData.lineWidth / 2; - - // sort color - var color = HEXtoRGB(graphicsData.lineColor); - var alpha = graphicsData.lineAlpha; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var p1x, p1y, p2x, p2y, p3x, p3y; - var perpx, perpy, perp2x, perp2y, perp3x, perp3y; - var ipx, ipy; - var a1, b1, c1, a2, b2, c2; - var denom, pdist, dist; - - p1x = points[0]; - p1y = points[1]; - - p2x = points[2]; - p2y = points[3]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - // start - verts.push(p1x - perpx , p1y - perpy, - r, g, b, alpha); - - verts.push(p1x + perpx , p1y + perpy, - r, g, b, alpha); - - for (var i = 1; i < length-1; i++) - { - p1x = points[(i-1)*2]; - p1y = points[(i-1)*2 + 1]; - - p2x = points[(i)*2] - p2y = points[(i)*2 + 1] - - p3x = points[(i+1)*2]; - p3y = points[(i+1)*2 + 1]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - perp2x = -(p2y - p3y); - perp2y = p2x - p3x; - - dist = Math.sqrt(perp2x*perp2x + perp2y*perp2y); - perp2x /= dist; - perp2y /= dist; - perp2x *= width; - perp2y *= width; - - a1 = (-perpy + p1y) - (-perpy + p2y); - b1 = (-perpx + p2x) - (-perpx + p1x); - c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y); - a2 = (-perp2y + p3y) - (-perp2y + p2y); - b2 = (-perp2x + p2x) - (-perp2x + p3x); - c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y); - - denom = a1*b2 - a2*b1; - - if (denom == 0) { - denom+=1; - } - - px = (b1*c2 - b2*c1)/denom; - py = (a2*c1 - a1*c2)/denom; - - pdist = (px -p2x) * (px -p2x) + (py -p2y) + (py -p2y); - - if(pdist > 140 * 140) - { - perp3x = perpx - perp2x; - perp3y = perpy - perp2y; - - dist = Math.sqrt(perp3x*perp3x + perp3y*perp3y); - perp3x /= dist; - perp3y /= dist; - perp3x *= width; - perp3y *= width; - - verts.push(p2x - perp3x, p2y -perp3y); - verts.push(r, g, b, alpha); - - verts.push(p2x + perp3x, p2y +perp3y); - verts.push(r, g, b, alpha); - - verts.push(p2x - perp3x, p2y -perp3y); - verts.push(r, g, b, alpha); - - indexCount++; - } - else - { - verts.push(px , py); - verts.push(r, g, b, alpha); - - verts.push(p2x - (px-p2x), p2y - (py - p2y));//, 4); - verts.push(r, g, b, alpha); - } - } - - p1x = points[(length-2)*2] - p1y = points[(length-2)*2 + 1] - - p2x = points[(length-1)*2] - p2y = points[(length-1)*2 + 1] - - perpx = -(p1y - p2y) - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - verts.push(p2x - perpx , p2y - perpy) - verts.push(r, g, b, alpha); - - verts.push(p2x + perpx , p2y + perpy) - verts.push(r, g, b, alpha); - - indices.push(indexStart); - - for (var i=0; i < indexCount; i++) - { - indices.push(indexStart++); - }; - - indices.push(indexStart-1); -} - -/** - * Builds a polygon to draw - * - * @static - * @private - * @method buildPoly - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildPoly = function(graphicsData, webGLData) -{ - var points = graphicsData.points; - if(points.length < 6)return; - - // get first and last point.. figure out the middle! - var verts = webGLData.points; - var indices = webGLData.indices; - - var length = points.length / 2; - - // sort color - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var triangles = PIXI.PolyK.Triangulate(points); - - var vertPos = verts.length / 6; - - for (var i=0; i < triangles.length; i+=3) - { - indices.push(triangles[i] + vertPos); - indices.push(triangles[i] + vertPos); - indices.push(triangles[i+1] + vertPos); - indices.push(triangles[i+2] +vertPos); - indices.push(triangles[i+2] + vertPos); - }; - - for (var i = 0; i < length; i++) - { - verts.push(points[i * 2], points[i * 2 + 1], - r, g, b, alpha); - }; -} - -function HEXtoRGB(hex) { - return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; -} - - - - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI._defaultFrame = new PIXI.Rectangle(0,0,1,1); - -// an instance of the gl context.. -// only one at the moment :/ -PIXI.gl; - -/** - * the WebGLRenderer is draws the stage and all its content onto a webGL enabled canvas. This renderer - * should be used for browsers support webGL. This Render works by automatically managing webGLBatchs. - * So no need for Sprite Batch's or Sprite Cloud's - * Dont forget to add the view to your DOM or you will not see anything :) - * - * @class WebGLRenderer - * @constructor - * @param width=0 {Number} the width of the canvas view - * @param height=0 {Number} the height of the canvas view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - * - */ -PIXI.WebGLRenderer = function(width, height, view, transparent) -{ - // do a catch.. only 1 webGL renderer.. - - this.transparent = !!transparent; - - this.width = width || 800; - this.height = height || 600; - - this.view = view || document.createElement( 'canvas' ); - this.view.width = this.width; - this.view.height = this.height; - - // deal with losing context.. - var scope = this; - this.view.addEventListener('webglcontextlost', function(event) { scope.handleContextLost(event); }, false) - this.view.addEventListener('webglcontextrestored', function(event) { scope.handleContextRestored(event); }, false) - - this.batchs = []; - - try - { - PIXI.gl = this.gl = this.view.getContext("experimental-webgl", { - alpha: this.transparent, - antialias:true, // SPEED UP?? - premultipliedAlpha:false, - stencil:true - }); - } - catch (e) - { - throw new Error(" This browser does not support webGL. Try using the canvas renderer" + this); - } - - PIXI.initPrimitiveShader(); - PIXI.initDefaultShader(); - PIXI.initDefaultStripShader(); - - PIXI.activateDefaultShader(); - - var gl = this.gl; - PIXI.WebGLRenderer.gl = gl; - - this.batch = new PIXI.WebGLBatch(gl); - gl.disable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); - - gl.enable(gl.BLEND); - gl.colorMask(true, true, true, this.transparent); - - PIXI.projection = new PIXI.Point(400, 300); - - this.resize(this.width, this.height); - this.contextLost = false; - - this.stageRenderGroup = new PIXI.WebGLRenderGroup(this.gl); -} - -// constructor -PIXI.WebGLRenderer.prototype.constructor = PIXI.WebGLRenderer; - -/** - * Gets a new WebGLBatch from the pool - * - * @static - * @method getBatch - * @return {WebGLBatch} - * @private - */ -PIXI.WebGLRenderer.getBatch = function() -{ - if(PIXI._batchs.length == 0) - { - return new PIXI.WebGLBatch(PIXI.WebGLRenderer.gl); - } - else - { - return PIXI._batchs.pop(); - } -} - -/** - * Puts a batch back into the pool - * - * @static - * @method returnBatch - * @param batch {WebGLBatch} The batch to return - * @private - */ -PIXI.WebGLRenderer.returnBatch = function(batch) -{ - batch.clean(); - PIXI._batchs.push(batch); -} - -/** - * Renders the stage to its webGL view - * - * @method render - * @param stage {Stage} the Stage element to be rendered - */ -PIXI.WebGLRenderer.prototype.render = function(stage) -{ - if(this.contextLost)return; - - - // if rendering a new stage clear the batchs.. - if(this.__stage !== stage) - { - // TODO make this work - // dont think this is needed any more? - //if(this.__stage)this.checkVisibility(this.__stage, false) - - this.__stage = stage; - this.stageRenderGroup.setRenderable(stage); - } - - // TODO not needed now... - // update children if need be - // best to remove first! - /*for (var i=0; i < stage.__childrenRemoved.length; i++) - { - var group = stage.__childrenRemoved[i].__renderGroup - if(group)group.removeDisplayObject(stage.__childrenRemoved[i]); - }*/ - - // update any textures - PIXI.WebGLRenderer.updateTextures(); - - // recursivly loop through all items! - //this.checkVisibility(stage, true); - - // update the scene graph - stage.updateTransform(); - - var gl = this.gl; - - // -- Does this need to be set every frame? -- // - gl.colorMask(true, true, true, this.transparent); - gl.viewport(0, 0, this.width, this.height); - - // set the correct matrix.. - // gl.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform, false, this.projectionMatrix); - - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - - gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); - gl.clear(gl.COLOR_BUFFER_BIT); - - // HACK TO TEST - //PIXI.projectionMatrix = this.projectionMatrix; - - this.stageRenderGroup.backgroundColor = stage.backgroundColorSplit; - this.stageRenderGroup.render(PIXI.projection); - - // interaction - // run interaction! - if(stage.interactive) - { - //need to add some events! - if(!stage._interactiveEventsAdded) - { - stage._interactiveEventsAdded = true; - stage.interactionManager.setTarget(this); - } - } - - // after rendering lets confirm all frames that have been uodated.. - if(PIXI.Texture.frameUpdates.length > 0) - { - for (var i=0; i < PIXI.Texture.frameUpdates.length; i++) - { - PIXI.Texture.frameUpdates[i].updateFrame = false; - }; - - PIXI.Texture.frameUpdates = []; - } -} - -/** - * Updates the textures loaded into this webgl renderer - * - * @static - * @method updateTextures - * @private - */ -PIXI.WebGLRenderer.updateTextures = function() -{ - for (var i=0; i < PIXI.texturesToUpdate.length; i++) this.updateTexture(PIXI.texturesToUpdate[i]); - for (var i=0; i < PIXI.texturesToDestroy.length; i++) this.destroyTexture(PIXI.texturesToDestroy[i]); - PIXI.texturesToUpdate = []; - PIXI.texturesToDestroy = []; -} - -/** - * Updates a loaded webgl texture - * - * @static - * @method updateTexture - * @param texture {Texture} The texture to update - * @private - */ -PIXI.WebGLRenderer.updateTexture = function(texture) -{ - var gl = PIXI.gl; - - if(!texture._glTexture) - { - texture._glTexture = gl.createTexture(); - } - - if(texture.hasLoaded) - { - gl.bindTexture(gl.TEXTURE_2D, texture._glTexture); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true); - - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - - // reguler... - - if(!texture._powerOf2) - { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - } - else - { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); - } - - gl.bindTexture(gl.TEXTURE_2D, null); - } -} - -/** - * Destroys a loaded webgl texture - * - * @method destroyTexture - * @param texture {Texture} The texture to update - * @private - */ -PIXI.WebGLRenderer.prototype.destroyTexture = function(texture) -{ - var gl = this.gl; - - if(texture._glTexture) - { - texture._glTexture = gl.createTexture(); - gl.deleteTexture(gl.TEXTURE_2D, texture._glTexture); - } -} - -/** - * resizes the webGL view to the specified width and height - * - * @method resize - * @param width {Number} the new width of the webGL view - * @param height {Number} the new height of the webGL view - */ -PIXI.WebGLRenderer.prototype.resize = function(width, height) -{ - this.width = width; - this.height = height; - - this.view.width = width; - this.view.height = height; - - this.gl.viewport(0, 0, this.width, this.height); - - //var projectionMatrix = this.projectionMatrix; - - PIXI.projection.x = this.width/2; - PIXI.projection.y = this.height/2; - -// projectionMatrix[0] = 2/this.width; -// projectionMatrix[5] = -2/this.height; -// projectionMatrix[12] = -1; -// projectionMatrix[13] = 1; -} - -/** - * Handles a lost webgl context - * - * @method handleContextLost - * @param event {Event} - * @private - */ -PIXI.WebGLRenderer.prototype.handleContextLost = function(event) -{ - event.preventDefault(); - this.contextLost = true; -} - -/** - * Handles a restored webgl context - * - * @method handleContextRestored - * @param event {Event} - * @private - */ -PIXI.WebGLRenderer.prototype.handleContextRestored = function(event) -{ - this.gl = this.view.getContext("experimental-webgl", { - alpha: true - }); - - this.initShaders(); - - for(var key in PIXI.TextureCache) - { - var texture = PIXI.TextureCache[key].baseTexture; - texture._glTexture = null; - PIXI.WebGLRenderer.updateTexture(texture); - }; - - for (var i=0; i < this.batchs.length; i++) - { - this.batchs[i].restoreLostContext(this.gl)// - this.batchs[i].dirty = true; - }; - - PIXI._restoreBatchs(this.gl); - - this.contextLost = false; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI._batchs = []; - -/** - * @private - */ -PIXI._getBatch = function(gl) -{ - if(PIXI._batchs.length == 0) - { - return new PIXI.WebGLBatch(gl); - } - else - { - return PIXI._batchs.pop(); - } -} - -/** - * @private - */ -PIXI._returnBatch = function(batch) -{ - batch.clean(); - PIXI._batchs.push(batch); -} - -/** - * @private - */ -PIXI._restoreBatchs = function(gl) -{ - for (var i=0; i < PIXI._batchs.length; i++) - { - PIXI._batchs[i].restoreLostContext(gl); - }; -} - -/** - * A WebGLBatch Enables a group of sprites to be drawn using the same settings. - * if a group of sprites all have the same baseTexture and blendMode then they can be grouped into a batch. - * All the sprites in a batch can then be drawn in one go by the GPU which is hugely efficient. ALL sprites - * in the webGL renderer are added to a batch even if the batch only contains one sprite. Batching is handled - * automatically by the webGL renderer. A good tip is: the smaller the number of batchs there are, the faster - * the webGL renderer will run. - * - * @class WebGLBatch - * @constructor - * @param gl {WebGLContext} an instance of the webGL context - */ -PIXI.WebGLBatch = function(gl) -{ - this.gl = gl; - - this.size = 0; - - this.vertexBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - this.uvBuffer = gl.createBuffer(); - this.colorBuffer = gl.createBuffer(); - this.blendMode = PIXI.blendModes.NORMAL; - this.dynamicSize = 1; -} - -// constructor -PIXI.WebGLBatch.prototype.constructor = PIXI.WebGLBatch; - -/** - * Cleans the batch so that is can be returned to an object pool and reused - * - * @method clean - */ -PIXI.WebGLBatch.prototype.clean = function() -{ - this.verticies = []; - this.uvs = []; - this.indices = []; - this.colors = []; - //this.sprites = []; - this.dynamicSize = 1; - this.texture = null; - this.last = null; - this.size = 0; - this.head; - this.tail; -} - -/** - * Recreates the buffers in the event of a context loss - * - * @method restoreLostContext - * @param gl {WebGLContext} - */ -PIXI.WebGLBatch.prototype.restoreLostContext = function(gl) -{ - this.gl = gl; - this.vertexBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - this.uvBuffer = gl.createBuffer(); - this.colorBuffer = gl.createBuffer(); -} - -/** - * inits the batch's texture and blend mode based if the supplied sprite - * - * @method init - * @param sprite {Sprite} the first sprite to be added to the batch. Only sprites with - * the same base texture and blend mode will be allowed to be added to this batch - */ -PIXI.WebGLBatch.prototype.init = function(sprite) -{ - sprite.batch = this; - this.dirty = true; - this.blendMode = sprite.blendMode; - this.texture = sprite.texture.baseTexture; -// this.sprites.push(sprite); - this.head = sprite; - this.tail = sprite; - this.size = 1; - - this.growBatch(); -} - -/** - * inserts a sprite before the specified sprite - * - * @method insertBefore - * @param sprite {Sprite} the sprite to be added - * @param nextSprite {nextSprite} the first sprite will be inserted before this sprite - */ -PIXI.WebGLBatch.prototype.insertBefore = function(sprite, nextSprite) -{ - this.size++; - - sprite.batch = this; - this.dirty = true; - var tempPrev = nextSprite.__prev; - nextSprite.__prev = sprite; - sprite.__next = nextSprite; - - if(tempPrev) - { - sprite.__prev = tempPrev; - tempPrev.__next = sprite; - } - else - { - this.head = sprite; - //this.head.__prev = null - } -} - -/** - * inserts a sprite after the specified sprite - * - * @method insertAfter - * @param sprite {Sprite} the sprite to be added - * @param previousSprite {Sprite} the first sprite will be inserted after this sprite - */ -PIXI.WebGLBatch.prototype.insertAfter = function(sprite, previousSprite) -{ - this.size++; - - sprite.batch = this; - this.dirty = true; - - var tempNext = previousSprite.__next; - previousSprite.__next = sprite; - sprite.__prev = previousSprite; - - if(tempNext) - { - sprite.__next = tempNext; - tempNext.__prev = sprite; - } - else - { - this.tail = sprite - } -} - -/** - * removes a sprite from the batch - * - * @method remove - * @param sprite {Sprite} the sprite to be removed - */ -PIXI.WebGLBatch.prototype.remove = function(sprite) -{ - this.size--; - - if(this.size == 0) - { - sprite.batch = null; - sprite.__prev = null; - sprite.__next = null; - return; - } - - if(sprite.__prev) - { - sprite.__prev.__next = sprite.__next; - } - else - { - this.head = sprite.__next; - this.head.__prev = null; - } - - if(sprite.__next) - { - sprite.__next.__prev = sprite.__prev; - } - else - { - this.tail = sprite.__prev; - this.tail.__next = null - } - - sprite.batch = null; - sprite.__next = null; - sprite.__prev = null; - this.dirty = true; -} - -/** - * Splits the batch into two with the specified sprite being the start of the new batch. - * - * @method split - * @param sprite {Sprite} the sprite that indicates where the batch should be split - * @return {WebGLBatch} the new batch - */ -PIXI.WebGLBatch.prototype.split = function(sprite) -{ - this.dirty = true; - - var batch = new PIXI.WebGLBatch(this.gl);//PIXI._getBatch(this.gl); - batch.init(sprite); - batch.texture = this.texture; - batch.tail = this.tail; - - this.tail = sprite.__prev; - this.tail.__next = null; - - sprite.__prev = null; - // return a splite batch! - //sprite.__prev.__next = null; - //sprite.__prev = null; - - // TODO this size is wrong! - // need to recalculate :/ problem with a linked list! - // unless it gets calculated in the "clean"? - - // need to loop through items as there is no way to know the length on a linked list :/ - var tempSize = 0; - while(sprite) - { - tempSize++; - sprite.batch = batch; - sprite = sprite.__next; - } - - batch.size = tempSize; - this.size -= tempSize; - - return batch; -} - -/** - * Merges two batchs together - * - * @method merge - * @param batch {WebGLBatch} the batch that will be merged - */ -PIXI.WebGLBatch.prototype.merge = function(batch) -{ - this.dirty = true; - - this.tail.__next = batch.head; - batch.head.__prev = this.tail; - - this.size += batch.size; - - this.tail = batch.tail; - - var sprite = batch.head; - while(sprite) - { - sprite.batch = this; - sprite = sprite.__next; - } -} - -/** - * Grows the size of the batch. As the elements in the batch cannot have a dynamic size this - * function is used to increase the size of the batch. It also creates a little extra room so - * that the batch does not need to be resized every time a sprite is added - * - * @method growBatch - */ -PIXI.WebGLBatch.prototype.growBatch = function() -{ - var gl = this.gl; - if( this.size == 1) - { - this.dynamicSize = 1; - } - else - { - this.dynamicSize = this.size * 1.5 - } - // grow verts - this.verticies = new Float32Array(this.dynamicSize * 8); - - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER,this.verticies , gl.DYNAMIC_DRAW); - - this.uvs = new Float32Array( this.dynamicSize * 8 ) - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, this.uvs , gl.DYNAMIC_DRAW); - - this.dirtyUVS = true; - - this.colors = new Float32Array( this.dynamicSize * 4 ) - gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, this.colors , gl.DYNAMIC_DRAW); - - this.dirtyColors = true; - - this.indices = new Uint16Array(this.dynamicSize * 6); - var length = this.indices.length/6; - - for (var i=0; i < length; i++) - { - var index2 = i * 6; - var index3 = i * 4; - this.indices[index2 + 0] = index3 + 0; - this.indices[index2 + 1] = index3 + 1; - this.indices[index2 + 2] = index3 + 2; - this.indices[index2 + 3] = index3 + 0; - this.indices[index2 + 4] = index3 + 2; - this.indices[index2 + 5] = index3 + 3; - }; - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW); -} - -/** - * Refresh's all the data in the batch and sync's it with the webGL buffers - * - * @method refresh - */ -PIXI.WebGLBatch.prototype.refresh = function() -{ - var gl = this.gl; - - if (this.dynamicSize < this.size) - { - this.growBatch(); - } - - var indexRun = 0; - var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index; - var a, b, c, d, tx, ty; - - var displayObject = this.head; - - while(displayObject) - { - index = indexRun * 8; - - var texture = displayObject.texture; - - var frame = texture.frame; - var tw = texture.baseTexture.width; - var th = texture.baseTexture.height; - - this.uvs[index + 0] = frame.x / tw; - this.uvs[index +1] = frame.y / th; - - this.uvs[index +2] = (frame.x + frame.width) / tw; - this.uvs[index +3] = frame.y / th; - - this.uvs[index +4] = (frame.x + frame.width) / tw; - this.uvs[index +5] = (frame.y + frame.height) / th; - - this.uvs[index +6] = frame.x / tw; - this.uvs[index +7] = (frame.y + frame.height) / th; - - displayObject.updateFrame = false; - - colorIndex = indexRun * 4; - this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha; - - displayObject = displayObject.__next; - - indexRun ++; - } - - this.dirtyUVS = true; - this.dirtyColors = true; -} - -/** - * Updates all the relevant geometry and uploads the data to the GPU - * - * @method update - */ -PIXI.WebGLBatch.prototype.update = function() -{ - var gl = this.gl; - var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, index2, index3 - - var a, b, c, d, tx, ty; - - var indexRun = 0; - - var displayObject = this.head; - - while(displayObject) - { - if(displayObject.worldVisible) - { - width = displayObject.texture.frame.width; - height = displayObject.texture.frame.height; - - // TODO trim?? - aX = displayObject.anchor.x;// - displayObject.texture.trim.x - aY = displayObject.anchor.y; //- displayObject.texture.trim.y - w0 = width * (1-aX); - w1 = width * -aX; - - h0 = height * (1-aY); - h1 = height * -aY; - - index = indexRun * 8; - - worldTransform = displayObject.worldTransform; - - a = worldTransform[0]; - b = worldTransform[3]; - c = worldTransform[1]; - d = worldTransform[4]; - tx = worldTransform[2]; - ty = worldTransform[5]; - - this.verticies[index + 0 ] = a * w1 + c * h1 + tx; - this.verticies[index + 1 ] = d * h1 + b * w1 + ty; - - this.verticies[index + 2 ] = a * w0 + c * h1 + tx; - this.verticies[index + 3 ] = d * h1 + b * w0 + ty; - - this.verticies[index + 4 ] = a * w0 + c * h0 + tx; - this.verticies[index + 5 ] = d * h0 + b * w0 + ty; - - this.verticies[index + 6] = a * w1 + c * h0 + tx; - this.verticies[index + 7] = d * h0 + b * w1 + ty; - - if(displayObject.updateFrame || displayObject.texture.updateFrame) - { - this.dirtyUVS = true; - - var texture = displayObject.texture; - - var frame = texture.frame; - var tw = texture.baseTexture.width; - var th = texture.baseTexture.height; - - this.uvs[index + 0] = frame.x / tw; - this.uvs[index +1] = frame.y / th; - - this.uvs[index +2] = (frame.x + frame.width) / tw; - this.uvs[index +3] = frame.y / th; - - this.uvs[index +4] = (frame.x + frame.width) / tw; - this.uvs[index +5] = (frame.y + frame.height) / th; - - this.uvs[index +6] = frame.x / tw; - this.uvs[index +7] = (frame.y + frame.height) / th; - - displayObject.updateFrame = false; - } - - // TODO this probably could do with some optimisation.... - if(displayObject.cacheAlpha != displayObject.worldAlpha) - { - displayObject.cacheAlpha = displayObject.worldAlpha; - - var colorIndex = indexRun * 4; - this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha; - this.dirtyColors = true; - } - } - else - { - index = indexRun * 8; - - this.verticies[index + 0 ] = 0; - this.verticies[index + 1 ] = 0; - - this.verticies[index + 2 ] = 0; - this.verticies[index + 3 ] = 0; - - this.verticies[index + 4 ] = 0; - this.verticies[index + 5 ] = 0; - - this.verticies[index + 6] = 0; - this.verticies[index + 7] = 0; - } - - indexRun++; - displayObject = displayObject.__next; - } -} - -/** - * Draws the batch to the frame buffer - * - * @method render - */ -PIXI.WebGLBatch.prototype.render = function(start, end) -{ - start = start || 0; - //end = end || this.size; - if(end == undefined)end = this.size; - - if(this.dirty) - { - this.refresh(); - this.dirty = false; - } - - if (this.size == 0)return; - - this.update(); - var gl = this.gl; - - //TODO optimize this! - - var shaderProgram = PIXI.shaderProgram; - gl.useProgram(shaderProgram); - - // update the verts.. - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - // ok.. - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.verticies) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - - if(this.dirtyUVS) - { - this.dirtyUVS = false; - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvs); - } - - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, this.texture._glTexture); - - // update color! - gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer); - - if(this.dirtyColors) - { - this.dirtyColors = false; - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.colors); - } - - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - - //var startIndex = 0//1; - var len = end - start; - // console.log(this.size) - // DRAW THAT this! - gl.drawElements(gl.TRIANGLES, len * 6, gl.UNSIGNED_SHORT, start * 2 * 6 ); -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A WebGLBatch Enables a group of sprites to be drawn using the same settings. - * if a group of sprites all have the same baseTexture and blendMode then they can be - * grouped into a batch. All the sprites in a batch can then be drawn in one go by the - * GPU which is hugely efficient. ALL sprites in the webGL renderer are added to a batch - * even if the batch only contains one sprite. Batching is handled automatically by the - * webGL renderer. A good tip is: the smaller the number of batchs there are, the faster - * the webGL renderer will run. - * - * @class WebGLBatch - * @contructor - * @param gl {WebGLContext} An instance of the webGL context - */ -PIXI.WebGLRenderGroup = function(gl) -{ - this.gl = gl; - this.root; - - this.backgroundColor; - this.batchs = []; - this.toRemove = []; -} - -// constructor -PIXI.WebGLRenderGroup.prototype.constructor = PIXI.WebGLRenderGroup; - -/** - * Add a display object to the webgl renderer - * - * @method setRenderable - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.setRenderable = function(displayObject) -{ - // has this changed?? - if(this.root)this.removeDisplayObjectAndChildren(this.root); - - displayObject.worldVisible = displayObject.visible; - - // soooooo // - // to check if any batchs exist already?? - - // TODO what if its already has an object? should remove it - this.root = displayObject; - this.addDisplayObjectAndChildren(displayObject); -} - -/** - * Renders the stage to its webgl view - * - * @method render - * @param projection {Object} - */ -PIXI.WebGLRenderGroup.prototype.render = function(projection) -{ - PIXI.WebGLRenderer.updateTextures(); - - var gl = this.gl; - - - gl.uniform2f(PIXI.shaderProgram.projectionVector, projection.x, projection.y); - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - - // TODO remove this by replacing visible with getter setters.. - this.checkVisibility(this.root, this.root.visible); - - // will render all the elements in the group - var renderable; - - - for (var i=0; i < this.batchs.length; i++) - { - renderable = this.batchs[i]; - if(renderable instanceof PIXI.WebGLBatch) - { - this.batchs[i].render(); - } - else if(renderable instanceof PIXI.TilingSprite) - { - if(renderable.visible)this.renderTilingSprite(renderable, projection); - } - else if(renderable instanceof PIXI.Strip) - { - if(renderable.visible)this.renderStrip(renderable, projection); - } - else if(renderable instanceof PIXI.Graphics) - { - if(renderable.visible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable, projection);//, projectionMatrix); - } - else if(renderable instanceof PIXI.FilterBlock) - { - /* - * for now only masks are supported.. - */ - if(renderable.open) - { - gl.enable(gl.STENCIL_TEST); - - gl.colorMask(false, false, false, false); - gl.stencilFunc(gl.ALWAYS,1,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE); - - PIXI.WebGLGraphics.renderGraphics(renderable.mask, projection); - - gl.colorMask(true, true, true, false); - gl.stencilFunc(gl.NOTEQUAL,0,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); - } - else - { - gl.disable(gl.STENCIL_TEST); - } - } - } - -} - -/** - * Renders the stage to its webgl view - * - * @method handleFilter - * @param filter {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.handleFilter = function(filter, projection) -{ - -} - -/** - * Renders a specific displayObject - * - * @method renderSpecific - * @param displayObject {DisplayObject} - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderSpecific = function(displayObject, projection) -{ - PIXI.WebGLRenderer.updateTextures(); - - var gl = this.gl; - this.checkVisibility(displayObject, displayObject.visible); - -// gl.uniformMatrix4fv(PIXI.shaderProgram.mvMatrixUniform, false, projectionMatrix); - gl.uniform2f(PIXI.shaderProgram.projectionVector, projection.x, projection.y); - - // to do! - // render part of the scene... - - var startIndex; - var startBatchIndex; - - var endIndex; - var endBatchIndex; - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.first; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - var startBatch = nextRenderable.batch; - - if(nextRenderable instanceof PIXI.Sprite) - { - startBatch = nextRenderable.batch; - - var head = startBatch.head; - var next = head; - - // ok now we have the batch.. need to find the start index! - if(head == nextRenderable) - { - startIndex = 0; - } - else - { - startIndex = 1; - - while(head.__next != nextRenderable) - { - startIndex++; - head = head.__next; - } - } - } - else - { - startBatch = nextRenderable; - } - - // Get the LAST renderable object - var lastRenderable = displayObject; - var endBatch; - var lastItem = displayObject; - while(lastItem.children.length > 0) - { - lastItem = lastItem.children[lastItem.children.length-1]; - if(lastItem.renderable)lastRenderable = lastItem; - } - - if(lastRenderable instanceof PIXI.Sprite) - { - endBatch = lastRenderable.batch; - - var head = endBatch.head; - - if(head == lastRenderable) - { - endIndex = 0; - } - else - { - endIndex = 1; - - while(head.__next != lastRenderable) - { - endIndex++; - head = head.__next; - } - } - } - else - { - endBatch = lastRenderable; - } - - // TODO - need to fold this up a bit! - - if(startBatch == endBatch) - { - if(startBatch instanceof PIXI.WebGLBatch) - { - startBatch.render(startIndex, endIndex+1); - } - else - { - this.renderSpecial(startBatch, projection); - } - return; - } - - // now we have first and last! - startBatchIndex = this.batchs.indexOf(startBatch); - endBatchIndex = this.batchs.indexOf(endBatch); - - // DO the first batch - if(startBatch instanceof PIXI.WebGLBatch) - { - startBatch.render(startIndex); - } - else - { - this.renderSpecial(startBatch, projection); - } - - // DO the middle batchs.. - for (var i=startBatchIndex+1; i < endBatchIndex; i++) - { - renderable = this.batchs[i]; - - if(renderable instanceof PIXI.WebGLBatch) - { - this.batchs[i].render(); - } - else - { - this.renderSpecial(renderable, projection); - } - } - - // DO the last batch.. - if(endBatch instanceof PIXI.WebGLBatch) - { - endBatch.render(0, endIndex+1); - } - else - { - this.renderSpecial(endBatch, projection); - } -} - -/** - * Renders a specific renderable - * - * @method renderSpecial - * @param renderable {DisplayObject} - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderSpecial = function(renderable, projection) -{ - if(renderable instanceof PIXI.TilingSprite) - { - if(renderable.visible)this.renderTilingSprite(renderable, projection); - } - else if(renderable instanceof PIXI.Strip) - { - if(renderable.visible)this.renderStrip(renderable, projection); - } - else if(renderable instanceof PIXI.CustomRenderable) - { - if(renderable.visible) renderable.renderWebGL(this, projection); - } - else if(renderable instanceof PIXI.Graphics) - { - if(renderable.visible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable, projection); - } - else if(renderable instanceof PIXI.FilterBlock) - { - /* - * for now only masks are supported.. - */ - - var gl = PIXI.gl; - - if(renderable.open) - { - gl.enable(gl.STENCIL_TEST); - - gl.colorMask(false, false, false, false); - gl.stencilFunc(gl.ALWAYS,1,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE); - - PIXI.WebGLGraphics.renderGraphics(renderable.mask, projection); - - // we know this is a render texture so enable alpha too.. - gl.colorMask(true, true, true, true); - gl.stencilFunc(gl.NOTEQUAL,0,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); - } - else - { - gl.disable(gl.STENCIL_TEST); - } - } -} - -/** - * Checks the visibility of a displayObject - * - * @method checkVisibility - * @param displayObject {DisplayObject} - * @param globalVisible {Boolean} - * @private - */ -PIXI.WebGLRenderGroup.prototype.checkVisibility = function(displayObject, globalVisible) -{ - // give the dp a reference to its renderGroup... - var children = displayObject.children; - //displayObject.worldVisible = globalVisible; - for (var i=0; i < children.length; i++) - { - var child = children[i]; - - // TODO optimize... should'nt need to loop through everything all the time - child.worldVisible = child.visible && globalVisible; - - // everything should have a batch! - // time to see whats new! - if(child.textureChange) - { - child.textureChange = false; - if(child.worldVisible)this.updateTexture(child); - // update texture!! - } - - if(child.children.length > 0) - { - this.checkVisibility(child, child.worldVisible); - } - }; -} - -/** - * Updates a webgl texture - * - * @method updateTexture - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.updateTexture = function(displayObject) -{ - - // TODO definitely can optimse this function.. - - this.removeObject(displayObject); - - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - var previousRenderable = displayObject.first; - while(previousRenderable != this.root) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.last; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - - this.insertObject(displayObject, previousRenderable, nextRenderable); -} - -/** - * Adds filter blocks - * - * @method addFilterBlocks - * @param start {FilterBlock} - * @param end {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.addFilterBlocks = function(start, end) -{ - start.__renderGroup = this; - end.__renderGroup = this; - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - var previousRenderable = start; - while(previousRenderable != this.root) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - this.insertAfter(start, previousRenderable); - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var previousRenderable2 = end; - while(previousRenderable2 != this.root) - { - previousRenderable2 = previousRenderable2._iPrev; - if(previousRenderable2.renderable && previousRenderable2.__renderGroup)break; - } - this.insertAfter(end, previousRenderable2); -} - -/** - * Remove filter blocks - * - * @method removeFilterBlocks - * @param start {FilterBlock} - * @param end {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeFilterBlocks = function(start, end) -{ - this.removeObject(start); - this.removeObject(end); -} - -/** - * Adds a display object and children to the webgl context - * - * @method addDisplayObjectAndChildren - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.addDisplayObjectAndChildren = function(displayObject) -{ - if(displayObject.__renderGroup)displayObject.__renderGroup.removeDisplayObjectAndChildren(displayObject); - - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - - var previousRenderable = displayObject.first; - while(previousRenderable != this.root.first) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.last; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - - // one the display object hits this. we can break the loop - - var tempObject = displayObject.first; - var testObject = displayObject.last._iNext; - do - { - tempObject.__renderGroup = this; - - if(tempObject.renderable) - { - - this.insertObject(tempObject, previousRenderable, nextRenderable); - previousRenderable = tempObject; - } - - tempObject = tempObject._iNext; - } - while(tempObject != testObject) -} - -/** - * Removes a display object and children to the webgl context - * - * @method removeDisplayObjectAndChildren - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeDisplayObjectAndChildren = function(displayObject) -{ - if(displayObject.__renderGroup != this)return; - -// var displayObject = displayObject.first; - var lastObject = displayObject.last; - do - { - displayObject.__renderGroup = null; - if(displayObject.renderable)this.removeObject(displayObject); - displayObject = displayObject._iNext; - } - while(displayObject) -} - -/** - * Inserts a displayObject into the linked list - * - * @method insertObject - * @param displayObject {DisplayObject} - * @param previousObject {DisplayObject} - * @param nextObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.insertObject = function(displayObject, previousObject, nextObject) -{ - // while looping below THE OBJECT MAY NOT HAVE BEEN ADDED - var previousSprite = previousObject; - var nextSprite = nextObject; - - /* - * so now we have the next renderable and the previous renderable - * - */ - if(displayObject instanceof PIXI.Sprite) - { - var previousBatch - var nextBatch - - if(previousSprite instanceof PIXI.Sprite) - { - previousBatch = previousSprite.batch; - if(previousBatch) - { - if(previousBatch.texture == displayObject.texture.baseTexture && previousBatch.blendMode == displayObject.blendMode) - { - previousBatch.insertAfter(displayObject, previousSprite); - return; - } - } - } - else - { - // TODO reword! - previousBatch = previousSprite; - } - - if(nextSprite) - { - if(nextSprite instanceof PIXI.Sprite) - { - nextBatch = nextSprite.batch; - - //batch may not exist if item was added to the display list but not to the webGL - if(nextBatch) - { - if(nextBatch.texture == displayObject.texture.baseTexture && nextBatch.blendMode == displayObject.blendMode) - { - nextBatch.insertBefore(displayObject, nextSprite); - return; - } - else - { - if(nextBatch == previousBatch) - { - // THERE IS A SPLIT IN THIS BATCH! // - var splitBatch = previousBatch.split(nextSprite); - // COOL! - // add it back into the array - /* - * OOPS! - * seems the new sprite is in the middle of a batch - * lets split it.. - */ - var batch = PIXI.WebGLRenderer.getBatch(); - - var index = this.batchs.indexOf( previousBatch ); - batch.init(displayObject); - this.batchs.splice(index+1, 0, batch, splitBatch); - - return; - } - } - } - } - else - { - // TODO re-word! - - nextBatch = nextSprite; - } - } - - /* - * looks like it does not belong to any batch! - * but is also not intersecting one.. - * time to create anew one! - */ - - var batch = PIXI.WebGLRenderer.getBatch(); - batch.init(displayObject); - - if(previousBatch) // if this is invalid it means - { - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, batch); - } - else - { - this.batchs.push(batch); - } - - return; - } - else if(displayObject instanceof PIXI.TilingSprite) - { - - // add to a batch!! - this.initTilingSprite(displayObject); - // this.batchs.push(displayObject); - - } - else if(displayObject instanceof PIXI.Strip) - { - // add to a batch!! - this.initStrip(displayObject); - // this.batchs.push(displayObject); - } - else if(displayObject)// instanceof PIXI.Graphics) - { - //displayObject.initWebGL(this); - - // add to a batch!! - //this.initStrip(displayObject); - //this.batchs.push(displayObject); - } - - this.insertAfter(displayObject, previousSprite); - - // insert and SPLIT! - -} - -/** - * Inserts a displayObject into the linked list - * - * @method insertAfter - * @param item {DisplayObject} - * @param displayObject {DisplayObject} The object to insert - * @private - */ -PIXI.WebGLRenderGroup.prototype.insertAfter = function(item, displayObject) -{ - if(displayObject instanceof PIXI.Sprite) - { - var previousBatch = displayObject.batch; - - if(previousBatch) - { - // so this object is in a batch! - - // is it not? need to split the batch - if(previousBatch.tail == displayObject) - { - // is it tail? insert in to batchs - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, item); - } - else - { - // TODO MODIFY ADD / REMOVE CHILD TO ACCOUNT FOR FILTERS (also get prev and next) // - - // THERE IS A SPLIT IN THIS BATCH! // - var splitBatch = previousBatch.split(displayObject.__next); - - // COOL! - // add it back into the array - /* - * OOPS! - * seems the new sprite is in the middle of a batch - * lets split it.. - */ - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, item, splitBatch); - } - } - else - { - this.batchs.push(item); - } - } - else - { - var index = this.batchs.indexOf( displayObject ); - this.batchs.splice(index+1, 0, item); - } -} - -/** - * Removes a displayObject from the linked list - * - * @method removeObject - * @param displayObject {DisplayObject} The object to remove - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeObject = function(displayObject) -{ - // loop through children.. - // display object // - - // add a child from the render group.. - // remove it and all its children! - //displayObject.cacheVisible = false;//displayObject.visible; - - /* - * removing is a lot quicker.. - * - */ - var batchToRemove; - - if(displayObject instanceof PIXI.Sprite) - { - // should always have a batch! - var batch = displayObject.batch; - if(!batch)return; // this means the display list has been altered befre rendering - - batch.remove(displayObject); - - if(batch.size==0) - { - batchToRemove = batch; - } - } - else - { - batchToRemove = displayObject; - } - - /* - * Looks like there is somthing that needs removing! - */ - if(batchToRemove) - { - var index = this.batchs.indexOf( batchToRemove ); - if(index == -1)return;// this means it was added then removed before rendered - - // ok so.. check to see if you adjacent batchs should be joined. - // TODO may optimise? - if(index == 0 || index == this.batchs.length-1) - { - // wha - eva! just get of the empty batch! - this.batchs.splice(index, 1); - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - - return; - } - - if(this.batchs[index-1] instanceof PIXI.WebGLBatch && this.batchs[index+1] instanceof PIXI.WebGLBatch) - { - if(this.batchs[index-1].texture == this.batchs[index+1].texture && this.batchs[index-1].blendMode == this.batchs[index+1].blendMode) - { - //console.log("MERGE") - this.batchs[index-1].merge(this.batchs[index+1]); - - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - PIXI.WebGLRenderer.returnBatch(this.batchs[index+1]); - this.batchs.splice(index, 2); - return; - } - } - - this.batchs.splice(index, 1); - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - } -} - -/** - * Initializes a tiling sprite - * - * @method initTilingSprite - * @param sprite {TilingSprite} The tiling sprite to initialize - * @private - */ -PIXI.WebGLRenderGroup.prototype.initTilingSprite = function(sprite) -{ - var gl = this.gl; - - // make the texture tilable.. - - sprite.verticies = new Float32Array([0, 0, - sprite.width, 0, - sprite.width, sprite.height, - 0, sprite.height]); - - sprite.uvs = new Float32Array([0, 0, - 1, 0, - 1, 1, - 0, 1]); - - sprite.colors = new Float32Array([1,1,1,1]); - - sprite.indices = new Uint16Array([0, 1, 3,2])//, 2]); - - sprite._vertexBuffer = gl.createBuffer(); - sprite._indexBuffer = gl.createBuffer(); - sprite._uvBuffer = gl.createBuffer(); - sprite._colorBuffer = gl.createBuffer(); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.verticies, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.uvs, gl.DYNAMIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.colors, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, sprite._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, sprite.indices, gl.STATIC_DRAW); - -// return ( (x > 0) && ((x & (x - 1)) == 0) ); - - if(sprite.texture.baseTexture._glTexture) - { - gl.bindTexture(gl.TEXTURE_2D, sprite.texture.baseTexture._glTexture); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); - sprite.texture.baseTexture._powerOf2 = true; - } - else - { - sprite.texture.baseTexture._powerOf2 = true; - } -} - -/** - * Renders a Strip - * - * @method renderStrip - * @param strip {Strip} The strip to render - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderStrip = function(strip, projection) -{ - var gl = this.gl; - var shaderProgram = PIXI.shaderProgram; -// mat - //var mat4Real = PIXI.mat3.toMat4(strip.worldTransform); - //PIXI.mat4.transpose(mat4Real); - //PIXI.mat4.multiply(projectionMatrix, mat4Real, mat4Real ) - - - gl.useProgram(PIXI.stripShaderProgram); - - var m = PIXI.mat3.clone(strip.worldTransform); - - PIXI.mat3.transpose(m); - - // set the matrix transform for the - gl.uniformMatrix3fv(PIXI.stripShaderProgram.translationMatrix, false, m); - gl.uniform2f(PIXI.stripShaderProgram.projectionVector, projection.x, projection.y); - gl.uniform1f(PIXI.stripShaderProgram.alpha, strip.worldAlpha); - -/* - if(strip.blendMode == PIXI.blendModes.NORMAL) - { - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - } - else - { - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR); - } - */ - - - if(!strip.dirty) - { - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferSubData(gl.ARRAY_BUFFER, 0, strip.verticies) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - } - else - { - strip.dirty = false; - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW); - - } - //console.log(gl.TRIANGLE_STRIP); - - gl.drawElements(gl.TRIANGLE_STRIP, strip.indices.length, gl.UNSIGNED_SHORT, 0); - - gl.useProgram(PIXI.shaderProgram); -} - -/** - * Renders a TilingSprite - * - * @method renderTilingSprite - * @param sprite {TilingSprite} The tiling sprite to render - * @param projectionMatrix {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderTilingSprite = function(sprite, projectionMatrix) -{ - var gl = this.gl; - var shaderProgram = PIXI.shaderProgram; - - var tilePosition = sprite.tilePosition; - var tileScale = sprite.tileScale; - - var offsetX = tilePosition.x/sprite.texture.baseTexture.width; - var offsetY = tilePosition.y/sprite.texture.baseTexture.height; - - var scaleX = (sprite.width / sprite.texture.baseTexture.width) / tileScale.x; - var scaleY = (sprite.height / sprite.texture.baseTexture.height) / tileScale.y; - - sprite.uvs[0] = 0 - offsetX; - sprite.uvs[1] = 0 - offsetY; - - sprite.uvs[2] = (1 * scaleX) -offsetX; - sprite.uvs[3] = 0 - offsetY; - - sprite.uvs[4] = (1 *scaleX) - offsetX; - sprite.uvs[5] = (1 *scaleY) - offsetY; - - sprite.uvs[6] = 0 - offsetX; - sprite.uvs[7] = (1 *scaleY) - offsetY; - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._uvBuffer); - gl.bufferSubData(gl.ARRAY_BUFFER, 0, sprite.uvs) - - this.renderStrip(sprite, projectionMatrix); -} - -/** - * Initializes a strip to be rendered - * - * @method initStrip - * @param strip {Strip} The strip to initialize - * @private - */ -PIXI.WebGLRenderGroup.prototype.initStrip = function(strip) -{ - // build the strip! - var gl = this.gl; - var shaderProgram = this.shaderProgram; - - strip._vertexBuffer = gl.createBuffer(); - strip._indexBuffer = gl.createBuffer(); - strip._uvBuffer = gl.createBuffer(); - strip._colorBuffer = gl.createBuffer(); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.DYNAMIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW); - - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW); -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * the CanvasRenderer draws the stage and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. - * Dont forget to add the view to your DOM or you will not see anything :) - * - * @class CanvasRenderer - * @constructor - * @param width=0 {Number} the width of the canvas view - * @param height=0 {Number} the height of the canvas view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - */ -PIXI.CanvasRenderer = function(width, height, view, transparent) -{ - this.transparent = transparent; - - /** - * The width of the canvas view - * - * @property width - * @type Number - * @default 800 - */ - this.width = width || 800; - - /** - * The height of the canvas view - * - * @property height - * @type Number - * @default 600 - */ - this.height = height || 600; - - /** - * The canvas element that the everything is drawn to - * - * @property view - * @type Canvas - */ - this.view = view || document.createElement( 'canvas' ); - - /** - * The canvas context that the everything is drawn to - * @property context - * @type Canvas 2d Context - */ - this.context = this.view.getContext("2d"); - - this.refresh = true; - // hack to enable some hardware acceleration! - //this.view.style["transform"] = "translatez(0)"; - - this.view.width = this.width; - this.view.height = this.height; - this.count = 0; -} - -// constructor -PIXI.CanvasRenderer.prototype.constructor = PIXI.CanvasRenderer; - -/** - * Renders the stage to its canvas view - * - * @method render - * @param stage {Stage} the Stage element to be rendered - */ -PIXI.CanvasRenderer.prototype.render = function(stage) -{ - // update children if need be - - //stage.__childrenAdded = []; - //stage.__childrenRemoved = []; - - // update textures if need be - PIXI.texturesToUpdate = []; - PIXI.texturesToDestroy = []; - - stage.updateTransform(); - - // update the background color - if(this.view.style.backgroundColor!=stage.backgroundColorString && !this.transparent)this.view.style.backgroundColor = stage.backgroundColorString; - - this.context.setTransform(1,0,0,1,0,0); - this.context.clearRect(0, 0, this.width, this.height) - this.renderDisplayObject(stage); - //as - - // run interaction! - if(stage.interactive) - { - //need to add some events! - if(!stage._interactiveEventsAdded) - { - stage._interactiveEventsAdded = true; - stage.interactionManager.setTarget(this); - } - } - - // remove frame updates.. - if(PIXI.Texture.frameUpdates.length > 0) - { - PIXI.Texture.frameUpdates = []; - } - - -} - -/** - * resizes the canvas view to the specified width and height - * - * @method resize - * @param width {Number} the new width of the canvas view - * @param height {Number} the new height of the canvas view - */ -PIXI.CanvasRenderer.prototype.resize = function(width, height) -{ - this.width = width; - this.height = height; - - this.view.width = width; - this.view.height = height; -} - -/** - * Renders a display object - * - * @method renderDisplayObject - * @param displayObject {DisplayObject} The displayObject to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject) -{ - // no loger recurrsive! - var transform; - var context = this.context; - - context.globalCompositeOperation = 'source-over'; - - // one the display object hits this. we can break the loop - var testObject = displayObject.last._iNext; - displayObject = displayObject.first; - - do - { - transform = displayObject.worldTransform; - - if(!displayObject.visible) - { - displayObject = displayObject.last._iNext; - continue; - } - - if(!displayObject.renderable) - { - displayObject = displayObject._iNext; - continue; - } - - if(displayObject instanceof PIXI.Sprite) - { - - var frame = displayObject.texture.frame; - - if(frame) - { - context.globalAlpha = displayObject.worldAlpha; - - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]); - - context.drawImage(displayObject.texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, - (displayObject.anchor.x) * -frame.width, - (displayObject.anchor.y) * -frame.height, - frame.width, - frame.height); - } - } - else if(displayObject instanceof PIXI.Strip) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - this.renderStrip(displayObject); - } - else if(displayObject instanceof PIXI.TilingSprite) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - this.renderTilingSprite(displayObject); - } - else if(displayObject instanceof PIXI.CustomRenderable) - { - displayObject.renderCanvas(this); - } - else if(displayObject instanceof PIXI.Graphics) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - PIXI.CanvasGraphics.renderGraphics(displayObject, context); - } - else if(displayObject instanceof PIXI.FilterBlock) - { - if(displayObject.open) - { - context.save(); - - var cacheAlpha = displayObject.mask.alpha; - var maskTransform = displayObject.mask.worldTransform; - - context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5]) - - displayObject.mask.worldAlpha = 0.5; - - context.worldAlpha = 0; - - PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, context); - // context.fillStyle = 0xFF0000; - // context.fillRect(0, 0, 200, 200); - context.clip(); - - displayObject.mask.worldAlpha = cacheAlpha; - //context.globalCompositeOperation = 'lighter'; - } - else - { - //context.globalCompositeOperation = 'source-over'; - context.restore(); - } - } - // count++ - displayObject = displayObject._iNext; - - - } - while(displayObject != testObject) - - -} - -/** - * Renders a flat strip - * - * @method renderStripFlat - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip) -{ - var context = this.context; - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - - context.beginPath(); - for (var i=1; i < length-2; i++) - { - - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - - }; - - context.fillStyle = "#FF0000"; - context.fill(); - context.closePath(); -} - -/** - * Renders a tiling sprite - * - * @method renderTilingSprite - * @param sprite {TilingSprite} The tilingsprite to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderTilingSprite = function(sprite) -{ - var context = this.context; - - context.globalAlpha = sprite.worldAlpha; - - if(!sprite.__tilePattern) sprite.__tilePattern = context.createPattern(sprite.texture.baseTexture.source, "repeat"); - - context.beginPath(); - - var tilePosition = sprite.tilePosition; - var tileScale = sprite.tileScale; - - // offset - context.scale(tileScale.x,tileScale.y); - context.translate(tilePosition.x, tilePosition.y); - - context.fillStyle = sprite.__tilePattern; - context.fillRect(-tilePosition.x,-tilePosition.y,sprite.width / tileScale.x, sprite.height / tileScale.y); - - context.scale(1/tileScale.x, 1/tileScale.y); - context.translate(-tilePosition.x, -tilePosition.y); - - context.closePath(); -} - -/** - * Renders a strip - * - * @method renderStrip - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStrip = function(strip) -{ - var context = this.context; - //context.globalCompositeOperation = 'lighter'; - // draw triangles!! - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - for (var i=1; i < length-2; i++) - { - - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; - var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height; - - - context.save(); - context.beginPath(); - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - context.closePath(); - - // context.fillStyle = "white"//rgb(1, 1, 1,1)); - // context.fill(); - context.clip(); - - - // Compute matrix transform - var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2; - var delta_a = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2; - var delta_b = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2; - var delta_c = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2; - var delta_d = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2; - var delta_e = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2; - var delta_f = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2; - - - - - context.transform(delta_a/delta, delta_d/delta, - delta_b/delta, delta_e/delta, - delta_c/delta, delta_f/delta); - - context.drawImage(strip.texture.baseTexture.source, 0, 0); - context.restore(); - }; - -// context.globalCompositeOperation = 'source-over'; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * A set of functions used by the canvas renderer to draw the primitive graphics data - * - * @class CanvasGraphics - */ -PIXI.CanvasGraphics = function() -{ - -} - - -/* - * Renders the graphics object - * - * @static - * @private - * @method renderGraphics - * @param graphics {Graphics} - * @param context {Context2D} - */ -PIXI.CanvasGraphics.renderGraphics = function(graphics, context) -{ - var worldAlpha = graphics.worldAlpha; - - for (var i=0; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - var points = data.points; - - context.strokeStyle = color = '#' + ('00000' + ( data.lineColor | 0).toString(16)).substr(-6); - - context.lineWidth = data.lineWidth; - - if(data.type == PIXI.Graphics.POLY) - { - //if(data.lineWidth <= 0)continue; - - context.beginPath(); - - context.moveTo(points[0], points[1]); - - for (var j=1; j < points.length/2; j++) - { - context.lineTo(points[j * 2], points[j * 2 + 1]); - } - - // if the first and last point are the same close the path - much neater :) - if(points[0] == points[points.length-2] && points[1] == points[points.length-1]) - { - context.closePath(); - } - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - else if(data.type == PIXI.Graphics.RECT) - { - - // TODO - need to be Undefined! - if(data.fillColor) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fillRect(points[0], points[1], points[2], points[3]); - - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.strokeRect(points[0], points[1], points[2], points[3]); - } - - } - else if(data.type == PIXI.Graphics.CIRC) - { - // TODO - need to be Undefined! - context.beginPath(); - context.arc(points[0], points[1], points[2],0,2*Math.PI); - context.closePath(); - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - else if(data.type == PIXI.Graphics.ELIP) - { - - // elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - - var elipseData = data.points; - - var w = elipseData[2] * 2; - var h = elipseData[3] * 2; - - var x = elipseData[0] - w/2; - var y = elipseData[1] - h/2; - - context.beginPath(); - - var kappa = .5522848, - ox = (w / 2) * kappa, // control point offset horizontal - oy = (h / 2) * kappa, // control point offset vertical - xe = x + w, // x-end - ye = y + h, // y-end - xm = x + w / 2, // x-middle - ym = y + h / 2; // y-middle - - context.moveTo(x, ym); - context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - - context.closePath(); - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - - }; -} - -/* - * Renders a graphics mask - * - * @static - * @private - * @method renderGraphicsMask - * @param graphics {Graphics} - * @param context {Context2D} - */ -PIXI.CanvasGraphics.renderGraphicsMask = function(graphics, context) -{ - var worldAlpha = graphics.worldAlpha; - - var len = graphics.graphicsData.length; - if(len > 1) - { - len = 1; - console.log("Pixi.js warning: masks in canvas can only mask using the first path in the graphics object") - } - - for (var i=0; i < 1; i++) - { - var data = graphics.graphicsData[i]; - var points = data.points; - - if(data.type == PIXI.Graphics.POLY) - { - //if(data.lineWidth <= 0)continue; - - context.beginPath(); - context.moveTo(points[0], points[1]); - - for (var j=1; j < points.length/2; j++) - { - context.lineTo(points[j * 2], points[j * 2 + 1]); - } - - // if the first and last point are the same close the path - much neater :) - if(points[0] == points[points.length-2] && points[1] == points[points.length-1]) - { - context.closePath(); - } - - } - else if(data.type == PIXI.Graphics.RECT) - { - context.beginPath(); - context.rect(points[0], points[1], points[2], points[3]); - context.closePath(); - } - else if(data.type == PIXI.Graphics.CIRC) - { - // TODO - need to be Undefined! - context.beginPath(); - context.arc(points[0], points[1], points[2],0,2*Math.PI); - context.closePath(); - } - else if(data.type == PIXI.Graphics.ELIP) - { - - // elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - var elipseData = data.points; - - var w = elipseData[2] * 2; - var h = elipseData[3] * 2; - - var x = elipseData[0] - w/2; - var y = elipseData[1] - h/2; - - context.beginPath(); - - var kappa = .5522848, - ox = (w / 2) * kappa, // control point offset horizontal - oy = (h / 2) * kappa, // control point offset vertical - xe = x + w, // x-end - ye = y + h, // y-end - xm = x + w / 2, // x-middle - ym = y + h / 2; // y-middle - - context.moveTo(x, ym); - context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - context.closePath(); - } - - - }; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * The Graphics class contains a set of methods that you can use to create primitive shapes and lines. - * It is important to know that with the webGL renderer only simple polys can be filled at this stage - * Complex polys will not be filled. Heres an example of a complex poly: http://www.goodboydigital.com/wp-content/uploads/2013/06/complexPolygon.png - * - * @class Graphics - * @extends DisplayObjectContainer - * @constructor - */ -PIXI.Graphics = function() -{ - PIXI.DisplayObjectContainer.call( this ); - - this.renderable = true; - - /** - * The alpha of the fill of this graphics object - * - * @property fillAlpha - * @type Number - */ - this.fillAlpha = 1; - - /** - * The width of any lines drawn - * - * @property lineWidth - * @type Number - */ - this.lineWidth = 0; - - /** - * The color of any lines drawn - * - * @property lineColor - * @type String - */ - this.lineColor = "black"; - - /** - * Graphics data - * - * @property graphicsData - * @type Array - * @private - */ - this.graphicsData = []; - - /** - * Current path - * - * @property currentPath - * @type Object - * @private - */ - this.currentPath = {points:[]}; -} - -// constructor -PIXI.Graphics.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Graphics.prototype.constructor = PIXI.Graphics; - -/** - * Specifies a line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method. - * - * @method lineStyle - * @param lineWidth {Number} width of the line to draw, will update the object's stored style - * @param color {Number} color of the line to draw, will update the object's stored style - * @param alpha {Number} alpha of the line to draw, will update the object's stored style - */ -PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.lineWidth = lineWidth || 0; - this.lineColor = color || 0; - this.lineAlpha = (alpha == undefined) ? 1 : alpha; - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; - - this.graphicsData.push(this.currentPath); -} - -/** - * Moves the current drawing position to (x, y). - * - * @method moveTo - * @param x {Number} the X coord to move to - * @param y {Number} the Y coord to move to - */ -PIXI.Graphics.prototype.moveTo = function(x, y) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; - - this.currentPath.points.push(x, y); - - this.graphicsData.push(this.currentPath); -} - -/** - * Draws a line using the current line style from the current drawing position to (x, y); - * the current drawing position is then set to (x, y). - * - * @method lineTo - * @param x {Number} the X coord to draw to - * @param y {Number} the Y coord to draw to - */ -PIXI.Graphics.prototype.lineTo = function(x, y) -{ - this.currentPath.points.push(x, y); - this.dirty = true; -} - -/** - * Specifies a simple one-color fill that subsequent calls to other Graphics methods - * (such as lineTo() or drawCircle()) use when drawing. - * - * @method beginFill - * @param color {uint} the color of the fill - * @param alpha {Number} the alpha - */ -PIXI.Graphics.prototype.beginFill = function(color, alpha) -{ - this.filling = true; - this.fillColor = color || 0; - this.fillAlpha = alpha || 1; -} - -/** - * Applies a fill to the lines and shapes that were added since the last call to the beginFill() method. - * - * @method endFill - */ -PIXI.Graphics.prototype.endFill = function() -{ - this.filling = false; - this.fillColor = null; - this.fillAlpha = 1; -} - -/** - * @method drawRect - * - * @param x {Number} The X coord of the top-left of the rectangle - * @param y {Number} The Y coord of the top-left of the rectangle - * @param width {Number} The width of the rectangle - * @param height {Number} The height of the rectangle - */ -PIXI.Graphics.prototype.drawRect = function( x, y, width, height ) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, width, height], type:PIXI.Graphics.RECT}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Draws a circle. - * - * @method drawCircle - * @param x {Number} The X coord of the center of the circle - * @param y {Number} The Y coord of the center of the circle - * @param radius {Number} The radius of the circle - */ -PIXI.Graphics.prototype.drawCircle = function( x, y, radius) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, radius, radius], type:PIXI.Graphics.CIRC}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Draws an elipse. - * - * @method drawElipse - * @param x {Number} - * @param y {Number} - * @param width {Number} - * @param height {Number} - */ -PIXI.Graphics.prototype.drawElipse = function( x, y, width, height) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, width, height], type:PIXI.Graphics.ELIP}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings. - * - * @method clear - */ -PIXI.Graphics.prototype.clear = function() -{ - this.lineWidth = 0; - this.filling = false; - - this.dirty = true; - this.clearDirty = true; - this.graphicsData = []; -} - -// SOME TYPES: -PIXI.Graphics.POLY = 0; -PIXI.Graphics.RECT = 1; -PIXI.Graphics.CIRC = 2; -PIXI.Graphics.ELIP = 3; - -/** - * @author Mat Groves http://matgroves.com/ - */ - -PIXI.Strip = function(texture, width, height) -{ - PIXI.DisplayObjectContainer.call( this ); - this.texture = texture; - this.blendMode = PIXI.blendModes.NORMAL; - - try - { - this.uvs = new Float32Array([0, 1, - 1, 1, - 1, 0, 0,1]); - - this.verticies = new Float32Array([0, 0, - 0,0, - 0,0, 0, - 0, 0]); - - this.colors = new Float32Array([1, 1, 1, 1]); - - this.indices = new Uint16Array([0, 1, 2, 3]); - } - catch(error) - { - this.uvs = [0, 1, - 1, 1, - 1, 0, 0,1]; - - this.verticies = [0, 0, - 0,0, - 0,0, 0, - 0, 0]; - - this.colors = [1, 1, 1, 1]; - - this.indices = [0, 1, 2, 3]; - } - - - /* - this.uvs = new Float32Array() - this.verticies = new Float32Array() - this.colors = new Float32Array() - this.indices = new Uint16Array() -*/ - this.width = width; - this.height = height; - - // load the texture! - if(texture.baseTexture.hasLoaded) - { - this.width = this.texture.frame.width; - this.height = this.texture.frame.height; - this.updateFrame = true; - } - else - { - this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); - } - - this.renderable = true; -} - -// constructor -PIXI.Strip.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Strip.prototype.constructor = PIXI.Strip; - -PIXI.Strip.prototype.setTexture = function(texture) -{ - //TODO SET THE TEXTURES - //TODO VISIBILITY - - // stop current texture - this.texture = texture; - this.width = texture.frame.width; - this.height = texture.frame.height; - this.updateFrame = true; -} - -PIXI.Strip.prototype.onTextureUpdate = function(event) -{ - this.updateFrame = true; -} -// some helper functions.. - - -/** - * @author Mat Groves http://matgroves.com/ - */ - - -PIXI.Rope = function(texture, points) -{ - PIXI.Strip.call( this, texture ); - this.points = points; - - try - { - this.verticies = new Float32Array( points.length * 4); - this.uvs = new Float32Array( points.length * 4); - this.colors = new Float32Array( points.length * 2); - this.indices = new Uint16Array( points.length * 2); - } - catch(error) - { - this.verticies = verticies - - this.uvs = uvs - this.colors = colors - this.indices = indices - } - - this.refresh(); -} - - -// constructor -PIXI.Rope.prototype = Object.create( PIXI.Strip.prototype ); -PIXI.Rope.prototype.constructor = PIXI.Rope; - -PIXI.Rope.prototype.refresh = function() -{ - var points = this.points; - if(points.length < 1)return; - - var uvs = this.uvs - var indices = this.indices; - var colors = this.colors; - - var lastPoint = points[0]; - var nextPoint; - var perp = {x:0, y:0}; - var point = points[0]; - - this.count-=0.2; - - - uvs[0] = 0 - uvs[1] = 1 - uvs[2] = 0 - uvs[3] = 1 - - colors[0] = 1; - colors[1] = 1; - - indices[0] = 0; - indices[1] = 1; - - var total = points.length; - - for (var i = 1; i < total; i++) - { - - var point = points[i]; - var index = i * 4; - // time to do some smart drawing! - var amount = i/(total-1) - - if(i%2) - { - uvs[index] = amount; - uvs[index+1] = 0; - - uvs[index+2] = amount - uvs[index+3] = 1 - - } - else - { - uvs[index] = amount - uvs[index+1] = 0 - - uvs[index+2] = amount - uvs[index+3] = 1 - } - - index = i * 2; - colors[index] = 1; - colors[index+1] = 1; - - index = i * 2; - indices[index] = index; - indices[index + 1] = index + 1; - - lastPoint = point; - } -} - -PIXI.Rope.prototype.updateTransform = function() -{ - - var points = this.points; - if(points.length < 1)return; - - var verticies = this.verticies - - var lastPoint = points[0]; - var nextPoint; - var perp = {x:0, y:0}; - var point = points[0]; - - this.count-=0.2; - - verticies[0] = point.x + perp.x - verticies[1] = point.y + perp.y //+ 200 - verticies[2] = point.x - perp.x - verticies[3] = point.y - perp.y//+200 - // time to do some smart drawing! - - var total = points.length; - - for (var i = 1; i < total; i++) - { - - var point = points[i]; - var index = i * 4; - - if(i < points.length-1) - { - nextPoint = points[i+1]; - } - else - { - nextPoint = point - } - - perp.y = -(nextPoint.x - lastPoint.x); - perp.x = nextPoint.y - lastPoint.y; - - var ratio = (1 - (i / (total-1))) * 10; - if(ratio > 1)ratio = 1; - - var perpLength = Math.sqrt(perp.x * perp.x + perp.y * perp.y); - var num = this.texture.height/2//(20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio; - perp.x /= perpLength; - perp.y /= perpLength; - - perp.x *= num; - perp.y *= num; - - verticies[index] = point.x + perp.x - verticies[index+1] = point.y + perp.y - verticies[index+2] = point.x - perp.x - verticies[index+3] = point.y - perp.y - - lastPoint = point; - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call( this ); -} - -PIXI.Rope.prototype.setTexture = function(texture) -{ - // stop current texture - this.texture = texture; - this.updateFrame = true; -} - - - - - -/** - * @author Mat Groves http://matgroves.com/ - */ - -/** - * A tiling sprite is a fast way of rendering a tiling image - * - * @class TilingSprite - * @extends DisplayObjectContainer - * @constructor - * @param texture {Texture} the texture of the tiling sprite - * @param width {Number} the width of the tiling sprite - * @param height {Number} the height of the tiling sprite - */ -PIXI.TilingSprite = function(texture, width, height) -{ - PIXI.DisplayObjectContainer.call( this ); - - /** - * The texture that the sprite is using - * - * @property texture - * @type Texture - */ - this.texture = texture; - - /** - * The width of the tiling sprite - * - * @property width - * @type Number - */ - this.width = width; - - /** - * The height of the tiling sprite - * - * @property height - * @type Number - */ - this.height = height; - - /** - * The scaling of the image that is being tiled - * - * @property tileScale - * @type Point - */ - this.tileScale = new PIXI.Point(1,1); - - /** - * The offset position of the image that is being tiled - * - * @property tilePosition - * @type Point - */ - this.tilePosition = new PIXI.Point(0,0); - - this.renderable = true; - - this.blendMode = PIXI.blendModes.NORMAL -} - -// constructor -PIXI.TilingSprite.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.TilingSprite.prototype.constructor = PIXI.TilingSprite; - -/** - * Sets the texture of the tiling sprite - * - * @method setTexture - * @param texture {Texture} The PIXI texture that is displayed by the sprite - */ -PIXI.TilingSprite.prototype.setTexture = function(texture) -{ - //TODO SET THE TEXTURES - //TODO VISIBILITY - - // stop current texture - this.texture = texture; - this.updateFrame = true; -} - -/** - * When the texture is updated, this event will fire to update the frame - * - * @method onTextureUpdate - * @param event - * @private - */ -PIXI.TilingSprite.prototype.onTextureUpdate = function(event) -{ - this.updateFrame = true; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi - * - * Awesome JS run time provided by EsotericSoftware - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -/** - * A class that enables the you to import and run your spine animations in pixi. - * Spine animation data needs to be loaded using the PIXI.AssetLoader or PIXI.SpineLoader before it can be used by this class - * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source - * - * @class Spine - * @extends DisplayObjectContainer - * @constructor - * @param url {String} The url of the spine anim file to be used - */ -PIXI.Spine = function(url) -{ - PIXI.DisplayObjectContainer.call(this); - - this.spineData = PIXI.AnimCache[url]; - - if(!this.spineData) - { - throw new Error("Spine data must be preloaded using PIXI.SpineLoader or PIXI.AssetLoader: " + url); - return; - } - - this.count = 0; - - this.sprites = []; - - this.skeleton = new spine.Skeleton(this.spineData); - this.skeleton.updateWorldTransform(); - - this.stateData = new spine.AnimationStateData(this.spineData); - this.state = new spine.AnimationState(this.stateData); - - // add the sprites.. - for (var i = 0; i < this.skeleton.drawOrder.length; i++) { - - var attachmentName = this.skeleton.drawOrder[i].data.attachmentName; - - // kind of an assumtion here. that its a png - if(!PIXI.TextureCache[attachmentName]) - { - attachmentName += ".png"; - } - - - var sprite = new PIXI.Sprite(PIXI.Texture.fromFrame(attachmentName)); - sprite.anchor.x = sprite.anchor.y = 0.5; - this.addChild(sprite); - this.sprites.push(sprite); - }; -} - -PIXI.Spine.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Spine.prototype.constructor = PIXI.Spine; - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.Spine.prototype.updateTransform = function() -{ - // TODO should make this time based really.. - this.state.update(1/60); - this.state.apply(this.skeleton); - this.skeleton.updateWorldTransform(); - - - for (var i = 0; i < this.skeleton.drawOrder.length; i++) - { - var slot = this.skeleton.drawOrder[i]; - - var x = slot.bone.worldX + slot.attachment.x * slot.bone.m00 + slot.attachment.y * slot.bone.m01 + slot.attachment.width * 0.5; - var y = slot.bone.worldY + slot.attachment.x * slot.bone.m10 + slot.attachment.y * slot.bone.m11 + slot.attachment.height * 0.5; - //console.log(x + ' : ' + y); - - - //console.log(slot.attachment.name) - if(slot.cacheName != slot.attachment.name) - { - var attachmentName = slot.attachment.name; - - if(!PIXI.TextureCache[attachmentName]) - { - attachmentName += ".png"; - } - - this.sprites[i].setTexture(PIXI.TextureCache[attachmentName]); - - slot.cacheName = slot.attachment.name; - } - - x += -((slot.attachment.width * (slot.bone.worldScaleX + slot.attachment.scaleX - 1))>>1); - y += -((slot.attachment.height * (slot.bone.worldScaleY + slot.attachment.scaleY - 1))>>1); - - - this.sprites[i].position.x = x; - this.sprites[i].position.y = y; - this.sprites[i].rotation = (-(slot.bone.worldRotation + slot.attachment.rotation)) * (Math.PI/180); - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call(this); -} - -/* - * Awesome JS run time provided by EsotericSoftware - * - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -var spine = {}; - -spine.BoneData = function (name, parent) { - this.name = name; - this.parent = parent; -}; -spine.BoneData.prototype = { - length: 0, - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1 -}; - -spine.SlotData = function (name, boneData) { - this.name = name; - this.boneData = boneData; -}; -spine.SlotData.prototype = { - r: 1, g: 1, b: 1, a: 1, - attachmentName: null -}; - -spine.Bone = function (boneData, parent) { - this.data = boneData; - this.parent = parent; - this.setToSetupPose(); -}; -spine.Bone.yDown = false; -spine.Bone.prototype = { - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1, - m00: 0, m01: 0, worldX: 0, // a b x - m10: 0, m11: 0, worldY: 0, // c d y - worldRotation: 0, - worldScaleX: 1, worldScaleY: 1, - updateWorldTransform: function (flipX, flipY) { - var parent = this.parent; - if (parent != null) { - this.worldX = this.x * parent.m00 + this.y * parent.m01 + parent.worldX; - this.worldY = this.x * parent.m10 + this.y * parent.m11 + parent.worldY; - this.worldScaleX = parent.worldScaleX * this.scaleX; - this.worldScaleY = parent.worldScaleY * this.scaleY; - this.worldRotation = parent.worldRotation + this.rotation; - } else { - this.worldX = this.x; - this.worldY = this.y; - this.worldScaleX = this.scaleX; - this.worldScaleY = this.scaleY; - this.worldRotation = this.rotation; - } - var radians = this.worldRotation * Math.PI / 180; - var cos = Math.cos(radians); - var sin = Math.sin(radians); - this.m00 = cos * this.worldScaleX; - this.m10 = sin * this.worldScaleX; - this.m01 = -sin * this.worldScaleY; - this.m11 = cos * this.worldScaleY; - if (flipX) { - this.m00 = -this.m00; - this.m01 = -this.m01; - } - if (flipY) { - this.m10 = -this.m10; - this.m11 = -this.m11; - } - if (spine.Bone.yDown) { - this.m10 = -this.m10; - this.m11 = -this.m11; - } - }, - setToSetupPose: function () { - var data = this.data; - this.x = data.x; - this.y = data.y; - this.rotation = data.rotation; - this.scaleX = data.scaleX; - this.scaleY = data.scaleY; - } -}; - -spine.Slot = function (slotData, skeleton, bone) { - this.data = slotData; - this.skeleton = skeleton; - this.bone = bone; - this.setToSetupPose(); -}; -spine.Slot.prototype = { - r: 1, g: 1, b: 1, a: 1, - _attachmentTime: 0, - attachment: null, - setAttachment: function (attachment) { - this.attachment = attachment; - this._attachmentTime = this.skeleton.time; - }, - setAttachmentTime: function (time) { - this._attachmentTime = this.skeleton.time - time; - }, - getAttachmentTime: function () { - return this.skeleton.time - this._attachmentTime; - }, - setToSetupPose: function () { - var data = this.data; - this.r = data.r; - this.g = data.g; - this.b = data.b; - this.a = data.a; - - var slotDatas = this.skeleton.data.slots; - for (var i = 0, n = slotDatas.length; i < n; i++) { - if (slotDatas[i] == data) { - this.setAttachment(!data.attachmentName ? null : this.skeleton.getAttachmentBySlotIndex(i, data.attachmentName)); - break; - } - } - } -}; - -spine.Skin = function (name) { - this.name = name; - this.attachments = {}; -}; -spine.Skin.prototype = { - addAttachment: function (slotIndex, name, attachment) { - this.attachments[slotIndex + ":" + name] = attachment; - }, - getAttachment: function (slotIndex, name) { - return this.attachments[slotIndex + ":" + name]; - }, - _attachAll: function (skeleton, oldSkin) { - for (var key in oldSkin.attachments) { - var colon = key.indexOf(":"); - var slotIndex = parseInt(key.substring(0, colon)); - var name = key.substring(colon + 1); - var slot = skeleton.slots[slotIndex]; - if (slot.attachment && slot.attachment.name == name) { - var attachment = this.getAttachment(slotIndex, name); - if (attachment) slot.setAttachment(attachment); - } - } - } -}; - -spine.Animation = function (name, timelines, duration) { - this.name = name; - this.timelines = timelines; - this.duration = duration; -}; -spine.Animation.prototype = { - apply: function (skeleton, time, loop) { - if (loop && this.duration != 0) time %= this.duration; - var timelines = this.timelines; - for (var i = 0, n = timelines.length; i < n; i++) - timelines[i].apply(skeleton, time, 1); - }, - mix: function (skeleton, time, loop, alpha) { - if (loop && this.duration != 0) time %= this.duration; - var timelines = this.timelines; - for (var i = 0, n = timelines.length; i < n; i++) - timelines[i].apply(skeleton, time, alpha); - } -}; - -spine.binarySearch = function (values, target, step) { - var low = 0; - var high = Math.floor(values.length / step) - 2; - if (high == 0) return step; - var current = high >>> 1; - while (true) { - if (values[(current + 1) * step] <= target) - low = current + 1; - else - high = current; - if (low == high) return (low + 1) * step; - current = (low + high) >>> 1; - } -}; -spine.linearSearch = function (values, target, step) { - for (var i = 0, last = values.length - step; i <= last; i += step) - if (values[i] > target) return i; - return -1; -}; - -spine.Curves = function (frameCount) { - this.curves = []; // dfx, dfy, ddfx, ddfy, dddfx, dddfy, ... - this.curves.length = (frameCount - 1) * 6; -}; -spine.Curves.prototype = { - setLinear: function (frameIndex) { - this.curves[frameIndex * 6] = 0/*LINEAR*/; - }, - setStepped: function (frameIndex) { - this.curves[frameIndex * 6] = -1/*STEPPED*/; - }, - /** Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next. - * cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of - * the difference between the keyframe's values. */ - setCurve: function (frameIndex, cx1, cy1, cx2, cy2) { - var subdiv_step = 1 / 10/*BEZIER_SEGMENTS*/; - var subdiv_step2 = subdiv_step * subdiv_step; - var subdiv_step3 = subdiv_step2 * subdiv_step; - var pre1 = 3 * subdiv_step; - var pre2 = 3 * subdiv_step2; - var pre4 = 6 * subdiv_step2; - var pre5 = 6 * subdiv_step3; - var tmp1x = -cx1 * 2 + cx2; - var tmp1y = -cy1 * 2 + cy2; - var tmp2x = (cx1 - cx2) * 3 + 1; - var tmp2y = (cy1 - cy2) * 3 + 1; - var i = frameIndex * 6; - var curves = this.curves; - curves[i] = cx1 * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3; - curves[i + 1] = cy1 * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3; - curves[i + 2] = tmp1x * pre4 + tmp2x * pre5; - curves[i + 3] = tmp1y * pre4 + tmp2y * pre5; - curves[i + 4] = tmp2x * pre5; - curves[i + 5] = tmp2y * pre5; - }, - getCurvePercent: function (frameIndex, percent) { - percent = percent < 0 ? 0 : (percent > 1 ? 1 : percent); - var curveIndex = frameIndex * 6; - var curves = this.curves; - var dfx = curves[curveIndex]; - if (!dfx/*LINEAR*/) return percent; - if (dfx == -1/*STEPPED*/) return 0; - var dfy = curves[curveIndex + 1]; - var ddfx = curves[curveIndex + 2]; - var ddfy = curves[curveIndex + 3]; - var dddfx = curves[curveIndex + 4]; - var dddfy = curves[curveIndex + 5]; - var x = dfx, y = dfy; - var i = 10/*BEZIER_SEGMENTS*/ - 2; - while (true) { - if (x >= percent) { - var lastX = x - dfx; - var lastY = y - dfy; - return lastY + (y - lastY) * (percent - lastX) / (x - lastX); - } - if (i == 0) break; - i--; - dfx += ddfx; - dfy += ddfy; - ddfx += dddfx; - ddfy += dddfy; - x += dfx; - y += dfy; - } - return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1. - } -}; - -spine.RotateTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, angle, ... - this.frames.length = frameCount * 2; -}; -spine.RotateTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, angle) { - frameIndex *= 2; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = angle; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 2]) { // Time is after last frame. - var amount = bone.data.rotation + frames[frames.length - 1] - bone.rotation; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - bone.rotation += amount * alpha; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 2); - var lastFrameValue = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex - 2/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 2 - 1, percent); - - var amount = frames[frameIndex + 1/*FRAME_VALUE*/] - lastFrameValue; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - amount = bone.data.rotation + (lastFrameValue + amount * percent) - bone.rotation; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - bone.rotation += amount * alpha; - } -}; - -spine.TranslateTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, x, y, ... - this.frames.length = frameCount * 3; -}; -spine.TranslateTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 3; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 3; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = x; - this.frames[frameIndex + 2] = y; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 3]) { // Time is after last frame. - bone.x += (bone.data.x + frames[frames.length - 2] - bone.x) * alpha; - bone.y += (bone.data.y + frames[frames.length - 1] - bone.y) * alpha; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 3); - var lastFrameX = frames[frameIndex - 2]; - var lastFrameY = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent); - bone.x += (bone.data.x + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.x) * alpha; - bone.y += (bone.data.y + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.y) * alpha; - } -}; - -spine.ScaleTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, x, y, ... - this.frames.length = frameCount * 3; -}; -spine.ScaleTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 3; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 3; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = x; - this.frames[frameIndex + 2] = y; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 3]) { // Time is after last frame. - bone.scaleX += (bone.data.scaleX - 1 + frames[frames.length - 2] - bone.scaleX) * alpha; - bone.scaleY += (bone.data.scaleY - 1 + frames[frames.length - 1] - bone.scaleY) * alpha; - - - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 3); - var lastFrameX = frames[frameIndex - 2]; - var lastFrameY = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent); - - bone.scaleX += (bone.data.scaleX - 1 + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.scaleX) * alpha; - bone.scaleY += (bone.data.scaleY - 1 + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.scaleY) * alpha; - } -}; - -spine.ColorTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, r, g, b, a, ... - this.frames.length = frameCount * 5; -}; -spine.ColorTimeline.prototype = { - slotIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 5; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = r; - this.frames[frameIndex + 2] = g; - this.frames[frameIndex + 3] = b; - this.frames[frameIndex + 4] = a; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - var slot = skeleton.slots[this.slotIndex]; - - if (time >= frames[frames.length - 5]) { // Time is after last frame. - var i = frames.length - 1; - slot.r = frames[i - 3]; - slot.g = frames[i - 2]; - slot.b = frames[i - 1]; - slot.a = frames[i]; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 5); - var lastFrameR = frames[frameIndex - 4]; - var lastFrameG = frames[frameIndex - 3]; - var lastFrameB = frames[frameIndex - 2]; - var lastFrameA = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex - 5/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 5 - 1, percent); - - var r = lastFrameR + (frames[frameIndex + 1/*FRAME_R*/] - lastFrameR) * percent; - var g = lastFrameG + (frames[frameIndex + 2/*FRAME_G*/] - lastFrameG) * percent; - var b = lastFrameB + (frames[frameIndex + 3/*FRAME_B*/] - lastFrameB) * percent; - var a = lastFrameA + (frames[frameIndex + 4/*FRAME_A*/] - lastFrameA) * percent; - if (alpha < 1) { - slot.r += (r - slot.r) * alpha; - slot.g += (g - slot.g) * alpha; - slot.b += (b - slot.b) * alpha; - slot.a += (a - slot.a) * alpha; - } else { - slot.r = r; - slot.g = g; - slot.b = b; - slot.a = a; - } - } -}; - -spine.AttachmentTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, ... - this.frames.length = frameCount; - this.attachmentNames = []; // time, ... - this.attachmentNames.length = frameCount; -}; -spine.AttachmentTimeline.prototype = { - slotIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, attachmentName) { - this.frames[frameIndex] = time; - this.attachmentNames[frameIndex] = attachmentName; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var frameIndex; - if (time >= frames[frames.length - 1]) // Time is after last frame. - frameIndex = frames.length - 1; - else - frameIndex = spine.binarySearch(frames, time, 1) - 1; - - var attachmentName = this.attachmentNames[frameIndex]; - //console.log(skeleton.slots[this.slotIndex]) - - // change the name! - // skeleton.slots[this.slotIndex].attachmentName = attachmentName; - - skeleton.slots[this.slotIndex].setAttachment(!attachmentName ? null : skeleton.getAttachmentBySlotIndex(this.slotIndex, attachmentName)); - } -}; - -spine.SkeletonData = function () { - this.bones = []; - this.slots = []; - this.skins = []; - this.animations = []; -}; -spine.SkeletonData.prototype = { - defaultSkin: null, - /** @return May be null. */ - findBone: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].name == boneName) return bones[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findBoneIndex: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].name == boneName) return i; - return -1; - }, - /** @return May be null. */ - findSlot: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) { - if (slots[i].name == slotName) return slot[i]; - } - return null; - }, - /** @return -1 if the bone was not found. */ - findSlotIndex: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].name == slotName) return i; - return -1; - }, - /** @return May be null. */ - findSkin: function (skinName) { - var skins = this.skins; - for (var i = 0, n = skins.length; i < n; i++) - if (skins[i].name == skinName) return skins[i]; - return null; - }, - /** @return May be null. */ - findAnimation: function (animationName) { - var animations = this.animations; - for (var i = 0, n = animations.length; i < n; i++) - if (animations[i].name == animationName) return animations[i]; - return null; - } -}; - -spine.Skeleton = function (skeletonData) { - this.data = skeletonData; - - this.bones = []; - for (var i = 0, n = skeletonData.bones.length; i < n; i++) { - var boneData = skeletonData.bones[i]; - var parent = !boneData.parent ? null : this.bones[skeletonData.bones.indexOf(boneData.parent)]; - this.bones.push(new spine.Bone(boneData, parent)); - } - - this.slots = []; - this.drawOrder = []; - for (var i = 0, n = skeletonData.slots.length; i < n; i++) { - var slotData = skeletonData.slots[i]; - var bone = this.bones[skeletonData.bones.indexOf(slotData.boneData)]; - var slot = new spine.Slot(slotData, this, bone); - this.slots.push(slot); - this.drawOrder.push(slot); - } -}; -spine.Skeleton.prototype = { - x: 0, y: 0, - skin: null, - r: 1, g: 1, b: 1, a: 1, - time: 0, - flipX: false, flipY: false, - /** Updates the world transform for each bone. */ - updateWorldTransform: function () { - var flipX = this.flipX; - var flipY = this.flipY; - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - bones[i].updateWorldTransform(flipX, flipY); - }, - /** Sets the bones and slots to their setup pose values. */ - setToSetupPose: function () { - this.setBonesToSetupPose(); - this.setSlotsToSetupPose(); - }, - setBonesToSetupPose: function () { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - bones[i].setToSetupPose(); - }, - setSlotsToSetupPose: function () { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - slots[i].setToSetupPose(i); - }, - /** @return May return null. */ - getRootBone: function () { - return this.bones.length == 0 ? null : this.bones[0]; - }, - /** @return May be null. */ - findBone: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].data.name == boneName) return bones[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findBoneIndex: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].data.name == boneName) return i; - return -1; - }, - /** @return May be null. */ - findSlot: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].data.name == slotName) return slots[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findSlotIndex: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].data.name == slotName) return i; - return -1; - }, - setSkinByName: function (skinName) { - var skin = this.data.findSkin(skinName); - if (!skin) throw "Skin not found: " + skinName; - this.setSkin(skin); - }, - /** Sets the skin used to look up attachments not found in the {@link SkeletonData#getDefaultSkin() default skin}. Attachments - * from the new skin are attached if the corresponding attachment from the old skin was attached. - * @param newSkin May be null. */ - setSkin: function (newSkin) { - if (this.skin && newSkin) newSkin._attachAll(this, this.skin); - this.skin = newSkin; - }, - /** @return May be null. */ - getAttachmentBySlotName: function (slotName, attachmentName) { - return this.getAttachmentBySlotIndex(this.data.findSlotIndex(slotName), attachmentName); - }, - /** @return May be null. */ - getAttachmentBySlotIndex: function (slotIndex, attachmentName) { - if (this.skin) { - var attachment = this.skin.getAttachment(slotIndex, attachmentName); - if (attachment) return attachment; - } - if (this.data.defaultSkin) return this.data.defaultSkin.getAttachment(slotIndex, attachmentName); - return null; - }, - /** @param attachmentName May be null. */ - setAttachment: function (slotName, attachmentName) { - var slots = this.slots; - for (var i = 0, n = slots.size; i < n; i++) { - var slot = slots[i]; - if (slot.data.name == slotName) { - var attachment = null; - if (attachmentName) { - - attachment = this.getAttachment(i, attachmentName); - if (attachment == null) throw "Attachment not found: " + attachmentName + ", for slot: " + slotName; - } - - slot.setAttachment(attachment); - return; - } - } - throw "Slot not found: " + slotName; - }, - update: function (delta) { - time += delta; - } -}; - -spine.AttachmentType = { - region: 0 -}; - -spine.RegionAttachment = function () { - this.offset = []; - this.offset.length = 8; - this.uvs = []; - this.uvs.length = 8; -}; -spine.RegionAttachment.prototype = { - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1, - width: 0, height: 0, - rendererObject: null, - regionOffsetX: 0, regionOffsetY: 0, - regionWidth: 0, regionHeight: 0, - regionOriginalWidth: 0, regionOriginalHeight: 0, - setUVs: function (u, v, u2, v2, rotate) { - var uvs = this.uvs; - if (rotate) { - uvs[2/*X2*/] = u; - uvs[3/*Y2*/] = v2; - uvs[4/*X3*/] = u; - uvs[5/*Y3*/] = v; - uvs[6/*X4*/] = u2; - uvs[7/*Y4*/] = v; - uvs[0/*X1*/] = u2; - uvs[1/*Y1*/] = v2; - } else { - uvs[0/*X1*/] = u; - uvs[1/*Y1*/] = v2; - uvs[2/*X2*/] = u; - uvs[3/*Y2*/] = v; - uvs[4/*X3*/] = u2; - uvs[5/*Y3*/] = v; - uvs[6/*X4*/] = u2; - uvs[7/*Y4*/] = v2; - } - }, - updateOffset: function () { - var regionScaleX = this.width / this.regionOriginalWidth * this.scaleX; - var regionScaleY = this.height / this.regionOriginalHeight * this.scaleY; - var localX = -this.width / 2 * this.scaleX + this.regionOffsetX * regionScaleX; - var localY = -this.height / 2 * this.scaleY + this.regionOffsetY * regionScaleY; - var localX2 = localX + this.regionWidth * regionScaleX; - var localY2 = localY + this.regionHeight * regionScaleY; - var radians = this.rotation * Math.PI / 180; - var cos = Math.cos(radians); - var sin = Math.sin(radians); - var localXCos = localX * cos + this.x; - var localXSin = localX * sin; - var localYCos = localY * cos + this.y; - var localYSin = localY * sin; - var localX2Cos = localX2 * cos + this.x; - var localX2Sin = localX2 * sin; - var localY2Cos = localY2 * cos + this.y; - var localY2Sin = localY2 * sin; - var offset = this.offset; - offset[0/*X1*/] = localXCos - localYSin; - offset[1/*Y1*/] = localYCos + localXSin; - offset[2/*X2*/] = localXCos - localY2Sin; - offset[3/*Y2*/] = localY2Cos + localXSin; - offset[4/*X3*/] = localX2Cos - localY2Sin; - offset[5/*Y3*/] = localY2Cos + localX2Sin; - offset[6/*X4*/] = localX2Cos - localYSin; - offset[7/*Y4*/] = localYCos + localX2Sin; - }, - computeVertices: function (x, y, bone, vertices) { - - x += bone.worldX; - y += bone.worldY; - var m00 = bone.m00; - var m01 = bone.m01; - var m10 = bone.m10; - var m11 = bone.m11; - var offset = this.offset; - vertices[0/*X1*/] = offset[0/*X1*/] * m00 + offset[1/*Y1*/] * m01 + x; - vertices[1/*Y1*/] = offset[0/*X1*/] * m10 + offset[1/*Y1*/] * m11 + y; - vertices[2/*X2*/] = offset[2/*X2*/] * m00 + offset[3/*Y2*/] * m01 + x; - vertices[3/*Y2*/] = offset[2/*X2*/] * m10 + offset[3/*Y2*/] * m11 + y; - vertices[4/*X3*/] = offset[4/*X3*/] * m00 + offset[5/*X3*/] * m01 + x; - vertices[5/*X3*/] = offset[4/*X3*/] * m10 + offset[5/*X3*/] * m11 + y; - vertices[6/*X4*/] = offset[6/*X4*/] * m00 + offset[7/*Y4*/] * m01 + x; - vertices[7/*Y4*/] = offset[6/*X4*/] * m10 + offset[7/*Y4*/] * m11 + y; - } -} - -spine.AnimationStateData = function (skeletonData) { - this.skeletonData = skeletonData; - this.animationToMixTime = {}; -}; -spine.AnimationStateData.prototype = { - setMixByName: function (fromName, toName, duration) { - var from = this.skeletonData.findAnimation(fromName); - if (!from) throw "Animation not found: " + fromName; - var to = this.skeletonData.findAnimation(toName); - if (!to) throw "Animation not found: " + toName; - this.setMix(from, to, duration); - }, - setMix: function (from, to, duration) { - this.animationToMixTime[from.name + ":" + to.name] = duration; - }, - getMix: function (from, to) { - var time = this.animationToMixTime[from.name + ":" + to.name]; - return time ? time : 0; - } -}; - -spine.AnimationState = function (stateData) { - this.data = stateData; - this.queue = []; -}; -spine.AnimationState.prototype = { - current: null, - previous: null, - currentTime: 0, - previousTime: 0, - currentLoop: false, - previousLoop: false, - mixTime: 0, - mixDuration: 0, - update: function (delta) { - this.currentTime += delta; - this.previousTime += delta; - this.mixTime += delta; - - if (this.queue.length > 0) { - var entry = this.queue[0]; - if (this.currentTime >= entry.delay) { - this._setAnimation(entry.animation, entry.loop); - this.queue.shift(); - } - } - }, - apply: function (skeleton) { - if (!this.current) return; - if (this.previous) { - this.previous.apply(skeleton, this.previousTime, this.previousLoop); - var alpha = this.mixTime / this.mixDuration; - if (alpha >= 1) { - alpha = 1; - this.previous = null; - } - this.current.mix(skeleton, this.currentTime, this.currentLoop, alpha); - } else - this.current.apply(skeleton, this.currentTime, this.currentLoop); - }, - clearAnimation: function () { - this.previous = null; - this.current = null; - this.queue.length = 0; - }, - _setAnimation: function (animation, loop) { - this.previous = null; - if (animation && this.current) { - this.mixDuration = this.data.getMix(this.current, animation); - if (this.mixDuration > 0) { - this.mixTime = 0; - this.previous = this.current; - this.previousTime = this.currentTime; - this.previousLoop = this.currentLoop; - } - } - this.current = animation; - this.currentLoop = loop; - this.currentTime = 0; - }, - /** @see #setAnimation(Animation, Boolean) */ - setAnimationByName: function (animationName, loop) { - var animation = this.data.skeletonData.findAnimation(animationName); - if (!animation) throw "Animation not found: " + animationName; - this.setAnimation(animation, loop); - }, - /** Set the current animation. Any queued animations are cleared and the current animation time is set to 0. - * @param animation May be null. */ - setAnimation: function (animation, loop) { - this.queue.length = 0; - this._setAnimation(animation, loop); - }, - /** @see #addAnimation(Animation, Boolean, Number) */ - addAnimationByName: function (animationName, loop, delay) { - var animation = this.data.skeletonData.findAnimation(animationName); - if (!animation) throw "Animation not found: " + animationName; - this.addAnimation(animation, loop, delay); - }, - /** Adds an animation to be played delay seconds after the current or last queued animation. - * @param delay May be <= 0 to use duration of previous animation minus any mix duration plus the negative delay. */ - addAnimation: function (animation, loop, delay) { - var entry = {}; - entry.animation = animation; - entry.loop = loop; - - if (!delay || delay <= 0) { - var previousAnimation = this.queue.length == 0 ? this.current : this.queue[this.queue.length - 1].animation; - if (previousAnimation != null) - delay = previousAnimation.duration - this.data.getMix(previousAnimation, animation) + (delay || 0); - else - delay = 0; - } - entry.delay = delay; - - this.queue.push(entry); - }, - /** Returns true if no animation is set or if the current time is greater than the animation duration, regardless of looping. */ - isComplete: function () { - return !this.current || this.currentTime >= this.current.duration; - } -}; - -spine.SkeletonJson = function (attachmentLoader) { - this.attachmentLoader = attachmentLoader; -}; -spine.SkeletonJson.prototype = { - scale: 1, - readSkeletonData: function (root) { - var skeletonData = new spine.SkeletonData(); - - // Bones. - var bones = root["bones"]; - for (var i = 0, n = bones.length; i < n; i++) { - var boneMap = bones[i]; - var parent = null; - if (boneMap["parent"]) { - parent = skeletonData.findBone(boneMap["parent"]); - if (!parent) throw "Parent bone not found: " + boneMap["parent"]; - } - var boneData = new spine.BoneData(boneMap["name"], parent); - boneData.length = (boneMap["length"] || 0) * this.scale; - boneData.x = (boneMap["x"] || 0) * this.scale; - boneData.y = (boneMap["y"] || 0) * this.scale; - boneData.rotation = (boneMap["rotation"] || 0); - boneData.scaleX = boneMap["scaleX"] || 1; - boneData.scaleY = boneMap["scaleY"] || 1; - skeletonData.bones.push(boneData); - } - - // Slots. - var slots = root["slots"]; - for (var i = 0, n = slots.length; i < n; i++) { - var slotMap = slots[i]; - var boneData = skeletonData.findBone(slotMap["bone"]); - if (!boneData) throw "Slot bone not found: " + slotMap["bone"]; - var slotData = new spine.SlotData(slotMap["name"], boneData); - - var color = slotMap["color"]; - if (color) { - slotData.r = spine.SkeletonJson.toColor(color, 0); - slotData.g = spine.SkeletonJson.toColor(color, 1); - slotData.b = spine.SkeletonJson.toColor(color, 2); - slotData.a = spine.SkeletonJson.toColor(color, 3); - } - - slotData.attachmentName = slotMap["attachment"]; - - skeletonData.slots.push(slotData); - } - - // Skins. - var skins = root["skins"]; - for (var skinName in skins) { - if (!skins.hasOwnProperty(skinName)) continue; - var skinMap = skins[skinName]; - var skin = new spine.Skin(skinName); - for (var slotName in skinMap) { - if (!skinMap.hasOwnProperty(slotName)) continue; - var slotIndex = skeletonData.findSlotIndex(slotName); - var slotEntry = skinMap[slotName]; - for (var attachmentName in slotEntry) { - if (!slotEntry.hasOwnProperty(attachmentName)) continue; - var attachment = this.readAttachment(skin, attachmentName, slotEntry[attachmentName]); - if (attachment != null) skin.addAttachment(slotIndex, attachmentName, attachment); - } - } - skeletonData.skins.push(skin); - if (skin.name == "default") skeletonData.defaultSkin = skin; - } - - // Animations. - var animations = root["animations"]; - for (var animationName in animations) { - if (!animations.hasOwnProperty(animationName)) continue; - this.readAnimation(animationName, animations[animationName], skeletonData); - } - - return skeletonData; - }, - readAttachment: function (skin, name, map) { - name = map["name"] || name; - - var type = spine.AttachmentType[map["type"] || "region"]; - - // @ekelokorpi - // var attachment = this.attachmentLoader.newAttachment(skin, type, name); - var attachment = new spine.RegionAttachment(); - - // @Doormat23 - // add the name of the attachment - attachment.name = name; - - if (type == spine.AttachmentType.region) { - attachment.x = (map["x"] || 0) * this.scale; - attachment.y = (map["y"] || 0) * this.scale; - attachment.scaleX = map["scaleX"] || 1; - attachment.scaleY = map["scaleY"] || 1; - attachment.rotation = map["rotation"] || 0; - attachment.width = (map["width"] || 32) * this.scale; - attachment.height = (map["height"] || 32) * this.scale; - attachment.updateOffset(); - } - - return attachment; - }, - readAnimation: function (name, map, skeletonData) { - var timelines = []; - var duration = 0; - - var bones = map["bones"]; - for (var boneName in bones) { - if (!bones.hasOwnProperty(boneName)) continue; - var boneIndex = skeletonData.findBoneIndex(boneName); - if (boneIndex == -1) throw "Bone not found: " + boneName; - var boneMap = bones[boneName]; - - for (var timelineName in boneMap) { - if (!boneMap.hasOwnProperty(timelineName)) continue; - var values = boneMap[timelineName]; - if (timelineName == "rotate") { - var timeline = new spine.RotateTimeline(values.length); - timeline.boneIndex = boneIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - timeline.setFrame(frameIndex, valueMap["time"], valueMap["angle"]); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 2 - 2]); - - } else if (timelineName == "translate" || timelineName == "scale") { - var timeline; - var timelineScale = 1; - if (timelineName == "scale") - timeline = new spine.ScaleTimeline(values.length); - else { - timeline = new spine.TranslateTimeline(values.length); - timelineScale = this.scale; - } - timeline.boneIndex = boneIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - var x = (valueMap["x"] || 0) * timelineScale; - var y = (valueMap["y"] || 0) * timelineScale; - timeline.setFrame(frameIndex, valueMap["time"], x, y); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 3 - 3]); - - } else - throw "Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")"; - } - } - var slots = map["slots"]; - for (var slotName in slots) { - if (!slots.hasOwnProperty(slotName)) continue; - var slotMap = slots[slotName]; - var slotIndex = skeletonData.findSlotIndex(slotName); - - for (var timelineName in slotMap) { - if (!slotMap.hasOwnProperty(timelineName)) continue; - var values = slotMap[timelineName]; - if (timelineName == "color") { - var timeline = new spine.ColorTimeline(values.length); - timeline.slotIndex = slotIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - var color = valueMap["color"]; - var r = spine.SkeletonJson.toColor(color, 0); - var g = spine.SkeletonJson.toColor(color, 1); - var b = spine.SkeletonJson.toColor(color, 2); - var a = spine.SkeletonJson.toColor(color, 3); - timeline.setFrame(frameIndex, valueMap["time"], r, g, b, a); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 5 - 5]); - - } else if (timelineName == "attachment") { - var timeline = new spine.AttachmentTimeline(values.length); - timeline.slotIndex = slotIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - timeline.setFrame(frameIndex++, valueMap["time"], valueMap["name"]); - } - timelines.push(timeline); - // PIXI FIX - duration = Math.max(duration, timeline.frames[Math.floor(timeline.getFrameCount()) - 1]); - } else - throw "Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")"; - } - } - skeletonData.animations.push(new spine.Animation(name, timelines, duration)); - } -}; -spine.SkeletonJson.readCurve = function (timeline, frameIndex, valueMap) { - var curve = valueMap["curve"]; - if (!curve) return; - if (curve == "stepped") - timeline.curves.setStepped(frameIndex); - else if (curve instanceof Array) - timeline.curves.setCurve(frameIndex, curve[0], curve[1], curve[2], curve[3]); -}; -spine.SkeletonJson.toColor = function (hexString, colorIndex) { - if (hexString.length != 8) throw "Color hexidecimal length must be 8, recieved: " + hexString; - return parseInt(hexString.substring(colorIndex * 2, 2), 16) / 255; -}; - -spine.Atlas = function (atlasText, textureLoader) { - this.textureLoader = textureLoader; - this.pages = []; - this.regions = []; - - var reader = new spine.AtlasReader(atlasText); - var tuple = []; - tuple.length = 4; - var page = null; - while (true) { - var line = reader.readLine(); - if (line == null) break; - line = reader.trim(line); - if (line.length == 0) - page = null; - else if (!page) { - page = new spine.AtlasPage(); - page.name = line; - - page.format = spine.Atlas.Format[reader.readValue()]; - - reader.readTuple(tuple); - page.minFilter = spine.Atlas.TextureFilter[tuple[0]]; - page.magFilter = spine.Atlas.TextureFilter[tuple[1]]; - - var direction = reader.readValue(); - page.uWrap = spine.Atlas.TextureWrap.clampToEdge; - page.vWrap = spine.Atlas.TextureWrap.clampToEdge; - if (direction == "x") - page.uWrap = spine.Atlas.TextureWrap.repeat; - else if (direction == "y") - page.vWrap = spine.Atlas.TextureWrap.repeat; - else if (direction == "xy") - page.uWrap = page.vWrap = spine.Atlas.TextureWrap.repeat; - - textureLoader.load(page, line); - - this.pages.push(page); - - } else { - var region = new spine.AtlasRegion(); - region.name = line; - region.page = page; - - region.rotate = reader.readValue() == "true"; - - reader.readTuple(tuple); - var x = parseInt(tuple[0]); - var y = parseInt(tuple[1]); - - reader.readTuple(tuple); - var width = parseInt(tuple[0]); - var height = parseInt(tuple[1]); - - region.u = x / page.width; - region.v = y / page.height; - if (region.rotate) { - region.u2 = (x + height) / page.width; - region.v2 = (y + width) / page.height; - } else { - region.u2 = (x + width) / page.width; - region.v2 = (y + height) / page.height; - } - region.x = x; - region.y = y; - region.width = Math.abs(width); - region.height = Math.abs(height); - - if (reader.readTuple(tuple) == 4) { // split is optional - region.splits = [parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])]; - - if (reader.readTuple(tuple) == 4) { // pad is optional, but only present with splits - region.pads = [parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])]; - - reader.readTuple(tuple); - } - } - - region.originalWidth = parseInt(tuple[0]); - region.originalHeight = parseInt(tuple[1]); - - reader.readTuple(tuple); - region.offsetX = parseInt(tuple[0]); - region.offsetY = parseInt(tuple[1]); - - region.index = parseInt(reader.readValue()); - - this.regions.push(region); - } - } -}; -spine.Atlas.prototype = { - findRegion: function (name) { - var regions = this.regions; - for (var i = 0, n = regions.length; i < n; i++) - if (regions[i].name == name) return regions[i]; - return null; - }, - dispose: function () { - var pages = this.pages; - for (var i = 0, n = pages.length; i < n; i++) - this.textureLoader.unload(pages[i].rendererObject); - }, - updateUVs: function (page) { - var regions = this.regions; - for (var i = 0, n = regions.length; i < n; i++) { - var region = regions[i]; - if (region.page != page) continue; - region.u = region.x / page.width; - region.v = region.y / page.height; - if (region.rotate) { - region.u2 = (region.x + region.height) / page.width; - region.v2 = (region.y + region.width) / page.height; - } else { - region.u2 = (region.x + region.width) / page.width; - region.v2 = (region.y + region.height) / page.height; - } - } - } -}; - -spine.Atlas.Format = { - alpha: 0, - intensity: 1, - luminanceAlpha: 2, - rgb565: 3, - rgba4444: 4, - rgb888: 5, - rgba8888: 6 -}; - -spine.Atlas.TextureFilter = { - nearest: 0, - linear: 1, - mipMap: 2, - mipMapNearestNearest: 3, - mipMapLinearNearest: 4, - mipMapNearestLinear: 5, - mipMapLinearLinear: 6 -}; - -spine.Atlas.TextureWrap = { - mirroredRepeat: 0, - clampToEdge: 1, - repeat: 2 -}; - -spine.AtlasPage = function () {}; -spine.AtlasPage.prototype = { - name: null, - format: null, - minFilter: null, - magFilter: null, - uWrap: null, - vWrap: null, - rendererObject: null, - width: 0, - height: 0 -}; - -spine.AtlasRegion = function () {}; -spine.AtlasRegion.prototype = { - page: null, - name: null, - x: 0, y: 0, - width: 0, height: 0, - u: 0, v: 0, u2: 0, v2: 0, - offsetX: 0, offsetY: 0, - originalWidth: 0, originalHeight: 0, - index: 0, - rotate: false, - splits: null, - pads: null, -}; - -spine.AtlasReader = function (text) { - this.lines = text.split(/\r\n|\r|\n/); -}; -spine.AtlasReader.prototype = { - index: 0, - trim: function (value) { - return value.replace(/^\s+|\s+$/g, ""); - }, - readLine: function () { - if (this.index >= this.lines.length) return null; - return this.lines[this.index++]; - }, - readValue: function () { - var line = this.readLine(); - var colon = line.indexOf(":"); - if (colon == -1) throw "Invalid line: " + line; - return this.trim(line.substring(colon + 1)); - }, - /** Returns the number of tuple values read (2 or 4). */ - readTuple: function (tuple) { - var line = this.readLine(); - var colon = line.indexOf(":"); - if (colon == -1) throw "Invalid line: " + line; - var i = 0, lastMatch= colon + 1; - for (; i < 3; i++) { - var comma = line.indexOf(",", lastMatch); - if (comma == -1) { - if (i == 0) throw "Invalid line: " + line; - break; - } - tuple[i] = this.trim(line.substr(lastMatch, comma - lastMatch)); - lastMatch = comma + 1; - } - tuple[i] = this.trim(line.substring(lastMatch)); - return i + 1; - } -} - -spine.AtlasAttachmentLoader = function (atlas) { - this.atlas = atlas; -} -spine.AtlasAttachmentLoader.prototype = { - newAttachment: function (skin, type, name) { - switch (type) { - case spine.AttachmentType.region: - var region = this.atlas.findRegion(name); - if (!region) throw "Region not found in atlas: " + name + " (" + type + ")"; - var attachment = new spine.RegionAttachment(name); - attachment.rendererObject = region; - attachment.setUVs(region.u, region.v, region.u2, region.v2, region.rotate); - attachment.regionOffsetX = region.offsetX; - attachment.regionOffsetY = region.offsetY; - attachment.regionWidth = region.width; - attachment.regionHeight = region.height; - attachment.regionOriginalWidth = region.originalWidth; - attachment.regionOriginalHeight = region.originalHeight; - return attachment; - } - throw "Unknown attachment type: " + type; - } -} - -PIXI.AnimCache = {}; -spine.Bone.yDown = true; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * This object is one that will allow you to specify custom rendering functions based on render type - * - * @class CustomRenderable - * @extends DisplayObject - * @constructor - */ -PIXI.CustomRenderable = function() -{ - PIXI.DisplayObject.call( this ); - -} - -// constructor -PIXI.CustomRenderable.prototype = Object.create( PIXI.DisplayObject.prototype ); -PIXI.CustomRenderable.prototype.constructor = PIXI.CustomRenderable; - -/** - * If this object is being rendered by a CanvasRenderer it will call this callback - * - * @method renderCanvas - * @param renderer {CanvasRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.renderCanvas = function(renderer) -{ - // override! -} - -/** - * If this object is being rendered by a WebGLRenderer it will call this callback to initialize - * - * @method initWebGL - * @param renderer {WebGLRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.initWebGL = function(renderer) -{ - // override! -} - -/** - * If this object is being rendered by a WebGLRenderer it will call this callback - * - * @method renderWebGL - * @param renderer {WebGLRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.renderWebGL = function(renderGroup, projectionMatrix) -{ - // not sure if both needed? but ya have for now! - // override! -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI.BaseTextureCache = {}; -PIXI.texturesToUpdate = []; -PIXI.texturesToDestroy = []; - -/** - * A texture stores the information that represents an image. All textures have a base texture - * - * @class BaseTexture - * @uses EventTarget - * @constructor - * @param source {String} the source object (image or canvas) - */ -PIXI.BaseTexture = function(source) -{ - PIXI.EventTarget.call( this ); - - /** - * [read-only] The width of the base texture set when the image has loaded - * - * @property width - * @type Number - * @readOnly - */ - this.width = 100; - - /** - * [read-only] The height of the base texture set when the image has loaded - * - * @property height - * @type Number - * @readOnly - */ - this.height = 100; - - /** - * [read-only] Describes if the base texture has loaded or not - * - * @property hasLoaded - * @type Boolean - * @readOnly - */ - this.hasLoaded = false; - - /** - * The source that is loaded to create the texture - * - * @property source - * @type Image - */ - this.source = source; - - if(!source)return; - - if(this.source instanceof Image || this.source instanceof HTMLImageElement) - { - if(this.source.complete) - { - this.hasLoaded = true; - this.width = this.source.width; - this.height = this.source.height; - - PIXI.texturesToUpdate.push(this); - } - else - { - - var scope = this; - this.source.onload = function(){ - - scope.hasLoaded = true; - scope.width = scope.source.width; - scope.height = scope.source.height; - - // add it to somewhere... - PIXI.texturesToUpdate.push(scope); - scope.dispatchEvent( { type: 'loaded', content: scope } ); - } - // this.image.src = imageUrl; - } - } - else - { - this.hasLoaded = true; - this.width = this.source.width; - this.height = this.source.height; - - PIXI.texturesToUpdate.push(this); - } - - this._powerOf2 = false; -} - -PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; - -/** - * Destroys this base texture - * - * @method destroy - */ -PIXI.BaseTexture.prototype.destroy = function() -{ - if(this.source instanceof Image) - { - this.source.src = null; - } - this.source = null; - PIXI.texturesToDestroy.push(this); -} - -/** - * Helper function that returns a base texture based on an image url - * If the image is not in the base texture cache it will be created and loaded - * - * @static - * @method fromImage - * @param imageUrl {String} The image url of the texture - * @return BaseTexture - */ -PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin) -{ - var baseTexture = PIXI.BaseTextureCache[imageUrl]; - if(!baseTexture) - { - // new Image() breaks tex loading in some versions of Chrome. - // See https://code.google.com/p/chromium/issues/detail?id=238071 - var image = new Image();//document.createElement('img'); - if (crossorigin) - { - image.crossOrigin = ''; - } - image.src = imageUrl; - baseTexture = new PIXI.BaseTexture(image); - PIXI.BaseTextureCache[imageUrl] = baseTexture; - } - - return baseTexture; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI.TextureCache = {}; -PIXI.FrameCache = {}; - -/** - * A texture stores the information that represents an image or part of an image. It cannot be added - * to the display list directly. To do this use PIXI.Sprite. If no frame is provided then the whole image is used - * - * @class Texture - * @uses EventTarget - * @constructor - * @param baseTexture {BaseTexture} The base texture source to create the texture from - * @param frmae {Rectangle} The rectangle frame of the texture to show - */ -PIXI.Texture = function(baseTexture, frame) -{ - PIXI.EventTarget.call( this ); - - if(!frame) - { - this.noFrame = true; - frame = new PIXI.Rectangle(0,0,1,1); - } - - if(baseTexture instanceof PIXI.Texture) - baseTexture = baseTexture.baseTexture; - - /** - * The base texture of this texture - * - * @property baseTexture - * @type BaseTexture - */ - this.baseTexture = baseTexture; - - /** - * The frame specifies the region of the base texture that this texture uses - * - * @property frame - * @type Rectangle - */ - this.frame = frame; - - /** - * The trim point - * - * @property trim - * @type Point - */ - this.trim = new PIXI.Point(); - - this.scope = this; - - if(baseTexture.hasLoaded) - { - if(this.noFrame)frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); - //console.log(frame) - - this.setFrame(frame); - } - else - { - var scope = this; - baseTexture.addEventListener( 'loaded', function(){ scope.onBaseTextureLoaded()} ); - } -} - -PIXI.Texture.prototype.constructor = PIXI.Texture; - -/** - * Called when the base texture is loaded - * - * @method onBaseTextureLoaded - * @param event - * @private - */ -PIXI.Texture.prototype.onBaseTextureLoaded = function(event) -{ - var baseTexture = this.baseTexture; - baseTexture.removeEventListener( 'loaded', this.onLoaded ); - - if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); - this.noFrame = false; - this.width = this.frame.width; - this.height = this.frame.height; - - this.scope.dispatchEvent( { type: 'update', content: this } ); -} - -/** - * Destroys this texture - * - * @method destroy - * @param destroyBase {Boolean} Whether to destroy the base texture as well - */ -PIXI.Texture.prototype.destroy = function(destroyBase) -{ - if(destroyBase)this.baseTexture.destroy(); -} - -/** - * Specifies the rectangle region of the baseTexture - * - * @method setFrame - * @param frame {Rectangle} The frame of the texture to set it to - */ -PIXI.Texture.prototype.setFrame = function(frame) -{ - this.frame = frame; - this.width = frame.width; - this.height = frame.height; - - if(frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error("Texture Error: frame does not fit inside the base Texture dimensions " + this); - } - - this.updateFrame = true; - - PIXI.Texture.frameUpdates.push(this); - //this.dispatchEvent( { type: 'update', content: this } ); -} - -/** - * Helper function that returns a texture based on an image url - * If the image is not in the texture cache it will be created and loaded - * - * @static - * @method fromImage - * @param imageUrl {String} The image url of the texture - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - * @return Texture - */ -PIXI.Texture.fromImage = function(imageUrl, crossorigin) -{ - var texture = PIXI.TextureCache[imageUrl]; - - if(!texture) - { - texture = new PIXI.Texture(PIXI.BaseTexture.fromImage(imageUrl, crossorigin)); - PIXI.TextureCache[imageUrl] = texture; - } - - return texture; -} - -/** - * Helper function that returns a texture based on a frame id - * If the frame id is not in the texture cache an error will be thrown - * - * @static - * @method fromFrame - * @param frameId {String} The frame id of the texture - * @return Texture - */ -PIXI.Texture.fromFrame = function(frameId) -{ - var texture = PIXI.TextureCache[frameId]; - if(!texture)throw new Error("The frameId '"+ frameId +"' does not exist in the texture cache " + this); - return texture; -} - -/** - * Helper function that returns a texture based on a canvas element - * If the canvas is not in the texture cache it will be created and loaded - * - * @static - * @method fromCanvas - * @param canvas {Canvas} The canvas element source of the texture - * @return Texture - */ -PIXI.Texture.fromCanvas = function(canvas) -{ - var baseTexture = new PIXI.BaseTexture(canvas); - return new PIXI.Texture(baseTexture); -} - - -/** - * Adds a texture to the textureCache. - * - * @static - * @method addTextureToCache - * @param texture {Texture} - * @param id {String} the id that the texture will be stored against. - */ -PIXI.Texture.addTextureToCache = function(texture, id) -{ - PIXI.TextureCache[id] = texture; -} - -/** - * Remove a texture from the textureCache. - * - * @static - * @method removeTextureFromCache - * @param id {String} the id of the texture to be removed - * @return {Texture} the texture that was removed - */ -PIXI.Texture.removeTextureFromCache = function(id) -{ - var texture = PIXI.TextureCache[id] - PIXI.TextureCache[id] = null; - return texture; -} - -// this is more for webGL.. it contains updated frames.. -PIXI.Texture.frameUpdates = []; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - A RenderTexture is a special texture that allows any pixi displayObject to be rendered to it. - - __Hint__: All DisplayObjects (exmpl. Sprites) that renders on RenderTexture should be preloaded. - Otherwise black rectangles will be drawn instead. - - RenderTexture takes snapshot of DisplayObject passed to render method. If DisplayObject is passed to render method, position and rotation of it will be ignored. For example: - - var renderTexture = new PIXI.RenderTexture(800, 600); - var sprite = PIXI.Sprite.fromImage("spinObj_01.png"); - sprite.position.x = 800/2; - sprite.position.y = 600/2; - sprite.anchor.x = 0.5; - sprite.anchor.y = 0.5; - renderTexture.render(sprite); - - Sprite in this case will be rendered to 0,0 position. To render this sprite at center DisplayObjectContainer should be used: - - var doc = new PIXI.DisplayObjectContainer(); - doc.addChild(sprite); - renderTexture.render(doc); // Renders to center of renderTexture - - @class RenderTexture - @extends Texture - @constructor - @param width {Number} The width of the render texture - @param height {Number} The height of the render texture - */ -PIXI.RenderTexture = function(width, height) -{ - PIXI.EventTarget.call( this ); - - this.width = width || 100; - this.height = height || 100; - - this.indetityMatrix = PIXI.mat3.create(); - - this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); - - if(PIXI.gl) - { - this.initWebGL(); - } - else - { - this.initCanvas(); - } -} - -PIXI.RenderTexture.prototype = Object.create( PIXI.Texture.prototype ); -PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture; - -/** - * Initializes the webgl data for this texture - * - * @method initWebGL - * @private - */ -PIXI.RenderTexture.prototype.initWebGL = function() -{ - var gl = PIXI.gl; - this.glFramebuffer = gl.createFramebuffer(); - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - - this.glFramebuffer.width = this.width; - this.glFramebuffer.height = this.height; - - this.baseTexture = new PIXI.BaseTexture(); - - this.baseTexture.width = this.width; - this.baseTexture.height = this.height; - - this.baseTexture._glTexture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); - - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - - this.baseTexture.isRender = true; - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0); - - // create a projection matrix.. - this.projection = new PIXI.Point(this.width/2 , this.height/2); -/* - this.projectionMatrix = PIXI.mat4.create(); - - this.projectionMatrix[5] = 2/this.height// * 0.5; - this.projectionMatrix[13] = -1; - - this.projectionMatrix[0] = 2/this.width; - this.projectionMatrix[12] = -1; -*/ - // set the correct render function.. - this.render = this.renderWebGL; - - -} - - -PIXI.RenderTexture.prototype.resize = function(width, height) -{ - - this.width = width; - this.height = height; - - //this.frame.width = this.width - //this.frame.height = this.height; - - - if(PIXI.gl) - { - this.projection.x = this.width/2 - this.projection.y = this.height/2; - - var gl = PIXI.gl; - gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - } - else - { - - this.frame.width = this.width - this.frame.height = this.height; - this.renderer.resize(this.width, this.height); - } -} - -/** - * Initializes the canvas data for this texture - * - * @method initCanvas - * @private - */ -PIXI.RenderTexture.prototype.initCanvas = function() -{ - this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, 0); - - this.baseTexture = new PIXI.BaseTexture(this.renderer.view); - this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); - - this.render = this.renderCanvas; -} - -/** - * This function will draw the display object to the texture. - * - * @method renderWebGL - * @param displayObject {DisplayObject} The display object to render this texture on - * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn - * @private - */ -PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear) -{ - var gl = PIXI.gl; - - // enable the alpha color mask.. - gl.colorMask(true, true, true, true); - - gl.viewport(0, 0, this.width, this.height); - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - - if(clear) - { - gl.clearColor(0,0,0, 0); - gl.clear(gl.COLOR_BUFFER_BIT); - } - - // THIS WILL MESS WITH HIT TESTING! - var children = displayObject.children; - - //TODO -? create a new one??? dont think so! - displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix; - // modify to flip... - displayObject.worldTransform[4] = -1; - displayObject.worldTransform[5] = this.projection.y * 2; - - - if(position) - { - displayObject.worldTransform[2] = position.x; - displayObject.worldTransform[5] -= position.y; - } - - - - for(var i=0,j=children.length; i} assetURLs an array of image/sprite sheet urls that you would like loaded - * supported. Supported image formats include "jpeg", "jpg", "png", "gif". Supported - * sprite sheet data formats only include "JSON" at this time. Supported bitmap font - * data formats include "xml" and "fnt". - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.AssetLoader = function(assetURLs, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The array of asset URLs that are going to be loaded - * - * @property assetURLs - * @type Array - */ - this.assetURLs = assetURLs; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * Maps file extension to loader types - * - * @property loadersByType - * @type Object - */ - this.loadersByType = { - "jpg": PIXI.ImageLoader, - "jpeg": PIXI.ImageLoader, - "png": PIXI.ImageLoader, - "gif": PIXI.ImageLoader, - "json": PIXI.JsonLoader, - "anim": PIXI.SpineLoader, - "xml": PIXI.BitmapFontLoader, - "fnt": PIXI.BitmapFontLoader - }; - - -}; - -/** - * Fired when an item has loaded - * @event onProgress - */ - -/** - * Fired when all the assets have loaded - * @event onComplete - */ - -// constructor -PIXI.AssetLoader.prototype.constructor = PIXI.AssetLoader; - -/** - * Starts loading the assets sequentially - * - * @method load - */ -PIXI.AssetLoader.prototype.load = function() -{ - var scope = this; - - this.loadCount = this.assetURLs.length; - - for (var i=0; i < this.assetURLs.length; i++) - { - var fileName = this.assetURLs[i]; - var fileType = fileName.split(".").pop().toLowerCase(); - - var loaderClass = this.loadersByType[fileType]; - if(!loaderClass) - throw new Error(fileType + " is an unsupported file type"); - - var loader = new loaderClass(fileName, this.crossorigin); - - loader.addEventListener("loaded", function() - { - scope.onAssetLoaded(); - }); - loader.load(); - } -}; - -/** - * Invoked after each file is loaded - * - * @method onAssetLoaded - * @private - */ -PIXI.AssetLoader.prototype.onAssetLoaded = function() -{ - this.loadCount--; - this.dispatchEvent({type: "onProgress", content: this}); - if(this.onProgress) this.onProgress(); - - if(this.loadCount == 0) - { - this.dispatchEvent({type: "onComplete", content: this}); - if(this.onComplete) this.onComplete(); - } -}; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The json file loader is used to load in JSON data and parsing it - * When loaded this class will dispatch a "loaded" event - * If load failed this class will dispatch a "error" event - * - * @class JsonLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.JsonLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * [read-only] Whether the data has loaded yet - * - * @property loaded - * @type Boolean - * @readOnly - */ - this.loaded = false; - -}; - -// constructor -PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader; - -/** - * Loads the JSON data - * - * @method load - */ -PIXI.JsonLoader.prototype.load = function () { - this.ajaxRequest = new AjaxRequest(); - var scope = this; - this.ajaxRequest.onreadystatechange = function () { - scope.onJSONLoaded(); - }; - - this.ajaxRequest.open("GET", this.url, true); - if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json"); - this.ajaxRequest.send(null); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.JsonLoader.prototype.onJSONLoaded = function () { - if (this.ajaxRequest.readyState == 4) { - if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) { - this.json = JSON.parse(this.ajaxRequest.responseText); - - if(this.json.frames) - { - // sprite sheet - var scope = this; - var textureUrl = this.baseUrl + this.json.meta.image; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - var frameData = this.json.frames; - - this.texture = image.texture.baseTexture; - image.addEventListener("loaded", function (event) { - scope.onLoaded(); - }); - - for (var i in frameData) { - var rect = frameData[i].frame; - if (rect) { - PIXI.TextureCache[i] = new PIXI.Texture(this.texture, { - x: rect.x, - y: rect.y, - width: rect.w, - height: rect.h - }); - if (frameData[i].trimmed) { - //var realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w) - // calculate the offset! - } - } - } - - image.load(); - - } - else if(this.json.bones) - { - // spine animation - var spineJsonParser = new spine.SkeletonJson(); - var skeletonData = spineJsonParser.readSkeletonData(this.json); - PIXI.AnimCache[this.url] = skeletonData; - this.onLoaded(); - } - else - { - this.onLoaded(); - } - } - else - { - this.onError(); - } - } -}; - -/** - * Invoke when json file loaded - * - * @method onLoaded - * @private - */ -PIXI.JsonLoader.prototype.onLoaded = function () { - this.loaded = true; - this.dispatchEvent({ - type: "loaded", - content: this - }); -}; - -/** - * Invoke when error occured - * - * @method onError - * @private - */ -PIXI.JsonLoader.prototype.onError = function () { - this.dispatchEvent({ - type: "error", - content: this - }); -}; -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The sprite sheet loader is used to load in JSON sprite sheet data - * To generate the data you can use http://www.codeandweb.com/texturepacker and publish the "JSON" format - * There is a free version so thats nice, although the paid version is great value for money. - * It is highly recommended to use Sprite sheets (also know as texture atlas") as it means sprite"s can be batched and drawn together for highly increased rendering speed. - * Once the data has been loaded the frames are stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId() - * This loader will also load the image file that the Spritesheet points to as well as the data. - * When loaded this class will dispatch a "loaded" event - * - * @class SpriteSheetLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the sprite sheet JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ - -PIXI.SpriteSheetLoader = function (url, crossorigin) { - /* - * i use texture packer to load the assets.. - * http://www.codeandweb.com/texturepacker - * make sure to set the format as "JSON" - */ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * The texture being loaded - * - * @property texture - * @type Texture - */ - this.texture = null; - - /** - * The frames of the sprite sheet - * - * @property frames - * @type Object - */ - this.frames = {}; -}; - -// constructor -PIXI.SpriteSheetLoader.prototype.constructor = PIXI.SpriteSheetLoader; - -/** - * This will begin loading the JSON file - * - * @method load - */ -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; - scope.onJSONLoaded(); - }); - jsonLoader.load(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () { - var scope = this; - var textureUrl = this.baseUrl + this.json.meta.image; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - var frameData = this.json.frames; - - this.texture = image.texture.baseTexture; - image.addEventListener("loaded", function (event) { - scope.onLoaded(); - }); - - for (var i in frameData) { - var rect = frameData[i].frame; - if (rect) { - PIXI.TextureCache[i] = new PIXI.Texture(this.texture, { - x: rect.x, - y: rect.y, - width: rect.w, - height: rect.h - }); - if (frameData[i].trimmed) { - //var realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w) - // calculate the offset! - } - } - } - - image.load(); -}; -/** - * Invoke when all files are loaded (json and texture) - * - * @method onLoaded - * @private - */ -PIXI.SpriteSheetLoader.prototype.onLoaded = function () { - this.dispatchEvent({ - type: "loaded", - content: this - }); -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The image loader class is responsible for loading images file formats ("jpeg", "jpg", "png" and "gif") - * Once the image has been loaded it is stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId() - * When loaded this class will dispatch a 'loaded' event - * - * @class ImageLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the image - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.ImageLoader = function(url, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The texture being loaded - * - * @property texture - * @type Texture - */ - this.texture = PIXI.Texture.fromImage(url, crossorigin); -}; - -// constructor -PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader; - -/** - * Loads image or takes it from cache - * - * @method load - */ -PIXI.ImageLoader.prototype.load = function() -{ - if(!this.texture.baseTexture.hasLoaded) - { - var scope = this; - this.texture.baseTexture.addEventListener("loaded", function() - { - scope.onLoaded(); - }); - } - else - { - this.onLoaded(); - } -}; - -/** - * Invoked when image file is loaded or it is already cached and ready to use - * - * @method onLoaded - * @private - */ -PIXI.ImageLoader.prototype.onLoaded = function() -{ - this.dispatchEvent({type: "loaded", content: this}); -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The xml loader is used to load in XML bitmap font data ("xml" or "fnt") - * To generate the data you can use http://www.angelcode.com/products/bmfont/ - * This loader will also load the image file as the data. - * When loaded this class will dispatch a "loaded" event - * - * @class BitmapFontLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the sprite sheet JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.BitmapFontLoader = function(url, crossorigin) -{ - /* - * i use texture packer to load the assets.. - * http://www.codeandweb.com/texturepacker - * make sure to set the format as "JSON" - */ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * [read-only] The texture of the bitmap font - * - * @property baseUrl - * @type String - */ - this.texture = null; -}; - -// constructor -PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; - -/** - * Loads the XML font data - * - * @method load - */ -PIXI.BitmapFontLoader.prototype.load = function() -{ - this.ajaxRequest = new XMLHttpRequest(); - var scope = this; - this.ajaxRequest.onreadystatechange = function() - { - scope.onXMLLoaded(); - }; - - this.ajaxRequest.open("GET", this.url, true); - if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/xml"); - this.ajaxRequest.send(null) -}; - -/** - * Invoked when XML file is loaded, parses the data - * - * @method onXMLLoaded - * @private - */ -PIXI.BitmapFontLoader.prototype.onXMLLoaded = function() -{ - if (this.ajaxRequest.readyState == 4) - { - if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) - { - var textureUrl = this.baseUrl + this.ajaxRequest.responseXML.getElementsByTagName("page")[0].attributes.getNamedItem("file").nodeValue; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - this.texture = image.texture.baseTexture; - - var data = {}; - var info = this.ajaxRequest.responseXML.getElementsByTagName("info")[0]; - var common = this.ajaxRequest.responseXML.getElementsByTagName("common")[0]; - data.font = info.attributes.getNamedItem("face").nodeValue; - data.size = parseInt(info.attributes.getNamedItem("size").nodeValue, 10); - data.lineHeight = parseInt(common.attributes.getNamedItem("lineHeight").nodeValue, 10); - data.chars = {}; - - //parse letters - var letters = this.ajaxRequest.responseXML.getElementsByTagName("char"); - - for (var i = 0; i < letters.length; i++) - { - var charCode = parseInt(letters[i].attributes.getNamedItem("id").nodeValue, 10); - - var textureRect = { - x: parseInt(letters[i].attributes.getNamedItem("x").nodeValue, 10), - y: parseInt(letters[i].attributes.getNamedItem("y").nodeValue, 10), - width: parseInt(letters[i].attributes.getNamedItem("width").nodeValue, 10), - height: parseInt(letters[i].attributes.getNamedItem("height").nodeValue, 10) - }; - PIXI.TextureCache[charCode] = new PIXI.Texture(this.texture, textureRect); - - data.chars[charCode] = { - xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), - yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), - xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), - kerning: {}, - texture:new PIXI.Texture(this.texture, textureRect) - - }; - } - - //parse kernings - var kernings = this.ajaxRequest.responseXML.getElementsByTagName("kerning"); - for (i = 0; i < kernings.length; i++) - { - var first = parseInt(kernings[i].attributes.getNamedItem("first").nodeValue, 10); - var second = parseInt(kernings[i].attributes.getNamedItem("second").nodeValue, 10); - var amount = parseInt(kernings[i].attributes.getNamedItem("amount").nodeValue, 10); - - data.chars[second].kerning[first] = amount; - - } - - PIXI.BitmapText.fonts[data.font] = data; - - var scope = this; - image.addEventListener("loaded", function() { - scope.onLoaded(); - }); - image.load(); - } - } -}; - -/** - * Invoked when all files are loaded (xml/fnt and texture) - * - * @method onLoaded - * @private - */ -PIXI.BitmapFontLoader.prototype.onLoaded = function() -{ - this.dispatchEvent({type: "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 - * - * Awesome JS run time provided by EsotericSoftware - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -/** - * The Spine loader is used to load in JSON spine data - * To generate the data you need to use http://esotericsoftware.com/ and export the "JSON" format - * Due to a clash of names You will need to change the extension of the spine file from *.json to *.anim for it to load - * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source - * You will need to generate a sprite sheet to accompany the spine data - * When loaded this class will dispatch a "loaded" event - * - * @class Spine - * @uses EventTarget - * @constructor - * @param url {String} The url of the JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.SpineLoader = function(url, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] Whether the data has loaded yet - * - * @property loaded - * @type Boolean - * @readOnly - */ - this.loaded = false; -} - -PIXI.SpineLoader.prototype.constructor = PIXI.SpineLoader; - -/** - * Loads the JSON data - * - * @method load - */ -PIXI.SpineLoader.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; - scope.onJSONLoaded(); - }); - jsonLoader.load(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.SpineLoader.prototype.onJSONLoaded = function (event) { - var spineJsonParser = new spine.SkeletonJson(); - var skeletonData = spineJsonParser.readSkeletonData(this.json); - - PIXI.AnimCache[this.url] = skeletonData; - - this.onLoaded(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onLoaded - * @private - */ -PIXI.SpineLoader.prototype.onLoaded = function () { - this.loaded = true; - this.dispatchEvent({type: "loaded", content: this}); -}; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - if (typeof exports !== 'undefined') { - if (typeof module !== 'undefined' && module.exports) { - exports = module.exports = PIXI; - } - exports.PIXI = PIXI; - } else { - root.PIXI = PIXI; - } - - -}).call(this); \ No newline at end of file diff --git a/examples/example 11 - RenderTexture/index.html b/examples/example 11 - RenderTexture/index.html index 4020156..cb9c3b1 100644 --- a/examples/example 11 - RenderTexture/index.html +++ b/examples/example 11 - RenderTexture/index.html @@ -9,71 +9,71 @@ background-color: #000000; } - - - + + + - - + + + - + + + + + + + + + + diff --git a/examples/example 12 - Spine/index_pixie.html b/examples/example 12 - Spine/index_pixie.html index c21639b..798480c 100644 --- a/examples/example 12 - Spine/index_pixie.html +++ b/examples/example 12 - Spine/index_pixie.html @@ -9,89 +9,89 @@ background-color: #000000; } - - - + + + - + + + + + + + + + + diff --git a/examples/example 13 - Graphics/pixi.js b/examples/example 13 - Graphics/pixi.js deleted file mode 100644 index a6e7055..0000000 --- a/examples/example 13 - Graphics/pixi.js +++ /dev/null @@ -1,10438 +0,0 @@ -/** - * @license - * Pixi.JS - v1.3.0 - * Copyright (c) 2012, Mat Groves - * http://goodboydigital.com/ - * - * Compiled: 2013-07-24 - * - * Pixi.JS is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license.php - */ -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -(function(){ - - var root = this; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * @module PIXI - */ -var PIXI = PIXI || {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis. - * - * @class Point - * @constructor - * @param x {Number} position of the point - * @param y {Number} position of the point - */ -PIXI.Point = function(x, y) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; -} - -/** - * Creates a clone of this point - * - * @method clone - * @return {Point} a copy of the point - */ -PIXI.Point.prototype.clone = function() -{ - return new PIXI.Point(this.x, this.y); -} - -// constructor -PIXI.Point.prototype.constructor = PIXI.Point; - - -/** - * @author Mat Groves http://matgroves.com/ - */ - -/** - * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. - * - * @class Rectangle - * @constructor - * @param x {Number} The X coord of the upper-left corner of the rectangle - * @param y {Number} The Y coord of the upper-left corner of the rectangle - * @param width {Number} The overall wisth of this rectangle - * @param height {Number} The overall height of this rectangle - */ -PIXI.Rectangle = function(x, y, width, height) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property width - * @type Number - * @default 0 - */ - this.width = width || 0; - - /** - * @property height - * @type Number - * @default 0 - */ - this.height = height || 0; -} - -/** - * Creates a clone of this Rectangle - * - * @method clone - * @return {Rectangle} a copy of the rectangle - */ -PIXI.Rectangle.prototype.clone = function() -{ - return new PIXI.Rectangle(this.x, this.y, this.width, this.height); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this Rectangle - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this Rectangle - */ -PIXI.Rectangle.prototype.contains = function(x, y) -{ - if(this.width <= 0 || this.height <= 0) - return false; - - var x1 = this.x; - if(x > x1 && x < x1 + this.width) - { - var y1 = this.y; - - if(y > y1 && y < y1 + this.height) - { - return true; - } - } - - return false; -} - -// constructor -PIXI.Rectangle.prototype.constructor = PIXI.Rectangle; - - -/** - * @author Adrien Brault - */ - -/** - * @class Polygon - * @constructor - * @param points* {Array|Array|Point...|Number...} This can be an array of Points that form the polygon, - * a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arugments passed can be - * all the points of the polygon e.g. `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the - * arguments passed can be flat x,y values e.g. `new PIXI.Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are - * Numbers. - */ -PIXI.Polygon = function(points) -{ - //if points isn't an array, use arguments as the array - if(!(points instanceof Array)) - points = Array.prototype.slice.call(arguments); - - //if this is a flat array of numbers, convert it to points - if(typeof points[0] === 'number') { - var p = []; - for(var i = 0, il = points.length; i < il; i+=2) { - p.push( - new PIXI.Point(points[i], points[i + 1]) - ); - } - - points = p; - } - - this.points = points; -} - -/** - * Creates a clone of this polygon - * - * @method clone - * @return {Polygon} a copy of the polygon - */ -PIXI.Polygon.prototype.clone = function() -{ - var points = []; - for (var i=0; i y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi); - - if(intersect) inside = !inside; - } - - return inside; -} - -PIXI.Polygon.prototype.constructor = PIXI.Polygon; - - -/** - * @author Chad Engler - */ - -/** - * The Circle object can be used to specify a hit area for displayobjects - * - * @class Circle - * @constructor - * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this circle - * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this circle - * @param radius {Number} The radius of the circle - */ -PIXI.Circle = function(x, y, radius) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property radius - * @type Number - * @default 0 - */ - this.radius = radius || 0; -} - -/** - * Creates a clone of this Circle instance - * - * @method clone - * @return {Circle} a copy of the polygon - */ -PIXI.Circle.prototype.clone = function() -{ - return new PIXI.Circle(this.x, this.y, this.radius); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this circle - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this polygon - */ -PIXI.Circle.prototype.contains = function(x, y) -{ - if(this.radius <= 0) - return false; - - var dx = (this.x - x), - dy = (this.y - y), - r2 = this.radius * this.radius; - - dx *= dx; - dy *= dy; - - return (dx + dy <= r2); -} - -PIXI.Circle.prototype.constructor = PIXI.Circle; - - -/** - * @author Chad Engler - */ - -/** - * The Ellipse object can be used to specify a hit area for displayobjects - * - * @class Ellipse - * @constructor - * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this ellipse - * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this ellipse - * @param width {Number} The overall height of this ellipse - * @param height {Number} The overall width of this ellipse - */ -PIXI.Ellipse = function(x, y, width, height) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property width - * @type Number - * @default 0 - */ - this.width = width || 0; - - /** - * @property height - * @type Number - * @default 0 - */ - this.height = height || 0; -} - -/** - * Creates a clone of this Ellipse instance - * - * @method clone - * @return {Ellipse} a copy of the ellipse - */ -PIXI.Ellipse.prototype.clone = function() -{ - return new PIXI.Ellipse(this.x, this.y, this.width, this.height); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this ellipse - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this ellipse - */ -PIXI.Ellipse.prototype.contains = function(x, y) -{ - if(this.width <= 0 || this.height <= 0) - return false; - - //normalize the coords to an ellipse with center 0,0 - //and a radius of 0.5 - var normx = ((x - this.x) / this.width) - 0.5, - normy = ((y - this.y) / this.height) - 0.5; - - normx *= normx; - normy *= normy; - - return (normx + normy < 0.25); -} - -PIXI.Ellipse.getBounds = function() -{ - return new PIXI.Rectangle(this.x, this.y, this.width, this.height); -} - -PIXI.Ellipse.prototype.constructor = PIXI.Ellipse; - - - - -/* - * A lighter version of the rad gl-matrix created by Brandon Jones, Colin MacKenzie IV - * you both rock! - */ - -function determineMatrixArrayType() { - PIXI.Matrix = (typeof Float32Array !== 'undefined') ? Float32Array : Array; - return PIXI.Matrix; -} - -determineMatrixArrayType(); - -PIXI.mat3 = {}; - -PIXI.mat3.create = function() -{ - var matrix = new PIXI.Matrix(9); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 1; - matrix[5] = 0; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 1; - - return matrix; -} - - -PIXI.mat3.identity = function(matrix) -{ - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 1; - matrix[5] = 0; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 1; - - return matrix; -} - - -PIXI.mat4 = {}; - -PIXI.mat4.create = function() -{ - var matrix = new PIXI.Matrix(16); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 0; - matrix[5] = 1; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 0; - matrix[9] = 0; - matrix[10] = 1; - matrix[11] = 0; - matrix[12] = 0; - matrix[13] = 0; - matrix[14] = 0; - matrix[15] = 1; - - return matrix; -} - -PIXI.mat3.multiply = function (mat, mat2, dest) -{ - if (!dest) { dest = mat; } - - // Cache the matrix values (makes for huge speed increases!) - var a00 = mat[0], a01 = mat[1], a02 = mat[2], - a10 = mat[3], a11 = mat[4], a12 = mat[5], - a20 = mat[6], a21 = mat[7], a22 = mat[8], - - b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], - b10 = mat2[3], b11 = mat2[4], b12 = mat2[5], - b20 = mat2[6], b21 = mat2[7], b22 = mat2[8]; - - dest[0] = b00 * a00 + b01 * a10 + b02 * a20; - dest[1] = b00 * a01 + b01 * a11 + b02 * a21; - dest[2] = b00 * a02 + b01 * a12 + b02 * a22; - - dest[3] = b10 * a00 + b11 * a10 + b12 * a20; - dest[4] = b10 * a01 + b11 * a11 + b12 * a21; - dest[5] = b10 * a02 + b11 * a12 + b12 * a22; - - dest[6] = b20 * a00 + b21 * a10 + b22 * a20; - dest[7] = b20 * a01 + b21 * a11 + b22 * a21; - dest[8] = b20 * a02 + b21 * a12 + b22 * a22; - - return dest; -} - -PIXI.mat3.clone = function(mat) -{ - var matrix = new PIXI.Matrix(9); - - matrix[0] = mat[0]; - matrix[1] = mat[1]; - matrix[2] = mat[2]; - matrix[3] = mat[3]; - matrix[4] = mat[4]; - matrix[5] = mat[5]; - matrix[6] = mat[6]; - matrix[7] = mat[7]; - matrix[8] = mat[8]; - - return matrix; -} - -PIXI.mat3.transpose = function (mat, dest) -{ - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (!dest || mat === dest) { - var a01 = mat[1], a02 = mat[2], - a12 = mat[5]; - - mat[1] = mat[3]; - mat[2] = mat[6]; - mat[3] = a01; - mat[5] = mat[7]; - mat[6] = a02; - mat[7] = a12; - return mat; - } - - dest[0] = mat[0]; - dest[1] = mat[3]; - dest[2] = mat[6]; - dest[3] = mat[1]; - dest[4] = mat[4]; - dest[5] = mat[7]; - dest[6] = mat[2]; - dest[7] = mat[5]; - dest[8] = mat[8]; - return dest; -} - -PIXI.mat3.toMat4 = function (mat, dest) -{ - if (!dest) { dest = PIXI.mat4.create(); } - - dest[15] = 1; - dest[14] = 0; - dest[13] = 0; - dest[12] = 0; - - dest[11] = 0; - dest[10] = mat[8]; - dest[9] = mat[7]; - dest[8] = mat[6]; - - dest[7] = 0; - dest[6] = mat[5]; - dest[5] = mat[4]; - dest[4] = mat[3]; - - dest[3] = 0; - dest[2] = mat[2]; - dest[1] = mat[1]; - dest[0] = mat[0]; - - return dest; -} - - -///// - - -PIXI.mat4.create = function() -{ - var matrix = new PIXI.Matrix(16); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 0; - matrix[5] = 1; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 0; - matrix[9] = 0; - matrix[10] = 1; - matrix[11] = 0; - matrix[12] = 0; - matrix[13] = 0; - matrix[14] = 0; - matrix[15] = 1; - - return matrix; -} - -PIXI.mat4.transpose = function (mat, dest) -{ - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (!dest || mat === dest) - { - var a01 = mat[1], a02 = mat[2], a03 = mat[3], - a12 = mat[6], a13 = mat[7], - a23 = mat[11]; - - mat[1] = mat[4]; - mat[2] = mat[8]; - mat[3] = mat[12]; - mat[4] = a01; - mat[6] = mat[9]; - mat[7] = mat[13]; - mat[8] = a02; - mat[9] = a12; - mat[11] = mat[14]; - mat[12] = a03; - mat[13] = a13; - mat[14] = a23; - return mat; - } - - dest[0] = mat[0]; - dest[1] = mat[4]; - dest[2] = mat[8]; - dest[3] = mat[12]; - dest[4] = mat[1]; - dest[5] = mat[5]; - dest[6] = mat[9]; - dest[7] = mat[13]; - dest[8] = mat[2]; - dest[9] = mat[6]; - dest[10] = mat[10]; - dest[11] = mat[14]; - dest[12] = mat[3]; - dest[13] = mat[7]; - dest[14] = mat[11]; - dest[15] = mat[15]; - return dest; -} - -PIXI.mat4.multiply = function (mat, mat2, dest) -{ - if (!dest) { dest = mat; } - - // Cache the matrix values (makes for huge speed increases!) - var a00 = mat[ 0], a01 = mat[ 1], a02 = mat[ 2], a03 = mat[3]; - var a10 = mat[ 4], a11 = mat[ 5], a12 = mat[ 6], a13 = mat[7]; - var a20 = mat[ 8], a21 = mat[ 9], a22 = mat[10], a23 = mat[11]; - var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15]; - - // Cache only the current line of the second matrix - var b0 = mat2[0], b1 = mat2[1], b2 = mat2[2], b3 = mat2[3]; - dest[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[4]; - b1 = mat2[5]; - b2 = mat2[6]; - b3 = mat2[7]; - dest[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[8]; - b1 = mat2[9]; - b2 = mat2[10]; - b3 = mat2[11]; - dest[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[12]; - b1 = mat2[13]; - b2 = mat2[14]; - b3 = mat2[15]; - dest[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - return dest; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The base class for all objects that are rendered on the screen. - * - * @class DisplayObject - * @constructor - */ -PIXI.DisplayObject = function() -{ - this.last = this; - this.first = this; - - /** - * The coordinate of the object relative to the local coordinates of the parent. - * - * @property position - * @type Point - */ - this.position = new PIXI.Point(); - - /** - * The scale factor of the object. - * - * @property scale - * @type Point - */ - this.scale = new PIXI.Point(1,1);//{x:1, y:1}; - - /** - * The pivot point of the displayObject that it rotates around - * - * @property pivot - * @type Point - */ - this.pivot = new PIXI.Point(0,0); - - /** - * The rotation of the object in radians. - * - * @property rotation - * @type Number - */ - this.rotation = 0; - - /** - * The opacity of the object. - * - * @property alpha - * @type Number - */ - this.alpha = 1; - - /** - * The visibility of the object. - * - * @property visible - * @type Boolean - */ - this.visible = true; - - /** - * This is the defined area that will pick up mouse / touch events. It is null by default. - * Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children) - * - * @property hitArea - * @type Rectangle|Circle|Ellipse|Polygon - */ - this.hitArea = null; - - /** - * This is used to indicate if the displayObject should display a mouse hand cursor on rollover - * - * @property buttonMode - * @type Boolean - */ - this.buttonMode = false; - - /** - * Can this object be rendered - * - * @property renderable - * @type Boolean - */ - this.renderable = false; - - /** - * [read-only] The visibility of the object based on world (parent) factors. - * - * @property worldVisible - * @type Boolean - * @readOnly - */ - this.worldVisible = false; - - /** - * [read-only] The display object container that contains this display object. - * - * @property parent - * @type DisplayObjectContainer - * @readOnly - */ - this.parent = null; - - /** - * [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage. - * - * @property stage - * @type Stage - * @readOnly - */ - this.stage = null; - - /** - * [read-only] The index of this object in the parent's `children` array - * - * @property childIndex - * @type Number - * @readOnly - */ - this.childIndex = 0; - - /** - * [read-only] The multiplied alpha of the displayobject - * - * @property worldAlpha - * @type Number - * @readOnly - */ - this.worldAlpha = 1; - - /** - * [read-only] Whether or not the object is interactive, do not toggle directly! use the `interactive` property - * - * @property _interactive - * @type Boolean - * @readOnly - * @private - */ - this._interactive = false; - - /** - * [read-only] Current transform of the object based on world (parent) factors - * - * @property worldTransform - * @type Mat3 - * @readOnly - * @private - */ - this.worldTransform = PIXI.mat3.create()//mat3.identity(); - - /** - * [read-only] Current transform of the object locally - * - * @property localTransform - * @type Mat3 - * @readOnly - * @private - */ - this.localTransform = PIXI.mat3.create()//mat3.identity(); - - /** - * [NYI] Unkown - * - * @property color - * @type Array<> - * @private - */ - this.color = []; - - /** - * [NYI] Holds whether or not this object is dynamic, for rendering optimization - * - * @property dynamic - * @type Boolean - * @private - */ - this.dynamic = true; - - // chach that puppy! - this._sr = 0; - this._cr = 1; - - /* - * MOUSE Callbacks - */ - - /** - * A callback that is used when the users clicks on the displayObject with their mouse - * @method click - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user clicks the mouse down over the sprite - * @method mousedown - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the mouse that was over the displayObject - * for this callback to be fired the mouse must have been pressed down over the displayObject - * @method mouseup - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject - * for this callback to be fired, The touch must have started over the displayObject - * @method mouseupoutside - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the users mouse rolls over the displayObject - * @method mouseover - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the users mouse leaves the displayObject - * @method mouseout - * @param interactionData {InteractionData} - */ - - - /* - * TOUCH Callbacks - */ - - /** - * A callback that is used when the users taps on the sprite with their finger - * basically a touch version of click - * @method tap - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user touch's over the displayObject - * @method touchstart - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases a touch over the displayObject - * @method touchend - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the touch that was over the displayObject - * for this callback to be fired, The touch must have started over the sprite - * @method touchendoutside - * @param interactionData {InteractionData} - */ -} - -// constructor -PIXI.DisplayObject.prototype.constructor = PIXI.DisplayObject; - -//TODO make visible a getter setter -/* -Object.defineProperty(PIXI.DisplayObject.prototype, 'visible', { - get: function() { - return this._visible; - }, - set: function(value) { - this._visible = value; - } -});*/ - -/** - * [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default - * Instead of using this function you can now simply set the interactive property to true or false - * - * @method setInteractive - * @param interactive {Boolean} - * @deprecated Simply set the `interactive` property directly - */ -PIXI.DisplayObject.prototype.setInteractive = function(interactive) -{ - this.interactive = interactive; -} - -/** - * Indicates if the sprite will have touch and mouse interactivity. It is false by default - * - * @property interactive - * @type Boolean - * @default false - */ -Object.defineProperty(PIXI.DisplayObject.prototype, 'interactive', { - get: function() { - return this._interactive; - }, - set: function(value) { - this._interactive = value; - - // TODO more to be done here.. - // need to sort out a re-crawl! - if(this.stage)this.stage.dirty = true; - } -}); - -/** - * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. - * In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. - * To remove a mask, set this property to null. - * - * @property mask - * @type Graphics - */ -Object.defineProperty(PIXI.DisplayObject.prototype, 'mask', { - get: function() { - return this._mask; - }, - set: function(value) { - - this._mask = value; - - if(value) - { - this.addFilter(value) - } - else - { - this.removeFilter(); - } - } -}); - -/* - * Adds a filter to this displayObject - * - * @method addFilter - * @param mask {Graphics} the graphics object to use as a filter - * @private - */ -PIXI.DisplayObject.prototype.addFilter = function(mask) -{ - if(this.filter)return; - this.filter = true; - - - // insert a filter block.. - var start = new PIXI.FilterBlock(); - var end = new PIXI.FilterBlock(); - - - start.mask = mask; - end.mask = mask; - - start.first = start.last = this; - end.first = end.last = this; - - start.open = true; - - /* - * - * insert start - * - */ - - var childFirst = start - var childLast = start - var nextObject; - var previousObject; - - previousObject = this.first._iPrev; - - if(previousObject) - { - nextObject = previousObject._iNext; - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - } - else - { - nextObject = this; - } - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - - // now insert the end filter block.. - - /* - * - * insert end filter - * - */ - var childFirst = end - var childLast = end - var nextObject = null; - var previousObject = null; - - previousObject = this.last; - nextObject = previousObject._iNext; - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - var updateLast = this; - - var prevLast = this.last; - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = end; - } - updateLast = updateLast.parent; - } - - this.first = start; - - // if webGL... - if(this.__renderGroup) - { - this.__renderGroup.addFilterBlocks(start, end); - } - - mask.renderable = false; - -} - -/* - * Removes the filter to this displayObject - * - * @method removeFilter - * @private - */ -PIXI.DisplayObject.prototype.removeFilter = function() -{ - if(!this.filter)return; - this.filter = false; - - // modify the list.. - var startBlock = this.first; - - var nextObject = startBlock._iNext; - var previousObject = startBlock._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - if(previousObject)previousObject._iNext = nextObject; - - this.first = startBlock._iNext; - - - // remove the end filter - var lastBlock = this.last; - - var nextObject = lastBlock._iNext; - var previousObject = lastBlock._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - previousObject._iNext = nextObject; - - // this is always true too! -// if(this.last == lastBlock) - //{ - var tempLast = lastBlock._iPrev; - // need to make sure the parents last is updated too - var updateLast = this; - while(updateLast.last == lastBlock) - { - updateLast.last = tempLast; - updateLast = updateLast.parent; - if(!updateLast)break; - } - - var mask = startBlock.mask - mask.renderable = true; - - // if webGL... - if(this.__renderGroup) - { - this.__renderGroup.removeFilterBlocks(startBlock, lastBlock); - } - //} -} - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.DisplayObject.prototype.updateTransform = function() -{ - // TODO OPTIMIZE THIS!! with dirty - if(this.rotation != this.rotationCache) - { - this.rotationCache = this.rotation; - this._sr = Math.sin(this.rotation); - this._cr = Math.cos(this.rotation); - } - - var localTransform = this.localTransform; - var parentTransform = this.parent.worldTransform; - var worldTransform = this.worldTransform; - //console.log(localTransform) - localTransform[0] = this._cr * this.scale.x; - localTransform[1] = -this._sr * this.scale.y - localTransform[3] = this._sr * this.scale.x; - localTransform[4] = this._cr * this.scale.y; - - // TODO --> do we even need a local matrix??? - - var px = this.pivot.x; - var py = this.pivot.y; - - // Cache the matrix values (makes for huge speed increases!) - var a00 = localTransform[0], a01 = localTransform[1], a02 = this.position.x - localTransform[0] * px - py * localTransform[1], - a10 = localTransform[3], a11 = localTransform[4], a12 = this.position.y - localTransform[4] * py - px * localTransform[3], - - b00 = parentTransform[0], b01 = parentTransform[1], b02 = parentTransform[2], - b10 = parentTransform[3], b11 = parentTransform[4], b12 = parentTransform[5]; - - localTransform[2] = a02 - localTransform[5] = a12 - - worldTransform[0] = b00 * a00 + b01 * a10; - worldTransform[1] = b00 * a01 + b01 * a11; - worldTransform[2] = b00 * a02 + b01 * a12 + b02; - - worldTransform[3] = b10 * a00 + b11 * a10; - worldTransform[4] = b10 * a01 + b11 * a11; - worldTransform[5] = b10 * a02 + b11 * a12 + b12; - - // because we are using affine transformation, we can optimise the matrix concatenation process.. wooo! - // mat3.multiply(this.localTransform, this.parent.worldTransform, this.worldTransform); - this.worldAlpha = this.alpha * this.parent.worldAlpha; - -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * A DisplayObjectContainer represents a collection of display objects. - * It is the base class of all display objects that act as a container for other objects. - * - * @class DisplayObjectContainer - * @extends DisplayObject - * @constructor - */ -PIXI.DisplayObjectContainer = function() -{ - PIXI.DisplayObject.call( this ); - - /** - * [read-only] The of children of this container. - * - * @property children - * @type Array - * @readOnly - */ - this.children = []; -} - -// constructor -PIXI.DisplayObjectContainer.prototype = Object.create( PIXI.DisplayObject.prototype ); -PIXI.DisplayObjectContainer.prototype.constructor = PIXI.DisplayObjectContainer; - -//TODO make visible a getter setter -/* -Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'visible', { - get: function() { - return this._visible; - }, - set: function(value) { - this._visible = value; - - } -});*/ - -/** - * Adds a child to the container. - * - * @method addChild - * @param child {DisplayObject} The DisplayObject to add to the container - */ -PIXI.DisplayObjectContainer.prototype.addChild = function(child) -{ - if(child.parent != undefined) - { - - //// COULD BE THIS??? - child.parent.removeChild(child); - // return; - } - - child.parent = this; - child.childIndex = this.children.length; - - this.children.push(child); - - // updae the stage refference.. - - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = this.stage; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // LINKED LIST // - - // modify the list.. - var childFirst = child.first - var childLast = child.last; - var nextObject; - var previousObject; - - // this could be wrong if there is a filter?? - if(this.filter) - { - previousObject = this.last._iPrev; - } - else - { - previousObject = this.last; - } - - nextObject = previousObject._iNext; - - // always true in this case - //this.last = child.last; - // need to make sure the parents last is updated too - var updateLast = this; - var prevLast = previousObject; - - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = child.last; - } - updateLast = updateLast.parent; - } - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - // need to remove any render groups.. - if(this.__renderGroup) - { - // being used by a renderTexture.. if it exists then it must be from a render texture; - if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child); - // add them to the new render group.. - this.__renderGroup.addDisplayObjectAndChildren(child); - } - -} - -/** - * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown - * - * @method addChildAt - * @param child {DisplayObject} The child to add - * @param index {Number} The index to place the child in - */ -PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index) -{ - if(index >= 0 && index <= this.children.length) - { - if(child.parent != undefined) - { - child.parent.removeChild(child); - } - child.parent = this; - - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = this.stage; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // modify the list.. - var childFirst = child.first - var childLast = child.last; - var nextObject; - var previousObject; - - if(index == this.children.length) - { - previousObject = this.last; - var updateLast = this;//.parent; - var prevLast = this.last; - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = child.last; - } - updateLast = updateLast.parent; - } - } - else if(index == 0) - { - previousObject = this; - } - else - { - previousObject = this.children[index-1].last; - } - - nextObject = previousObject._iNext; - - // always true in this case - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - this.children.splice(index, 0, child); - // need to remove any render groups.. - if(this.__renderGroup) - { - // being used by a renderTexture.. if it exists then it must be from a render texture; - if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child); - // add them to the new render group.. - this.__renderGroup.addDisplayObjectAndChildren(child); - } - - } - else - { - throw new Error(child + " The index "+ index +" supplied is out of bounds " + this.children.length); - } -} - -/** - * [NYI] Swaps the depth of 2 displayObjects - * - * @method swapChildren - * @param child {DisplayObject} - * @param child2 {DisplayObject} - * @private - */ -PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2) -{ - /* - * this funtion needs to be recoded.. - * can be done a lot faster.. - */ - return; - - // need to fix this function :/ - /* - // TODO I already know this?? - var index = this.children.indexOf( child ); - var index2 = this.children.indexOf( child2 ); - - if ( index !== -1 && index2 !== -1 ) - { - // cool - - /* - if(this.stage) - { - // this is to satisfy the webGL batching.. - // TODO sure there is a nicer way to achieve this! - this.stage.__removeChild(child); - this.stage.__removeChild(child2); - - this.stage.__addChild(child); - this.stage.__addChild(child2); - } - - // swap the positions.. - this.children[index] = child2; - this.children[index2] = child; - - } - else - { - throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this); - }*/ -} - -/** - * Returns the Child at the specified index - * - * @method getChildAt - * @param index {Number} The index to get the child from - */ -PIXI.DisplayObjectContainer.prototype.getChildAt = function(index) -{ - if(index >= 0 && index < this.children.length) - { - return this.children[index]; - } - else - { - throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this); - } -} - -/** - * Removes a child from the container. - * - * @method removeChild - * @param child {DisplayObject} The DisplayObject to remove - */ -PIXI.DisplayObjectContainer.prototype.removeChild = function(child) -{ - var index = this.children.indexOf( child ); - if ( index !== -1 ) - { - // unlink // - // modify the list.. - var childFirst = child.first - var childLast = child.last; - - var nextObject = childLast._iNext; - var previousObject = childFirst._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - previousObject._iNext = nextObject; - - if(this.last == childLast) - { - var tempLast = childFirst._iPrev; - // need to make sure the parents last is updated too - var updateLast = this; - while(updateLast.last == childLast.last) - { - updateLast.last = tempLast; - updateLast = updateLast.parent; - if(!updateLast)break; - } - } - - childLast._iNext = null; - childFirst._iPrev = null; - - // update the stage reference.. - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = null; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // webGL trim - if(child.__renderGroup) - { - child.__renderGroup.removeDisplayObjectAndChildren(child); - } - - child.parent = undefined; - this.children.splice( index, 1 ); - } - else - { - throw new Error(child + " The supplied DisplayObject must be a child of the caller " + this); - } -} - -/* - * Updates the container's children's transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.DisplayObjectContainer.prototype.updateTransform = function() -{ - if(!this.visible)return; - - PIXI.DisplayObject.prototype.updateTransform.call( this ); - - for(var i=0,j=this.children.length; i} an array of {Texture} objects that make up the animation - */ -PIXI.MovieClip = function(textures) -{ - PIXI.Sprite.call(this, textures[0]); - - /** - * The array of textures that make up the animation - * - * @property textures - * @type Array - */ - this.textures = textures; - - /** - * The speed that the MovieClip will play at. Higher is faster, lower is slower - * - * @property animationSpeed - * @type Number - * @default 1 - */ - this.animationSpeed = 1; - - /** - * Whether or not the movie clip repeats after playing. - * - * @property loop - * @type Boolean - * @default true - */ - this.loop = true; - - /** - * Function to call when a MovieClip finishes playing - * - * @property onComplete - * @type Function - */ - this.onComplete = null; - - /** - * [read-only] The index MovieClips current frame (this may not have to be a whole number) - * - * @property currentFrame - * @type Number - * @default 0 - * @readOnly - */ - this.currentFrame = 0; - - /** - * [read-only] Indicates if the MovieClip is currently playing - * - * @property playing - * @type Boolean - * @readOnly - */ - this.playing = false; -} - -// constructor -PIXI.MovieClip.prototype = Object.create( PIXI.Sprite.prototype ); -PIXI.MovieClip.prototype.constructor = PIXI.MovieClip; - -/** - * Stops the MovieClip - * - * @method stop - */ -PIXI.MovieClip.prototype.stop = function() -{ - this.playing = false; -} - -/** - * Plays the MovieClip - * - * @method play - */ -PIXI.MovieClip.prototype.play = function() -{ - this.playing = true; -} - -/** - * Stops the MovieClip and goes to a specific frame - * - * @method gotoAndStop - * @param frameNumber {Number} frame index to stop at - */ -PIXI.MovieClip.prototype.gotoAndStop = function(frameNumber) -{ - this.playing = false; - this.currentFrame = frameNumber; - var round = (this.currentFrame + 0.5) | 0; - this.setTexture(this.textures[round % this.textures.length]); -} - -/** - * Goes to a specific frame and begins playing the MovieClip - * - * @method gotoAndPlay - * @param frameNumber {Number} frame index to start at - */ -PIXI.MovieClip.prototype.gotoAndPlay = function(frameNumber) -{ - this.currentFrame = frameNumber; - this.playing = true; -} - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.MovieClip.prototype.updateTransform = function() -{ - PIXI.Sprite.prototype.updateTransform.call(this); - - if(!this.playing)return; - - this.currentFrame += this.animationSpeed; - var round = (this.currentFrame + 0.5) | 0; - if(this.loop || round < this.textures.length) - { - this.setTexture(this.textures[round % this.textures.length]); - } - else if(round >= this.textures.length) - { - this.gotoAndStop(this.textures.length - 1); - if(this.onComplete) - { - this.onComplete(); - } - } -} -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - - -PIXI.FilterBlock = function(mask) -{ - this.graphics = mask - this.visible = true; - this.renderable = true; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Text Object will create a line(s) of text to split a line you can use "\n" - * - * @class Text - * @extends Sprite - * @constructor - * @param text {String} The copy that you would like the text to display - * @param [style] {Object} The style parameters - * @param [style.font] {String} default "bold 20pt Arial" The style and size of the font - * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00" - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - * @param [style.stroke] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00" - * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke) - * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used - * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap - */ -PIXI.Text = function(text, style) -{ - this.canvas = document.createElement("canvas"); - this.context = this.canvas.getContext("2d"); - PIXI.Sprite.call(this, PIXI.Texture.fromCanvas(this.canvas)); - - this.setText(text); - this.setStyle(style); - - this.updateText(); - this.dirty = false; -}; - -// constructor -PIXI.Text.prototype = Object.create(PIXI.Sprite.prototype); -PIXI.Text.prototype.constructor = PIXI.Text; - -/** - * Set the style of the text - * - * @method setStyle - * @param [style] {Object} The style parameters - * @param [style.font="bold 20pt Arial"] {String} The style and size of the font - * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00" - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - * @param [style.stroke="black"] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00" - * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke) - * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used - * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap - */ -PIXI.Text.prototype.setStyle = function(style) -{ - style = style || {}; - style.font = style.font || "bold 20pt Arial"; - style.fill = style.fill || "black"; - style.align = style.align || "left"; - style.stroke = style.stroke || "black"; //provide a default, see: https://github.com/GoodBoyDigital/pixi.js/issues/136 - style.strokeThickness = style.strokeThickness || 0; - style.wordWrap = style.wordWrap || false; - style.wordWrapWidth = style.wordWrapWidth || 100; - this.style = style; - this.dirty = true; -}; - -/** - * Set the copy for the text object. To split a line you can use "\n" - * - * @methos setText - * @param {String} text The copy that you would like the text to display - */ -PIXI.Sprite.prototype.setText = function(text) -{ - this.text = text.toString() || " "; - this.dirty = true; -}; - -/** - * Renders text - * - * @method updateText - * @private - */ -PIXI.Text.prototype.updateText = function() -{ - this.context.font = this.style.font; - - var outputText = this.text; - - // word wrap - // preserve original text - if(this.style.wordWrap)outputText = this.wordWrap(this.text); - - //split text into lines - var lines = outputText.split(/(?:\r\n|\r|\n)/); - - //calculate text width - var lineWidths = []; - var maxLineWidth = 0; - for (var i = 0; i < lines.length; i++) - { - var lineWidth = this.context.measureText(lines[i]).width; - lineWidths[i] = lineWidth; - maxLineWidth = Math.max(maxLineWidth, lineWidth); - } - this.canvas.width = maxLineWidth + this.style.strokeThickness; - - //calculate text height - var lineHeight = this.determineFontHeight("font: " + this.style.font + ";") + this.style.strokeThickness; - this.canvas.height = lineHeight * lines.length; - - //set canvas text styles - this.context.fillStyle = this.style.fill; - this.context.font = this.style.font; - - this.context.strokeStyle = this.style.stroke; - this.context.lineWidth = this.style.strokeThickness; - - this.context.textBaseline = "top"; - - //draw lines line by line - for (i = 0; i < lines.length; i++) - { - var linePosition = new PIXI.Point(this.style.strokeThickness / 2, this.style.strokeThickness / 2 + i * lineHeight); - - if(this.style.align == "right") - { - linePosition.x += maxLineWidth - lineWidths[i]; - } - else if(this.style.align == "center") - { - linePosition.x += (maxLineWidth - lineWidths[i]) / 2; - } - - if(this.style.stroke && this.style.strokeThickness) - { - this.context.strokeText(lines[i], linePosition.x, linePosition.y); - } - - if(this.style.fill) - { - this.context.fillText(lines[i], linePosition.x, linePosition.y); - } - } - - this.updateTexture(); -}; - -/** - * Updates texture size based on canvas size - * - * @method updateTexture - * @private - */ -PIXI.Text.prototype.updateTexture = function() -{ - this.texture.baseTexture.width = this.canvas.width; - this.texture.baseTexture.height = this.canvas.height; - this.texture.frame.width = this.canvas.width; - this.texture.frame.height = this.canvas.height; - - this._width = this.canvas.width; - this._height = this.canvas.height; - - PIXI.texturesToUpdate.push(this.texture.baseTexture); -}; - -/** - * Updates the transfor of this object - * - * @method updateTransform - * @private - */ -PIXI.Text.prototype.updateTransform = function() -{ - if(this.dirty) - { - this.updateText(); - this.dirty = false; - } - - PIXI.Sprite.prototype.updateTransform.call(this); -}; - -/* - * http://stackoverflow.com/users/34441/ellisbben - * great solution to the problem! - * - * @method determineFontHeight - * @param fontStyle {Object} - * @private - */ -PIXI.Text.prototype.determineFontHeight = function(fontStyle) -{ - // build a little reference dictionary so if the font style has been used return a - // cached version... - var result = PIXI.Text.heightCache[fontStyle]; - - if(!result) - { - var body = document.getElementsByTagName("body")[0]; - var dummy = document.createElement("div"); - var dummyText = document.createTextNode("M"); - dummy.appendChild(dummyText); - dummy.setAttribute("style", fontStyle + ';position:absolute;top:0;left:0'); - body.appendChild(dummy); - - result = dummy.offsetHeight; - PIXI.Text.heightCache[fontStyle] = result; - - body.removeChild(dummy); - } - - return result; -}; - -/** - * A Text Object will apply wordwrap - * - * @method wordWrap - * @param text {String} - * @private - */ -PIXI.Text.prototype.wordWrap = function(text) -{ - // search good wrap position - var searchWrapPos = function(ctx, text, start, end, wrapWidth) - { - var p = Math.floor((end-start) / 2) + start; - if(p == start) { - return 1; - } - - if(ctx.measureText(text.substring(0,p)).width <= wrapWidth) - { - if(ctx.measureText(text.substring(0,p+1)).width > wrapWidth) - { - return p; - } - else - { - return arguments.callee(ctx, text, p, end, wrapWidth); - } - } - else - { - return arguments.callee(ctx, text, start, p, wrapWidth); - } - }; - - var lineWrap = function(ctx, text, wrapWidth) - { - if(ctx.measureText(text).width <= wrapWidth || text.length < 1) - { - return text; - } - var pos = searchWrapPos(ctx, text, 0, text.length, wrapWidth); - return text.substring(0, pos) + "\n" + arguments.callee(ctx, text.substring(pos), wrapWidth); - }; - - var result = ""; - var lines = text.split("\n"); - for (var i = 0; i < lines.length; i++) - { - result += lineWrap(this.context, lines[i], this.style.wordWrapWidth) + "\n"; - } - - return result; -}; - -/** - * Destroys this text object - * - * @method destroy - * @param destroyTexture {Boolean} - */ -PIXI.Text.prototype.destroy = function(destroyTexture) -{ - if(destroyTexture) - { - this.texture.destroy(); - } - -}; - -PIXI.Text.heightCache = {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Text Object will create a line(s) of text using bitmap font. To split a line you can use "\n", "\r" or "\r\n" - * You can generate the fnt files using - * http://www.angelcode.com/products/bmfont/ for windows or - * http://www.bmglyph.com/ for mac. - * - * @class BitmapText - * @extends DisplayObjectContainer - * @constructor - * @param text {String} The copy that you would like the text to display - * @param style {Object} The style parameters - * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously) - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - */ -PIXI.BitmapText = function(text, style) -{ - PIXI.DisplayObjectContainer.call(this); - - this.setText(text); - this.setStyle(style); - this.updateText(); - this.dirty = false - -}; - -// constructor -PIXI.BitmapText.prototype = Object.create(PIXI.DisplayObjectContainer.prototype); -PIXI.BitmapText.prototype.constructor = PIXI.BitmapText; - -/** - * Set the copy for the text object - * - * @method setText - * @param text {String} The copy that you would like the text to display - */ -PIXI.BitmapText.prototype.setText = function(text) -{ - this.text = text || " "; - this.dirty = true; -}; - -/** - * Set the style of the text - * - * @method setStyle - * @param style {Object} The style parameters - * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously) - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - */ -PIXI.BitmapText.prototype.setStyle = function(style) -{ - style = style || {}; - style.align = style.align || "left"; - this.style = style; - - var font = style.font.split(" "); - this.fontName = font[font.length - 1]; - this.fontSize = font.length >= 2 ? parseInt(font[font.length - 2], 10) : PIXI.BitmapText.fonts[this.fontName].size; - - this.dirty = true; -}; - -/** - * Renders text - * - * @method updateText - * @private - */ -PIXI.BitmapText.prototype.updateText = function() -{ - var data = PIXI.BitmapText.fonts[this.fontName]; - var pos = new PIXI.Point(); - var prevCharCode = null; - var chars = []; - var maxLineWidth = 0; - var lineWidths = []; - var line = 0; - var scale = this.fontSize / data.size; - for(var i = 0; i < this.text.length; i++) - { - var charCode = this.text.charCodeAt(i); - if(/(?:\r\n|\r|\n)/.test(this.text.charAt(i))) - { - lineWidths.push(pos.x); - maxLineWidth = Math.max(maxLineWidth, pos.x); - line++; - - pos.x = 0; - pos.y += data.lineHeight; - prevCharCode = null; - continue; - } - - var charData = data.chars[charCode]; - if(!charData) continue; - - if(prevCharCode && charData[prevCharCode]) - { - pos.x += charData.kerning[prevCharCode]; - } - chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); - pos.x += charData.xAdvance; - - prevCharCode = charCode; - } - - lineWidths.push(pos.x); - maxLineWidth = Math.max(maxLineWidth, pos.x); - - var lineAlignOffsets = []; - for(i = 0; i <= line; i++) - { - var alignOffset = 0; - if(this.style.align == "right") - { - alignOffset = maxLineWidth - lineWidths[i]; - } - else if(this.style.align == "center") - { - alignOffset = (maxLineWidth - lineWidths[i]) / 2; - } - lineAlignOffsets.push(alignOffset); - } - - for(i = 0; i < chars.length; i++) - { - var c = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode); - c.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; - c.position.y = chars[i].position.y * scale; - c.scale.x = c.scale.y = scale; - this.addChild(c); - } - - this.width = pos.x * scale; - this.height = (pos.y + data.lineHeight) * scale; -}; - -/** - * Updates the transfor of this object - * - * @method updateTransform - * @private - */ -PIXI.BitmapText.prototype.updateTransform = function() -{ - if(this.dirty) - { - while(this.children.length > 0) - { - this.removeChild(this.getChildAt(0)); - } - this.updateText(); - - this.dirty = false; - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call(this); -}; - -PIXI.BitmapText.fonts = {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - - -/** - * The interaction manager deals with mouse and touch events. Any DisplayObject can be interactive - * This manager also supports multitouch. - * - * @class InteractionManager - * @constructor - * @param stage {Stage} The stage to handle interactions - */ -PIXI.InteractionManager = function(stage) -{ - /** - * a refference to the stage - * - * @property stage - * @type Stage - */ - this.stage = stage; - - /** - * the mouse data - * - * @property mouse - * @type InteractionData - */ - this.mouse = new PIXI.InteractionData(); - - /** - * an object that stores current touches (InteractionData) by id reference - * - * @property touchs - * @type Object - */ - this.touchs = {}; - - // helpers - this.tempPoint = new PIXI.Point(); - //this.tempMatrix = mat3.create(); - - this.mouseoverEnabled = true; - - //tiny little interactiveData pool! - this.pool = []; - - this.interactiveItems = []; - - this.last = 0; -} - -// constructor -PIXI.InteractionManager.prototype.constructor = PIXI.InteractionManager; - -/** - * Collects an interactive sprite recursively to have their interactions managed - * - * @method collectInteractiveSprite - * @param displayObject {DisplayObject} the displayObject to collect - * @param iParent {DisplayObject} - * @private - */ -PIXI.InteractionManager.prototype.collectInteractiveSprite = function(displayObject, iParent) -{ - var children = displayObject.children; - var length = children.length; - - /// make an interaction tree... {item.__interactiveParent} - for (var i = length-1; i >= 0; i--) - { - var child = children[i]; - - if(child.visible) { - // push all interactive bits - if(child.interactive) - { - iParent.interactiveChildren = true; - //child.__iParent = iParent; - this.interactiveItems.push(child); - - if(child.children.length > 0) - { - this.collectInteractiveSprite(child, child); - } - } - else - { - child.__iParent = null; - - if(child.children.length > 0) - { - this.collectInteractiveSprite(child, iParent); - } - } - } - } -} - -/** - * Sets the target for event delegation - * - * @method setTarget - * @param target {WebGLRenderer|CanvasRenderer} the renderer to bind events to - * @private - */ -PIXI.InteractionManager.prototype.setTarget = function(target) -{ - if (window.navigator.msPointerEnabled) - { - // time to remove some of that zoom in ja.. - target.view.style["-ms-content-zooming"] = "none"; - target.view.style["-ms-touch-action"] = "none" - - // DO some window specific touch! - } - - this.target = target; - target.view.addEventListener('mousemove', this.onMouseMove.bind(this), true); - target.view.addEventListener('mousedown', this.onMouseDown.bind(this), true); - document.body.addEventListener('mouseup', this.onMouseUp.bind(this), true); - target.view.addEventListener('mouseout', this.onMouseUp.bind(this), true); - - // aint no multi touch just yet! - target.view.addEventListener("touchstart", this.onTouchStart.bind(this), true); - target.view.addEventListener("touchend", this.onTouchEnd.bind(this), true); - target.view.addEventListener("touchmove", this.onTouchMove.bind(this), true); -} - -/** - * updates the state of interactive objects - * - * @method update - * @private - */ -PIXI.InteractionManager.prototype.update = function() -{ - if(!this.target)return; - - // frequency of 30fps?? - var now = Date.now(); - var diff = now - this.last; - diff = (diff * 30) / 1000; - if(diff < 1)return; - this.last = now; - // - - // ok.. so mouse events?? - // yes for now :) - // OPTIMSE - how often to check?? - if(this.dirty) - { - this.dirty = false; - - var len = this.interactiveItems.length; - - for (var i=0; i < len; i++) { - this.interactiveItems[i].interactiveChildren = false; - } - - this.interactiveItems = []; - - if(this.stage.interactive)this.interactiveItems.push(this.stage); - // go through and collect all the objects that are interactive.. - this.collectInteractiveSprite(this.stage, this.stage); - } - - // loop through interactive objects! - var length = this.interactiveItems.length; - - this.target.view.style.cursor = "default"; - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - if(!item.visible)continue; - - // OPTIMISATION - only calculate every time if the mousemove function exists.. - // OK so.. does the object have any other interactive functions? - // hit-test the clip! - - - if(item.mouseover || item.mouseout || item.buttonMode) - { - // ok so there are some functions so lets hit test it.. - item.__hit = this.hitTest(item, this.mouse); - this.mouse.target = item; - // ok so deal with interactions.. - // loks like there was a hit! - if(item.__hit) - { - if(item.buttonMode)this.target.view.style.cursor = "pointer"; - - if(!item.__isOver) - { - - if(item.mouseover)item.mouseover(this.mouse); - item.__isOver = true; - } - } - else - { - if(item.__isOver) - { - // roll out! - if(item.mouseout)item.mouseout(this.mouse); - item.__isOver = false; - } - } - } - - // ---> - } -} - -/** - * Is called when the mouse moves accross the renderer element - * - * @method onMouseMove - * @param event {Event} The DOM event of the mouse moving - * @private - */ -PIXI.InteractionManager.prototype.onMouseMove = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - // TODO optimize by not check EVERY TIME! maybe half as often? // - var rect = this.target.view.getBoundingClientRect(); - - this.mouse.global.x = (event.clientX - rect.left) * (this.target.width / rect.width); - this.mouse.global.y = (event.clientY - rect.top) * ( this.target.height / rect.height); - - var length = this.interactiveItems.length; - var global = this.mouse.global; - - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mousemove) - { - //call the function! - item.mousemove(this.mouse); - } - } -} - -/** - * Is called when the mouse button is pressed down on the renderer element - * - * @method onMouseDown - * @param event {Event} The DOM event of a mouse button being pressed down - * @private - */ -PIXI.InteractionManager.prototype.onMouseDown = function(event) -{ - event.preventDefault(); - this.mouse.originalEvent = event || window.event; //IE uses window.event - - // loop through inteaction tree... - // hit test each item! -> - // get interactive items under point?? - //stage.__i - var length = this.interactiveItems.length; - var global = this.mouse.global; - - var index = 0; - var parent = this.stage; - - // while - // hit test - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mousedown || item.click) - { - item.__mouseIsDown = true; - item.__hit = this.hitTest(item, this.mouse); - - if(item.__hit) - { - //call the function! - if(item.mousedown)item.mousedown(this.mouse); - item.__isDown = true; - - // just the one! - if(!item.interactiveChildren)break; - } - } - } -} - -/** - * Is called when the mouse button is released on the renderer element - * - * @method onMouseUp - * @param event {Event} The DOM event of a mouse button being released - * @private - */ -PIXI.InteractionManager.prototype.onMouseUp = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - - var global = this.mouse.global; - - - var length = this.interactiveItems.length; - var up = false; - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mouseup || item.mouseupoutside || item.click) - { - item.__hit = this.hitTest(item, this.mouse); - - if(item.__hit && !up) - { - //call the function! - if(item.mouseup) - { - item.mouseup(this.mouse); - } - if(item.__isDown) - { - if(item.click)item.click(this.mouse); - } - - if(!item.interactiveChildren)up = true; - } - else - { - if(item.__isDown) - { - if(item.mouseupoutside)item.mouseupoutside(this.mouse); - } - } - - item.__isDown = false; - } - } -} - -/** - * Tests if the current mouse coords hit a sprite - * - * @method hitTest - * @param item {DisplayObject} The displayObject to test for a hit - * @param interactionData {InteractionData} The interactiondata object to update in the case of a hit - * @private - */ -PIXI.InteractionManager.prototype.hitTest = function(item, interactionData) -{ - var global = interactionData.global; - - if(!item.visible)return false; - - var isSprite = (item instanceof PIXI.Sprite), - worldTransform = item.worldTransform, - a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2], - a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5], - id = 1 / (a00 * a11 + a01 * -a10), - x = a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id, - y = a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id; - - interactionData.target = item; - - //a sprite or display object with a hit area defined - if(item.hitArea && item.hitArea.contains) { - if(item.hitArea.contains(x, y)) { - //if(isSprite) - interactionData.target = item; - - return true; - } - - return false; - } - // a sprite with no hitarea defined - else if(isSprite) - { - var width = item.texture.frame.width, - height = item.texture.frame.height, - x1 = -width * item.anchor.x, - y1; - - if(x > x1 && x < x1 + width) - { - y1 = -height * item.anchor.y; - - if(y > y1 && y < y1 + height) - { - // set the target property if a hit is true! - interactionData.target = item - return true; - } - } - } - - var length = item.children.length; - - for (var i = 0; i < length; i++) - { - var tempItem = item.children[i]; - var hit = this.hitTest(tempItem, interactionData); - if(hit) - { - // hmm.. TODO SET CORRECT TARGET? - interactionData.target = item - return true; - } - } - - return false; -} - -/** - * Is called when a touch is moved accross the renderer element - * - * @method onTouchMove - * @param event {Event} The DOM event of a touch moving accross the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchMove = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - var rect = this.target.view.getBoundingClientRect(); - var changedTouches = event.changedTouches; - - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - var touchData = this.touchs[touchEvent.identifier]; - - // update the touch position - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - } - - var length = this.interactiveItems.length; - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - if(item.touchmove)item.touchmove(touchData); - } -} - -/** - * Is called when a touch is started on the renderer element - * - * @method onTouchStart - * @param event {Event} The DOM event of a touch starting on the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchStart = function(event) -{ - event.preventDefault(); - this.mouse.originalEvent = event || window.event; //IE uses window.event - - var rect = this.target.view.getBoundingClientRect(); - - var changedTouches = event.changedTouches; - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - - var touchData = this.pool.pop(); - if(!touchData)touchData = new PIXI.InteractionData(); - - this.touchs[touchEvent.identifier] = touchData; - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - - var length = this.interactiveItems.length; - - for (var j = 0; j < length; j++) - { - var item = this.interactiveItems[j]; - - if(item.touchstart || item.tap) - { - item.__hit = this.hitTest(item, touchData); - - if(item.__hit) - { - //call the function! - if(item.touchstart)item.touchstart(touchData); - item.__isDown = true; - item.__touchData = touchData; - - if(!item.interactiveChildren)break; - } - } - } - } -} - -/** - * Is called when a touch is ended on the renderer element - * - * @method onTouchEnd - * @param event {Event} The DOM event of a touch ending on the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchEnd = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - var rect = this.target.view.getBoundingClientRect(); - var changedTouches = event.changedTouches; - - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - var touchData = this.touchs[touchEvent.identifier]; - var up = false; - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - - var length = this.interactiveItems.length; - for (var j = 0; j < length; j++) - { - var item = this.interactiveItems[j]; - var itemTouchData = item.__touchData; // <-- Here! - item.__hit = this.hitTest(item, touchData); - - if(itemTouchData == touchData) - { - // so this one WAS down... - - // hitTest?? - - if(item.touchend || item.tap) - { - if(item.__hit && !up) - { - if(item.touchend)item.touchend(touchData); - if(item.__isDown) - { - if(item.tap)item.tap(touchData); - } - - if(!item.interactiveChildren)up = true; - } - else - { - if(item.__isDown) - { - if(item.touchendoutside)item.touchendoutside(touchData); - } - } - - item.__isDown = false; - } - - item.__touchData = null; - - } - else - { - - } - } - // remove the touch.. - this.pool.push(touchData); - this.touchs[touchEvent.identifier] = null; - } -} - -/** - * Holds all information related to an Interaction event - * - * @class InteractionData - * @constructor - */ -PIXI.InteractionData = function() -{ - /** - * This point stores the global coords of where the touch/mouse event happened - * - * @property global - * @type Point - */ - this.global = new PIXI.Point(); - - // this is here for legacy... but will remove - this.local = new PIXI.Point(); - - /** - * The target Sprite that was interacted with - * - * @property target - * @type Sprite - */ - this.target; - - /** - * When passed to an event handler, this will be the original DOM Event that was captured - * - * @property originalEvent - * @type Event - */ - this.originalEvent; -} - -/** - * This will return the local coords of the specified displayObject for this InteractionData - * - * @method getLocalPosition - * @param displayObject {DisplayObject} The DisplayObject that you would like the local coords off - * @return {Point} A point containing the coords of the InteractionData position relative to the DisplayObject - */ -PIXI.InteractionData.prototype.getLocalPosition = function(displayObject) -{ - var worldTransform = displayObject.worldTransform; - var global = this.global; - - // do a cheeky transform to get the mouse coords; - var a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2], - a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5], - id = 1 / (a00 * a11 + a01 * -a10); - // set the mouse coords... - return new PIXI.Point(a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id, - a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id) -} - -// constructor -PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Stage represents the root of the display tree. Everything connected to the stage is rendered - * - * @class Stage - * @extends DisplayObjectContainer - * @constructor - * @param backgroundColor {Number} the background color of the stage, easiest way to pass this in is in hex format - * like: 0xFFFFFF for white - * @param interactive {Boolean} enable / disable interaction (default is false) - */ -PIXI.Stage = function(backgroundColor, interactive) -{ - PIXI.DisplayObjectContainer.call( this ); - - /** - * [read-only] Current transform of the object based on world (parent) factors - * - * @property worldTransform - * @type Mat3 - * @readOnly - * @private - */ - this.worldTransform = PIXI.mat3.create(); - - /** - * Whether or not the stage is interactive - * - * @property interactive - * @type Boolean - */ - this.interactive = interactive; - - /** - * The interaction manage for this stage, manages all interactive activity on the stage - * - * @property interactive - * @type InteractionManager - */ - this.interactionManager = new PIXI.InteractionManager(this); - - /** - * Whether the stage is dirty and needs to have interactions updated - * - * @property dirty - * @type Boolean - * @private - */ - this.dirty = true; - - this.__childrenAdded = []; - this.__childrenRemoved = []; - - //the stage is it's own stage - this.stage = this; - - //optimize hit detection a bit - this.stage.hitArea = new PIXI.Rectangle(0,0,100000, 100000); - - this.setBackgroundColor(backgroundColor); - this.worldVisible = true; -} - -// constructor -PIXI.Stage.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Stage.prototype.constructor = PIXI.Stage; - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.Stage.prototype.updateTransform = function() -{ - this.worldAlpha = 1; - - for(var i=0,j=this.children.length; i> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; -} - -/** - * A polyfill for Function.prototype.bind - * - * @method bind - */ -if (typeof Function.prototype.bind != 'function') { - Function.prototype.bind = (function () { - var slice = Array.prototype.slice; - return function (thisArg) { - var target = this, boundArgs = slice.call(arguments, 1); - - if (typeof target != 'function') throw new TypeError(); - - function bound() { - var args = boundArgs.concat(slice.call(arguments)); - target.apply(this instanceof bound ? this : thisArg, args); - } - - bound.prototype = (function F(proto) { - proto && (F.prototype = proto); - if (!(this instanceof F)) return new F; - })(target.prototype); - - return bound; - }; - })(); -} - -/** - * A wrapper for ajax requests to be handled cross browser - * - * @class AjaxRequest - * @constructor - */ -var AjaxRequest = PIXI.AjaxRequest = function() -{ - var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE - - if (window.ActiveXObject) - { //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken) - for (var i=0; i>>>>>>>>") - console.log("_") - var safe = 0; - var tmp = item.first; - console.log(tmp); - - while(tmp._iNext) - { - safe++; -// console.log(tmp.childIndex + tmp); - tmp = tmp._iNext; - console.log(tmp);//.childIndex); - // console.log(tmp); - - if(safe > 100) - { - console.log("BREAK") - break - } - } -} - - - - - - -/** - * https://github.com/mrdoob/eventtarget.js/ - * THankS mr DOob! - */ - -/** - * Adds event emitter functionality to a class - * - * @class EventTarget - * @example - * function MyEmitter() { - * PIXI.EventTarget.call(this); //mixes in event target stuff - * } - * - * var em = new MyEmitter(); - * em.emit({ type: 'eventName', data: 'some data' }); - */ -PIXI.EventTarget = function () { - - var listeners = {}; - - this.addEventListener = this.on = function ( type, listener ) { - - - if ( listeners[ type ] === undefined ) { - - listeners[ type ] = []; - - } - - if ( listeners[ type ].indexOf( listener ) === - 1 ) { - - listeners[ type ].push( listener ); - } - - }; - - this.dispatchEvent = this.emit = function ( event ) { - - for ( var listener in listeners[ event.type ] ) { - - listeners[ event.type ][ listener ]( event ); - - } - - }; - - this.removeEventListener = this.off = function ( type, listener ) { - - var index = listeners[ type ].indexOf( listener ); - - if ( index !== - 1 ) { - - listeners[ type ].splice( index, 1 ); - - } - - }; - -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * This helper function will automatically detect which renderer you should be using. - * WebGL is the preferred renderer as it is a lot fastest. If webGL is not supported by - * the browser then this function will return a canvas renderer - * - * @method autoDetectRenderer - * @static - * @param width {Number} the width of the renderers view - * @param height {Number} the height of the renderers view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - */ -PIXI.autoDetectRenderer = function(width, height, view, transparent) -{ - if(!width)width = 800; - if(!height)height = 600; - - // BORROWED from Mr Doob (mrdoob.com) - var webgl = ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )(); - - //console.log(webgl); - if( webgl ) - { - return new PIXI.WebGLRenderer(width, height, view, transparent); - } - - return new PIXI.CanvasRenderer(width, height, view, transparent); -}; - - - -/* - PolyK library - url: http://polyk.ivank.net - Released under MIT licence. - - Copyright (c) 2012 Ivan Kuckir - - 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. - - This is an amazing lib! - - slightly modified by mat groves (matgroves.com); -*/ - -PIXI.PolyK = {}; - -/** - * Triangulates shapes for webGL graphic fills - * - * @method Triangulate - * @namespace PolyK - * @constructor - */ -PIXI.PolyK.Triangulate = function(p) -{ - var sign = true; - - var n = p.length>>1; - if(n<3) return []; - var tgs = []; - var avl = []; - for(var i=0; i 3) - { - var i0 = avl[(i+0)%al]; - var i1 = avl[(i+1)%al]; - var i2 = avl[(i+2)%al]; - - var ax = p[2*i0], ay = p[2*i0+1]; - var bx = p[2*i1], by = p[2*i1+1]; - var cx = p[2*i2], cy = p[2*i2+1]; - - var earFound = false; - if(PIXI.PolyK._convex(ax, ay, bx, by, cx, cy, sign)) - { - earFound = true; - for(var j=0; j 3*al) - { - // need to flip flip reverse it! - // reset! - if(sign) - { - var tgs = []; - avl = []; - for(var i=0; i= 0) && (v >= 0) && (u + v < 1); -} - -/** - * Checks if a shape is convex - * - * @class _convex - * @namespace PolyK - * @private - */ -PIXI.PolyK._convex = function(ax, ay, bx, by, cx, cy, sign) -{ - return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) == sign; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/* - * the default suoer fast shader! - */ - -PIXI.shaderFragmentSrc = [ - "precision mediump float;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "uniform sampler2D uSampler;", - "void main(void) {", - "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));", - "gl_FragColor = gl_FragColor * vColor;", - "}" -]; - -PIXI.shaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec2 aTextureCoord;", - "attribute float aColor;", - //"uniform mat4 uMVMatrix;", - - "uniform vec2 projectionVector;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "void main(void) {", - // "gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0, 1.0);", - "gl_Position = vec4( aVertexPosition.x / projectionVector.x -1.0, aVertexPosition.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vTextureCoord = aTextureCoord;", - "vColor = aColor;", - "}" -]; - -/* - * the triangle strip shader.. - */ - -PIXI.stripShaderFragmentSrc = [ - "precision mediump float;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "uniform float alpha;", - "uniform sampler2D uSampler;", - "void main(void) {", - "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));", - "gl_FragColor = gl_FragColor * alpha;", - "}" -]; - - -PIXI.stripShaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec2 aTextureCoord;", - "attribute float aColor;", - "uniform mat3 translationMatrix;", - "uniform vec2 projectionVector;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "void main(void) {", - "vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);", - "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vTextureCoord = aTextureCoord;", - "vColor = aColor;", - "}" -]; - - -/* - * primitive shader.. - */ - -PIXI.primitiveShaderFragmentSrc = [ - "precision mediump float;", - "varying vec4 vColor;", - "void main(void) {", - "gl_FragColor = vColor;", - "}" -]; - -PIXI.primitiveShaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec4 aColor;", - "uniform mat3 translationMatrix;", - "uniform vec2 projectionVector;", - "uniform float alpha;", - "varying vec4 vColor;", - "void main(void) {", - "vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);", - "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vColor = aColor * alpha;", - "}" -]; - -PIXI.initPrimitiveShader = function() -{ - var gl = PIXI.gl; - - var shaderProgram = PIXI.compileProgram(PIXI.primitiveShaderVertexSrc, PIXI.primitiveShaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, "translationMatrix"); - - shaderProgram.alpha = gl.getUniformLocation(shaderProgram, "alpha"); - - PIXI.primitiveProgram = shaderProgram; -} - -PIXI.initDefaultShader = function() -{ - var gl = this.gl; - var shaderProgram = PIXI.compileProgram(PIXI.shaderVertexSrc, PIXI.shaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord"); - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - // shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix"); - shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler"); - - PIXI.shaderProgram = shaderProgram; -} - -PIXI.initDefaultStripShader = function() -{ - var gl = this.gl; - var shaderProgram = PIXI.compileProgram(PIXI.stripShaderVertexSrc, PIXI.stripShaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord"); - shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, "translationMatrix"); - shaderProgram.alpha = gl.getUniformLocation(shaderProgram, "alpha"); - - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - - shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler"); - - PIXI.stripShaderProgram = shaderProgram; -} - -PIXI.CompileVertexShader = function(gl, shaderSrc) -{ - return PIXI._CompileShader(gl, shaderSrc, gl.VERTEX_SHADER); -} - -PIXI.CompileFragmentShader = function(gl, shaderSrc) -{ - return PIXI._CompileShader(gl, shaderSrc, gl.FRAGMENT_SHADER); -} - -PIXI._CompileShader = function(gl, shaderSrc, shaderType) -{ - var src = shaderSrc.join("\n"); - var shader = gl.createShader(shaderType); - gl.shaderSource(shader, src); - gl.compileShader(shader); - - if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { - alert(gl.getShaderInfoLog(shader)); - return null; - } - - return shader; -} - - -PIXI.compileProgram = function(vertexSrc, fragmentSrc) -{ - var gl = PIXI.gl; - var fragmentShader = PIXI.CompileFragmentShader(gl, fragmentSrc); - var vertexShader = PIXI.CompileVertexShader(gl, vertexSrc); - - var shaderProgram = gl.createProgram(); - - gl.attachShader(shaderProgram, vertexShader); - gl.attachShader(shaderProgram, fragmentShader); - gl.linkProgram(shaderProgram); - - if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) { - alert("Could not initialise shaders"); - } - - return shaderProgram; -} - - -PIXI.activateDefaultShader = function() -{ - var gl = PIXI.gl; - var shaderProgram = PIXI.shaderProgram; - - gl.useProgram(shaderProgram); - - - gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute); - gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute); - gl.enableVertexAttribArray(shaderProgram.colorAttribute); -} - - - -PIXI.activatePrimitiveShader = function() -{ - var gl = PIXI.gl; - - gl.disableVertexAttribArray(PIXI.shaderProgram.textureCoordAttribute); - gl.disableVertexAttribArray(PIXI.shaderProgram.colorAttribute); - - gl.useProgram(PIXI.primitiveProgram); - - gl.enableVertexAttribArray(PIXI.primitiveProgram.vertexPositionAttribute); - gl.enableVertexAttribArray(PIXI.primitiveProgram.colorAttribute); -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A set of functions used by the webGL renderer to draw the primitive graphics data - * - * @class CanvasGraphics - */ -PIXI.WebGLGraphics = function() -{ - -} - -/** - * Renders the graphics object - * - * @static - * @private - * @method renderGraphics - * @param graphics {Graphics} - * @param projection {Object} - */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) -{ - var gl = PIXI.gl; - - if(!graphics._webGL)graphics._webGL = {points:[], indices:[], lastIndex:0, - buffer:gl.createBuffer(), - indexBuffer:gl.createBuffer()}; - - if(graphics.dirty) - { - graphics.dirty = false; - - if(graphics.clearDirty) - { - graphics.clearDirty = false; - - graphics._webGL.lastIndex = 0; - graphics._webGL.points = []; - graphics._webGL.indices = []; - - } - - PIXI.WebGLGraphics.updateGraphics(graphics); - } - - - PIXI.activatePrimitiveShader(); - - // This could be speeded up fo sure! - var m = PIXI.mat3.clone(graphics.worldTransform); - - PIXI.mat3.transpose(m); - - // set the matrix transform for the - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - - gl.uniformMatrix3fv(PIXI.primitiveProgram.translationMatrix, false, m); - - gl.uniform2f(PIXI.primitiveProgram.projectionVector, projection.x, projection.y); - - gl.uniform1f(PIXI.primitiveProgram.alpha, graphics.worldAlpha); - - gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer); - - // WHY DOES THIS LINE NEED TO BE THERE??? - gl.vertexAttribPointer(PIXI.shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - // its not even used.. but need to be set or it breaks? - // only on pc though.. - - gl.vertexAttribPointer(PIXI.primitiveProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 4 * 6, 0); - gl.vertexAttribPointer(PIXI.primitiveProgram.colorAttribute, 4, gl.FLOAT, false,4 * 6, 2 * 4); - - // set the index buffer! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer); - - gl.drawElements(gl.TRIANGLE_STRIP, graphics._webGL.indices.length, gl.UNSIGNED_SHORT, 0 ); - - // return to default shader... - PIXI.activateDefaultShader(); -} - -/** - * Updates the graphics object - * - * @static - * @private - * @method updateGraphics - * @param graphics {Graphics} - */ -PIXI.WebGLGraphics.updateGraphics = function(graphics) -{ - for (var i=graphics._webGL.lastIndex; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - - if(data.type == PIXI.Graphics.POLY) - { - if(data.fill) - { - if(data.points.length>3) - PIXI.WebGLGraphics.buildPoly(data, graphics._webGL); - } - - if(data.lineWidth > 0) - { - PIXI.WebGLGraphics.buildLine(data, graphics._webGL); - } - } - else if(data.type == PIXI.Graphics.RECT) - { - PIXI.WebGLGraphics.buildRectangle(data, graphics._webGL); - } - else if(data.type == PIXI.Graphics.CIRC || data.type == PIXI.Graphics.ELIP) - { - PIXI.WebGLGraphics.buildCircle(data, graphics._webGL); - } - }; - - graphics._webGL.lastIndex = graphics.graphicsData.length; - - var gl = PIXI.gl; - - graphics._webGL.glPoints = new Float32Array(graphics._webGL.points); - - gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer); - gl.bufferData(gl.ARRAY_BUFFER, graphics._webGL.glPoints, gl.STATIC_DRAW); - - graphics._webGL.glIndicies = new Uint16Array(graphics._webGL.indices); - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.glIndicies, gl.STATIC_DRAW); -} - -/** - * Builds a rectangle to draw - * - * @static - * @private - * @method buildRectangle - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData) -{ - // --- // - // need to convert points to a nice regular data - // - var rectData = graphicsData.points; - var x = rectData[0]; - var y = rectData[1]; - var width = rectData[2]; - var height = rectData[3]; - - - if(graphicsData.fill) - { - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vertPos = verts.length/6; - - // start - verts.push(x, y); - verts.push(r, g, b, alpha); - - verts.push(x + width, y); - verts.push(r, g, b, alpha); - - verts.push(x , y + height); - verts.push(r, g, b, alpha); - - verts.push(x + width, y + height); - verts.push(r, g, b, alpha); - - // insert 2 dead triangles.. - indices.push(vertPos, vertPos, vertPos+1, vertPos+2, vertPos+3, vertPos+3) - } - - if(graphicsData.lineWidth) - { - graphicsData.points = [x, y, - x + width, y, - x + width, y + height, - x, y + height, - x, y]; - - PIXI.WebGLGraphics.buildLine(graphicsData, webGLData); - } - -} - -/** - * Builds a circle to draw - * - * @static - * @private - * @method buildCircle - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildCircle = function(graphicsData, webGLData) -{ - // --- // - // need to convert points to a nice regular data - // - var rectData = graphicsData.points; - var x = rectData[0]; - var y = rectData[1]; - var width = rectData[2]; - var height = rectData[3]; - - var totalSegs = 40; - var seg = (Math.PI * 2) / totalSegs ; - - if(graphicsData.fill) - { - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vecPos = verts.length/6; - - indices.push(vecPos); - - for (var i=0; i < totalSegs + 1 ; i++) - { - verts.push(x,y, r, g, b, alpha); - - verts.push(x + Math.sin(seg * i) * width, - y + Math.cos(seg * i) * height, - r, g, b, alpha); - - indices.push(vecPos++, vecPos++); - }; - - indices.push(vecPos-1); - } - - if(graphicsData.lineWidth) - { - graphicsData.points = []; - - for (var i=0; i < totalSegs + 1; i++) - { - graphicsData.points.push(x + Math.sin(seg * i) * width, - y + Math.cos(seg * i) * height) - }; - - PIXI.WebGLGraphics.buildLine(graphicsData, webGLData); - } - -} - -/** - * Builds a line to draw - * - * @static - * @private - * @method buildLine - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData) -{ - // TODO OPTIMISE! - - var wrap = true; - var points = graphicsData.points; - if(points.length == 0)return; - - // get first and last point.. figure out the middle! - var firstPoint = new PIXI.Point( points[0], points[1] ); - var lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] ); - - // if the first point is the last point - goona have issues :) - if(firstPoint.x == lastPoint.x && firstPoint.y == lastPoint.y) - { - points.pop(); - points.pop(); - - lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] ); - - var midPointX = lastPoint.x + (firstPoint.x - lastPoint.x) *0.5; - var midPointY = lastPoint.y + (firstPoint.y - lastPoint.y) *0.5; - - points.unshift(midPointX, midPointY); - points.push(midPointX, midPointY) - } - - var verts = webGLData.points; - var indices = webGLData.indices; - var length = points.length / 2; - var indexCount = points.length; - var indexStart = verts.length/6; - - // DRAW the Line - var width = graphicsData.lineWidth / 2; - - // sort color - var color = HEXtoRGB(graphicsData.lineColor); - var alpha = graphicsData.lineAlpha; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var p1x, p1y, p2x, p2y, p3x, p3y; - var perpx, perpy, perp2x, perp2y, perp3x, perp3y; - var ipx, ipy; - var a1, b1, c1, a2, b2, c2; - var denom, pdist, dist; - - p1x = points[0]; - p1y = points[1]; - - p2x = points[2]; - p2y = points[3]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - // start - verts.push(p1x - perpx , p1y - perpy, - r, g, b, alpha); - - verts.push(p1x + perpx , p1y + perpy, - r, g, b, alpha); - - for (var i = 1; i < length-1; i++) - { - p1x = points[(i-1)*2]; - p1y = points[(i-1)*2 + 1]; - - p2x = points[(i)*2] - p2y = points[(i)*2 + 1] - - p3x = points[(i+1)*2]; - p3y = points[(i+1)*2 + 1]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - perp2x = -(p2y - p3y); - perp2y = p2x - p3x; - - dist = Math.sqrt(perp2x*perp2x + perp2y*perp2y); - perp2x /= dist; - perp2y /= dist; - perp2x *= width; - perp2y *= width; - - a1 = (-perpy + p1y) - (-perpy + p2y); - b1 = (-perpx + p2x) - (-perpx + p1x); - c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y); - a2 = (-perp2y + p3y) - (-perp2y + p2y); - b2 = (-perp2x + p2x) - (-perp2x + p3x); - c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y); - - denom = a1*b2 - a2*b1; - - if (denom == 0) { - denom+=1; - } - - px = (b1*c2 - b2*c1)/denom; - py = (a2*c1 - a1*c2)/denom; - - pdist = (px -p2x) * (px -p2x) + (py -p2y) + (py -p2y); - - if(pdist > 140 * 140) - { - perp3x = perpx - perp2x; - perp3y = perpy - perp2y; - - dist = Math.sqrt(perp3x*perp3x + perp3y*perp3y); - perp3x /= dist; - perp3y /= dist; - perp3x *= width; - perp3y *= width; - - verts.push(p2x - perp3x, p2y -perp3y); - verts.push(r, g, b, alpha); - - verts.push(p2x + perp3x, p2y +perp3y); - verts.push(r, g, b, alpha); - - verts.push(p2x - perp3x, p2y -perp3y); - verts.push(r, g, b, alpha); - - indexCount++; - } - else - { - verts.push(px , py); - verts.push(r, g, b, alpha); - - verts.push(p2x - (px-p2x), p2y - (py - p2y));//, 4); - verts.push(r, g, b, alpha); - } - } - - p1x = points[(length-2)*2] - p1y = points[(length-2)*2 + 1] - - p2x = points[(length-1)*2] - p2y = points[(length-1)*2 + 1] - - perpx = -(p1y - p2y) - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - verts.push(p2x - perpx , p2y - perpy) - verts.push(r, g, b, alpha); - - verts.push(p2x + perpx , p2y + perpy) - verts.push(r, g, b, alpha); - - indices.push(indexStart); - - for (var i=0; i < indexCount; i++) - { - indices.push(indexStart++); - }; - - indices.push(indexStart-1); -} - -/** - * Builds a polygon to draw - * - * @static - * @private - * @method buildPoly - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildPoly = function(graphicsData, webGLData) -{ - var points = graphicsData.points; - if(points.length < 6)return; - - // get first and last point.. figure out the middle! - var verts = webGLData.points; - var indices = webGLData.indices; - - var length = points.length / 2; - - // sort color - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var triangles = PIXI.PolyK.Triangulate(points); - - var vertPos = verts.length / 6; - - for (var i=0; i < triangles.length; i+=3) - { - indices.push(triangles[i] + vertPos); - indices.push(triangles[i] + vertPos); - indices.push(triangles[i+1] + vertPos); - indices.push(triangles[i+2] +vertPos); - indices.push(triangles[i+2] + vertPos); - }; - - for (var i = 0; i < length; i++) - { - verts.push(points[i * 2], points[i * 2 + 1], - r, g, b, alpha); - }; -} - -function HEXtoRGB(hex) { - return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; -} - - - - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI._defaultFrame = new PIXI.Rectangle(0,0,1,1); - -// an instance of the gl context.. -// only one at the moment :/ -PIXI.gl; - -/** - * the WebGLRenderer is draws the stage and all its content onto a webGL enabled canvas. This renderer - * should be used for browsers support webGL. This Render works by automatically managing webGLBatchs. - * So no need for Sprite Batch's or Sprite Cloud's - * Dont forget to add the view to your DOM or you will not see anything :) - * - * @class WebGLRenderer - * @constructor - * @param width=0 {Number} the width of the canvas view - * @param height=0 {Number} the height of the canvas view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - * - */ -PIXI.WebGLRenderer = function(width, height, view, transparent) -{ - // do a catch.. only 1 webGL renderer.. - - this.transparent = !!transparent; - - this.width = width || 800; - this.height = height || 600; - - this.view = view || document.createElement( 'canvas' ); - this.view.width = this.width; - this.view.height = this.height; - - // deal with losing context.. - var scope = this; - this.view.addEventListener('webglcontextlost', function(event) { scope.handleContextLost(event); }, false) - this.view.addEventListener('webglcontextrestored', function(event) { scope.handleContextRestored(event); }, false) - - this.batchs = []; - - try - { - PIXI.gl = this.gl = this.view.getContext("experimental-webgl", { - alpha: this.transparent, - antialias:true, // SPEED UP?? - premultipliedAlpha:false, - stencil:true - }); - } - catch (e) - { - throw new Error(" This browser does not support webGL. Try using the canvas renderer" + this); - } - - PIXI.initPrimitiveShader(); - PIXI.initDefaultShader(); - PIXI.initDefaultStripShader(); - - PIXI.activateDefaultShader(); - - var gl = this.gl; - PIXI.WebGLRenderer.gl = gl; - - this.batch = new PIXI.WebGLBatch(gl); - gl.disable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); - - gl.enable(gl.BLEND); - gl.colorMask(true, true, true, this.transparent); - - PIXI.projection = new PIXI.Point(400, 300); - - this.resize(this.width, this.height); - this.contextLost = false; - - this.stageRenderGroup = new PIXI.WebGLRenderGroup(this.gl); -} - -// constructor -PIXI.WebGLRenderer.prototype.constructor = PIXI.WebGLRenderer; - -/** - * Gets a new WebGLBatch from the pool - * - * @static - * @method getBatch - * @return {WebGLBatch} - * @private - */ -PIXI.WebGLRenderer.getBatch = function() -{ - if(PIXI._batchs.length == 0) - { - return new PIXI.WebGLBatch(PIXI.WebGLRenderer.gl); - } - else - { - return PIXI._batchs.pop(); - } -} - -/** - * Puts a batch back into the pool - * - * @static - * @method returnBatch - * @param batch {WebGLBatch} The batch to return - * @private - */ -PIXI.WebGLRenderer.returnBatch = function(batch) -{ - batch.clean(); - PIXI._batchs.push(batch); -} - -/** - * Renders the stage to its webGL view - * - * @method render - * @param stage {Stage} the Stage element to be rendered - */ -PIXI.WebGLRenderer.prototype.render = function(stage) -{ - if(this.contextLost)return; - - - // if rendering a new stage clear the batchs.. - if(this.__stage !== stage) - { - // TODO make this work - // dont think this is needed any more? - //if(this.__stage)this.checkVisibility(this.__stage, false) - - this.__stage = stage; - this.stageRenderGroup.setRenderable(stage); - } - - // TODO not needed now... - // update children if need be - // best to remove first! - /*for (var i=0; i < stage.__childrenRemoved.length; i++) - { - var group = stage.__childrenRemoved[i].__renderGroup - if(group)group.removeDisplayObject(stage.__childrenRemoved[i]); - }*/ - - // update any textures - PIXI.WebGLRenderer.updateTextures(); - - // recursivly loop through all items! - //this.checkVisibility(stage, true); - - // update the scene graph - stage.updateTransform(); - - var gl = this.gl; - - // -- Does this need to be set every frame? -- // - gl.colorMask(true, true, true, this.transparent); - gl.viewport(0, 0, this.width, this.height); - - // set the correct matrix.. - // gl.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform, false, this.projectionMatrix); - - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - - gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); - gl.clear(gl.COLOR_BUFFER_BIT); - - // HACK TO TEST - //PIXI.projectionMatrix = this.projectionMatrix; - - this.stageRenderGroup.backgroundColor = stage.backgroundColorSplit; - this.stageRenderGroup.render(PIXI.projection); - - // interaction - // run interaction! - if(stage.interactive) - { - //need to add some events! - if(!stage._interactiveEventsAdded) - { - stage._interactiveEventsAdded = true; - stage.interactionManager.setTarget(this); - } - } - - // after rendering lets confirm all frames that have been uodated.. - if(PIXI.Texture.frameUpdates.length > 0) - { - for (var i=0; i < PIXI.Texture.frameUpdates.length; i++) - { - PIXI.Texture.frameUpdates[i].updateFrame = false; - }; - - PIXI.Texture.frameUpdates = []; - } -} - -/** - * Updates the textures loaded into this webgl renderer - * - * @static - * @method updateTextures - * @private - */ -PIXI.WebGLRenderer.updateTextures = function() -{ - for (var i=0; i < PIXI.texturesToUpdate.length; i++) this.updateTexture(PIXI.texturesToUpdate[i]); - for (var i=0; i < PIXI.texturesToDestroy.length; i++) this.destroyTexture(PIXI.texturesToDestroy[i]); - PIXI.texturesToUpdate = []; - PIXI.texturesToDestroy = []; -} - -/** - * Updates a loaded webgl texture - * - * @static - * @method updateTexture - * @param texture {Texture} The texture to update - * @private - */ -PIXI.WebGLRenderer.updateTexture = function(texture) -{ - var gl = PIXI.gl; - - if(!texture._glTexture) - { - texture._glTexture = gl.createTexture(); - } - - if(texture.hasLoaded) - { - gl.bindTexture(gl.TEXTURE_2D, texture._glTexture); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true); - - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - - // reguler... - - if(!texture._powerOf2) - { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - } - else - { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); - } - - gl.bindTexture(gl.TEXTURE_2D, null); - } -} - -/** - * Destroys a loaded webgl texture - * - * @method destroyTexture - * @param texture {Texture} The texture to update - * @private - */ -PIXI.WebGLRenderer.prototype.destroyTexture = function(texture) -{ - var gl = this.gl; - - if(texture._glTexture) - { - texture._glTexture = gl.createTexture(); - gl.deleteTexture(gl.TEXTURE_2D, texture._glTexture); - } -} - -/** - * resizes the webGL view to the specified width and height - * - * @method resize - * @param width {Number} the new width of the webGL view - * @param height {Number} the new height of the webGL view - */ -PIXI.WebGLRenderer.prototype.resize = function(width, height) -{ - this.width = width; - this.height = height; - - this.view.width = width; - this.view.height = height; - - this.gl.viewport(0, 0, this.width, this.height); - - //var projectionMatrix = this.projectionMatrix; - - PIXI.projection.x = this.width/2; - PIXI.projection.y = this.height/2; - -// projectionMatrix[0] = 2/this.width; -// projectionMatrix[5] = -2/this.height; -// projectionMatrix[12] = -1; -// projectionMatrix[13] = 1; -} - -/** - * Handles a lost webgl context - * - * @method handleContextLost - * @param event {Event} - * @private - */ -PIXI.WebGLRenderer.prototype.handleContextLost = function(event) -{ - event.preventDefault(); - this.contextLost = true; -} - -/** - * Handles a restored webgl context - * - * @method handleContextRestored - * @param event {Event} - * @private - */ -PIXI.WebGLRenderer.prototype.handleContextRestored = function(event) -{ - this.gl = this.view.getContext("experimental-webgl", { - alpha: true - }); - - this.initShaders(); - - for(var key in PIXI.TextureCache) - { - var texture = PIXI.TextureCache[key].baseTexture; - texture._glTexture = null; - PIXI.WebGLRenderer.updateTexture(texture); - }; - - for (var i=0; i < this.batchs.length; i++) - { - this.batchs[i].restoreLostContext(this.gl)// - this.batchs[i].dirty = true; - }; - - PIXI._restoreBatchs(this.gl); - - this.contextLost = false; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI._batchs = []; - -/** - * @private - */ -PIXI._getBatch = function(gl) -{ - if(PIXI._batchs.length == 0) - { - return new PIXI.WebGLBatch(gl); - } - else - { - return PIXI._batchs.pop(); - } -} - -/** - * @private - */ -PIXI._returnBatch = function(batch) -{ - batch.clean(); - PIXI._batchs.push(batch); -} - -/** - * @private - */ -PIXI._restoreBatchs = function(gl) -{ - for (var i=0; i < PIXI._batchs.length; i++) - { - PIXI._batchs[i].restoreLostContext(gl); - }; -} - -/** - * A WebGLBatch Enables a group of sprites to be drawn using the same settings. - * if a group of sprites all have the same baseTexture and blendMode then they can be grouped into a batch. - * All the sprites in a batch can then be drawn in one go by the GPU which is hugely efficient. ALL sprites - * in the webGL renderer are added to a batch even if the batch only contains one sprite. Batching is handled - * automatically by the webGL renderer. A good tip is: the smaller the number of batchs there are, the faster - * the webGL renderer will run. - * - * @class WebGLBatch - * @constructor - * @param gl {WebGLContext} an instance of the webGL context - */ -PIXI.WebGLBatch = function(gl) -{ - this.gl = gl; - - this.size = 0; - - this.vertexBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - this.uvBuffer = gl.createBuffer(); - this.colorBuffer = gl.createBuffer(); - this.blendMode = PIXI.blendModes.NORMAL; - this.dynamicSize = 1; -} - -// constructor -PIXI.WebGLBatch.prototype.constructor = PIXI.WebGLBatch; - -/** - * Cleans the batch so that is can be returned to an object pool and reused - * - * @method clean - */ -PIXI.WebGLBatch.prototype.clean = function() -{ - this.verticies = []; - this.uvs = []; - this.indices = []; - this.colors = []; - //this.sprites = []; - this.dynamicSize = 1; - this.texture = null; - this.last = null; - this.size = 0; - this.head; - this.tail; -} - -/** - * Recreates the buffers in the event of a context loss - * - * @method restoreLostContext - * @param gl {WebGLContext} - */ -PIXI.WebGLBatch.prototype.restoreLostContext = function(gl) -{ - this.gl = gl; - this.vertexBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - this.uvBuffer = gl.createBuffer(); - this.colorBuffer = gl.createBuffer(); -} - -/** - * inits the batch's texture and blend mode based if the supplied sprite - * - * @method init - * @param sprite {Sprite} the first sprite to be added to the batch. Only sprites with - * the same base texture and blend mode will be allowed to be added to this batch - */ -PIXI.WebGLBatch.prototype.init = function(sprite) -{ - sprite.batch = this; - this.dirty = true; - this.blendMode = sprite.blendMode; - this.texture = sprite.texture.baseTexture; -// this.sprites.push(sprite); - this.head = sprite; - this.tail = sprite; - this.size = 1; - - this.growBatch(); -} - -/** - * inserts a sprite before the specified sprite - * - * @method insertBefore - * @param sprite {Sprite} the sprite to be added - * @param nextSprite {nextSprite} the first sprite will be inserted before this sprite - */ -PIXI.WebGLBatch.prototype.insertBefore = function(sprite, nextSprite) -{ - this.size++; - - sprite.batch = this; - this.dirty = true; - var tempPrev = nextSprite.__prev; - nextSprite.__prev = sprite; - sprite.__next = nextSprite; - - if(tempPrev) - { - sprite.__prev = tempPrev; - tempPrev.__next = sprite; - } - else - { - this.head = sprite; - //this.head.__prev = null - } -} - -/** - * inserts a sprite after the specified sprite - * - * @method insertAfter - * @param sprite {Sprite} the sprite to be added - * @param previousSprite {Sprite} the first sprite will be inserted after this sprite - */ -PIXI.WebGLBatch.prototype.insertAfter = function(sprite, previousSprite) -{ - this.size++; - - sprite.batch = this; - this.dirty = true; - - var tempNext = previousSprite.__next; - previousSprite.__next = sprite; - sprite.__prev = previousSprite; - - if(tempNext) - { - sprite.__next = tempNext; - tempNext.__prev = sprite; - } - else - { - this.tail = sprite - } -} - -/** - * removes a sprite from the batch - * - * @method remove - * @param sprite {Sprite} the sprite to be removed - */ -PIXI.WebGLBatch.prototype.remove = function(sprite) -{ - this.size--; - - if(this.size == 0) - { - sprite.batch = null; - sprite.__prev = null; - sprite.__next = null; - return; - } - - if(sprite.__prev) - { - sprite.__prev.__next = sprite.__next; - } - else - { - this.head = sprite.__next; - this.head.__prev = null; - } - - if(sprite.__next) - { - sprite.__next.__prev = sprite.__prev; - } - else - { - this.tail = sprite.__prev; - this.tail.__next = null - } - - sprite.batch = null; - sprite.__next = null; - sprite.__prev = null; - this.dirty = true; -} - -/** - * Splits the batch into two with the specified sprite being the start of the new batch. - * - * @method split - * @param sprite {Sprite} the sprite that indicates where the batch should be split - * @return {WebGLBatch} the new batch - */ -PIXI.WebGLBatch.prototype.split = function(sprite) -{ - this.dirty = true; - - var batch = new PIXI.WebGLBatch(this.gl);//PIXI._getBatch(this.gl); - batch.init(sprite); - batch.texture = this.texture; - batch.tail = this.tail; - - this.tail = sprite.__prev; - this.tail.__next = null; - - sprite.__prev = null; - // return a splite batch! - //sprite.__prev.__next = null; - //sprite.__prev = null; - - // TODO this size is wrong! - // need to recalculate :/ problem with a linked list! - // unless it gets calculated in the "clean"? - - // need to loop through items as there is no way to know the length on a linked list :/ - var tempSize = 0; - while(sprite) - { - tempSize++; - sprite.batch = batch; - sprite = sprite.__next; - } - - batch.size = tempSize; - this.size -= tempSize; - - return batch; -} - -/** - * Merges two batchs together - * - * @method merge - * @param batch {WebGLBatch} the batch that will be merged - */ -PIXI.WebGLBatch.prototype.merge = function(batch) -{ - this.dirty = true; - - this.tail.__next = batch.head; - batch.head.__prev = this.tail; - - this.size += batch.size; - - this.tail = batch.tail; - - var sprite = batch.head; - while(sprite) - { - sprite.batch = this; - sprite = sprite.__next; - } -} - -/** - * Grows the size of the batch. As the elements in the batch cannot have a dynamic size this - * function is used to increase the size of the batch. It also creates a little extra room so - * that the batch does not need to be resized every time a sprite is added - * - * @method growBatch - */ -PIXI.WebGLBatch.prototype.growBatch = function() -{ - var gl = this.gl; - if( this.size == 1) - { - this.dynamicSize = 1; - } - else - { - this.dynamicSize = this.size * 1.5 - } - // grow verts - this.verticies = new Float32Array(this.dynamicSize * 8); - - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER,this.verticies , gl.DYNAMIC_DRAW); - - this.uvs = new Float32Array( this.dynamicSize * 8 ) - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, this.uvs , gl.DYNAMIC_DRAW); - - this.dirtyUVS = true; - - this.colors = new Float32Array( this.dynamicSize * 4 ) - gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, this.colors , gl.DYNAMIC_DRAW); - - this.dirtyColors = true; - - this.indices = new Uint16Array(this.dynamicSize * 6); - var length = this.indices.length/6; - - for (var i=0; i < length; i++) - { - var index2 = i * 6; - var index3 = i * 4; - this.indices[index2 + 0] = index3 + 0; - this.indices[index2 + 1] = index3 + 1; - this.indices[index2 + 2] = index3 + 2; - this.indices[index2 + 3] = index3 + 0; - this.indices[index2 + 4] = index3 + 2; - this.indices[index2 + 5] = index3 + 3; - }; - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW); -} - -/** - * Refresh's all the data in the batch and sync's it with the webGL buffers - * - * @method refresh - */ -PIXI.WebGLBatch.prototype.refresh = function() -{ - var gl = this.gl; - - if (this.dynamicSize < this.size) - { - this.growBatch(); - } - - var indexRun = 0; - var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index; - var a, b, c, d, tx, ty; - - var displayObject = this.head; - - while(displayObject) - { - index = indexRun * 8; - - var texture = displayObject.texture; - - var frame = texture.frame; - var tw = texture.baseTexture.width; - var th = texture.baseTexture.height; - - this.uvs[index + 0] = frame.x / tw; - this.uvs[index +1] = frame.y / th; - - this.uvs[index +2] = (frame.x + frame.width) / tw; - this.uvs[index +3] = frame.y / th; - - this.uvs[index +4] = (frame.x + frame.width) / tw; - this.uvs[index +5] = (frame.y + frame.height) / th; - - this.uvs[index +6] = frame.x / tw; - this.uvs[index +7] = (frame.y + frame.height) / th; - - displayObject.updateFrame = false; - - colorIndex = indexRun * 4; - this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha; - - displayObject = displayObject.__next; - - indexRun ++; - } - - this.dirtyUVS = true; - this.dirtyColors = true; -} - -/** - * Updates all the relevant geometry and uploads the data to the GPU - * - * @method update - */ -PIXI.WebGLBatch.prototype.update = function() -{ - var gl = this.gl; - var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, index2, index3 - - var a, b, c, d, tx, ty; - - var indexRun = 0; - - var displayObject = this.head; - - while(displayObject) - { - if(displayObject.worldVisible) - { - width = displayObject.texture.frame.width; - height = displayObject.texture.frame.height; - - // TODO trim?? - aX = displayObject.anchor.x;// - displayObject.texture.trim.x - aY = displayObject.anchor.y; //- displayObject.texture.trim.y - w0 = width * (1-aX); - w1 = width * -aX; - - h0 = height * (1-aY); - h1 = height * -aY; - - index = indexRun * 8; - - worldTransform = displayObject.worldTransform; - - a = worldTransform[0]; - b = worldTransform[3]; - c = worldTransform[1]; - d = worldTransform[4]; - tx = worldTransform[2]; - ty = worldTransform[5]; - - this.verticies[index + 0 ] = a * w1 + c * h1 + tx; - this.verticies[index + 1 ] = d * h1 + b * w1 + ty; - - this.verticies[index + 2 ] = a * w0 + c * h1 + tx; - this.verticies[index + 3 ] = d * h1 + b * w0 + ty; - - this.verticies[index + 4 ] = a * w0 + c * h0 + tx; - this.verticies[index + 5 ] = d * h0 + b * w0 + ty; - - this.verticies[index + 6] = a * w1 + c * h0 + tx; - this.verticies[index + 7] = d * h0 + b * w1 + ty; - - if(displayObject.updateFrame || displayObject.texture.updateFrame) - { - this.dirtyUVS = true; - - var texture = displayObject.texture; - - var frame = texture.frame; - var tw = texture.baseTexture.width; - var th = texture.baseTexture.height; - - this.uvs[index + 0] = frame.x / tw; - this.uvs[index +1] = frame.y / th; - - this.uvs[index +2] = (frame.x + frame.width) / tw; - this.uvs[index +3] = frame.y / th; - - this.uvs[index +4] = (frame.x + frame.width) / tw; - this.uvs[index +5] = (frame.y + frame.height) / th; - - this.uvs[index +6] = frame.x / tw; - this.uvs[index +7] = (frame.y + frame.height) / th; - - displayObject.updateFrame = false; - } - - // TODO this probably could do with some optimisation.... - if(displayObject.cacheAlpha != displayObject.worldAlpha) - { - displayObject.cacheAlpha = displayObject.worldAlpha; - - var colorIndex = indexRun * 4; - this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha; - this.dirtyColors = true; - } - } - else - { - index = indexRun * 8; - - this.verticies[index + 0 ] = 0; - this.verticies[index + 1 ] = 0; - - this.verticies[index + 2 ] = 0; - this.verticies[index + 3 ] = 0; - - this.verticies[index + 4 ] = 0; - this.verticies[index + 5 ] = 0; - - this.verticies[index + 6] = 0; - this.verticies[index + 7] = 0; - } - - indexRun++; - displayObject = displayObject.__next; - } -} - -/** - * Draws the batch to the frame buffer - * - * @method render - */ -PIXI.WebGLBatch.prototype.render = function(start, end) -{ - start = start || 0; - //end = end || this.size; - if(end == undefined)end = this.size; - - if(this.dirty) - { - this.refresh(); - this.dirty = false; - } - - if (this.size == 0)return; - - this.update(); - var gl = this.gl; - - //TODO optimize this! - - var shaderProgram = PIXI.shaderProgram; - gl.useProgram(shaderProgram); - - // update the verts.. - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - // ok.. - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.verticies) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - - if(this.dirtyUVS) - { - this.dirtyUVS = false; - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvs); - } - - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, this.texture._glTexture); - - // update color! - gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer); - - if(this.dirtyColors) - { - this.dirtyColors = false; - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.colors); - } - - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - - //var startIndex = 0//1; - var len = end - start; - // console.log(this.size) - // DRAW THAT this! - gl.drawElements(gl.TRIANGLES, len * 6, gl.UNSIGNED_SHORT, start * 2 * 6 ); -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A WebGLBatch Enables a group of sprites to be drawn using the same settings. - * if a group of sprites all have the same baseTexture and blendMode then they can be - * grouped into a batch. All the sprites in a batch can then be drawn in one go by the - * GPU which is hugely efficient. ALL sprites in the webGL renderer are added to a batch - * even if the batch only contains one sprite. Batching is handled automatically by the - * webGL renderer. A good tip is: the smaller the number of batchs there are, the faster - * the webGL renderer will run. - * - * @class WebGLBatch - * @contructor - * @param gl {WebGLContext} An instance of the webGL context - */ -PIXI.WebGLRenderGroup = function(gl) -{ - this.gl = gl; - this.root; - - this.backgroundColor; - this.batchs = []; - this.toRemove = []; -} - -// constructor -PIXI.WebGLRenderGroup.prototype.constructor = PIXI.WebGLRenderGroup; - -/** - * Add a display object to the webgl renderer - * - * @method setRenderable - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.setRenderable = function(displayObject) -{ - // has this changed?? - if(this.root)this.removeDisplayObjectAndChildren(this.root); - - displayObject.worldVisible = displayObject.visible; - - // soooooo // - // to check if any batchs exist already?? - - // TODO what if its already has an object? should remove it - this.root = displayObject; - this.addDisplayObjectAndChildren(displayObject); -} - -/** - * Renders the stage to its webgl view - * - * @method render - * @param projection {Object} - */ -PIXI.WebGLRenderGroup.prototype.render = function(projection) -{ - PIXI.WebGLRenderer.updateTextures(); - - var gl = this.gl; - - - gl.uniform2f(PIXI.shaderProgram.projectionVector, projection.x, projection.y); - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - - // TODO remove this by replacing visible with getter setters.. - this.checkVisibility(this.root, this.root.visible); - - // will render all the elements in the group - var renderable; - - - for (var i=0; i < this.batchs.length; i++) - { - renderable = this.batchs[i]; - if(renderable instanceof PIXI.WebGLBatch) - { - this.batchs[i].render(); - } - else if(renderable instanceof PIXI.TilingSprite) - { - if(renderable.visible)this.renderTilingSprite(renderable, projection); - } - else if(renderable instanceof PIXI.Strip) - { - if(renderable.visible)this.renderStrip(renderable, projection); - } - else if(renderable instanceof PIXI.Graphics) - { - if(renderable.visible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable, projection);//, projectionMatrix); - } - else if(renderable instanceof PIXI.FilterBlock) - { - /* - * for now only masks are supported.. - */ - if(renderable.open) - { - gl.enable(gl.STENCIL_TEST); - - gl.colorMask(false, false, false, false); - gl.stencilFunc(gl.ALWAYS,1,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE); - - PIXI.WebGLGraphics.renderGraphics(renderable.mask, projection); - - gl.colorMask(true, true, true, false); - gl.stencilFunc(gl.NOTEQUAL,0,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); - } - else - { - gl.disable(gl.STENCIL_TEST); - } - } - } - -} - -/** - * Renders the stage to its webgl view - * - * @method handleFilter - * @param filter {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.handleFilter = function(filter, projection) -{ - -} - -/** - * Renders a specific displayObject - * - * @method renderSpecific - * @param displayObject {DisplayObject} - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderSpecific = function(displayObject, projection) -{ - PIXI.WebGLRenderer.updateTextures(); - - var gl = this.gl; - this.checkVisibility(displayObject, displayObject.visible); - -// gl.uniformMatrix4fv(PIXI.shaderProgram.mvMatrixUniform, false, projectionMatrix); - gl.uniform2f(PIXI.shaderProgram.projectionVector, projection.x, projection.y); - - // to do! - // render part of the scene... - - var startIndex; - var startBatchIndex; - - var endIndex; - var endBatchIndex; - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.first; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - var startBatch = nextRenderable.batch; - - if(nextRenderable instanceof PIXI.Sprite) - { - startBatch = nextRenderable.batch; - - var head = startBatch.head; - var next = head; - - // ok now we have the batch.. need to find the start index! - if(head == nextRenderable) - { - startIndex = 0; - } - else - { - startIndex = 1; - - while(head.__next != nextRenderable) - { - startIndex++; - head = head.__next; - } - } - } - else - { - startBatch = nextRenderable; - } - - // Get the LAST renderable object - var lastRenderable = displayObject; - var endBatch; - var lastItem = displayObject; - while(lastItem.children.length > 0) - { - lastItem = lastItem.children[lastItem.children.length-1]; - if(lastItem.renderable)lastRenderable = lastItem; - } - - if(lastRenderable instanceof PIXI.Sprite) - { - endBatch = lastRenderable.batch; - - var head = endBatch.head; - - if(head == lastRenderable) - { - endIndex = 0; - } - else - { - endIndex = 1; - - while(head.__next != lastRenderable) - { - endIndex++; - head = head.__next; - } - } - } - else - { - endBatch = lastRenderable; - } - - // TODO - need to fold this up a bit! - - if(startBatch == endBatch) - { - if(startBatch instanceof PIXI.WebGLBatch) - { - startBatch.render(startIndex, endIndex+1); - } - else - { - this.renderSpecial(startBatch, projection); - } - return; - } - - // now we have first and last! - startBatchIndex = this.batchs.indexOf(startBatch); - endBatchIndex = this.batchs.indexOf(endBatch); - - // DO the first batch - if(startBatch instanceof PIXI.WebGLBatch) - { - startBatch.render(startIndex); - } - else - { - this.renderSpecial(startBatch, projection); - } - - // DO the middle batchs.. - for (var i=startBatchIndex+1; i < endBatchIndex; i++) - { - renderable = this.batchs[i]; - - if(renderable instanceof PIXI.WebGLBatch) - { - this.batchs[i].render(); - } - else - { - this.renderSpecial(renderable, projection); - } - } - - // DO the last batch.. - if(endBatch instanceof PIXI.WebGLBatch) - { - endBatch.render(0, endIndex+1); - } - else - { - this.renderSpecial(endBatch, projection); - } -} - -/** - * Renders a specific renderable - * - * @method renderSpecial - * @param renderable {DisplayObject} - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderSpecial = function(renderable, projection) -{ - if(renderable instanceof PIXI.TilingSprite) - { - if(renderable.visible)this.renderTilingSprite(renderable, projection); - } - else if(renderable instanceof PIXI.Strip) - { - if(renderable.visible)this.renderStrip(renderable, projection); - } - else if(renderable instanceof PIXI.CustomRenderable) - { - if(renderable.visible) renderable.renderWebGL(this, projection); - } - else if(renderable instanceof PIXI.Graphics) - { - if(renderable.visible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable, projection); - } - else if(renderable instanceof PIXI.FilterBlock) - { - /* - * for now only masks are supported.. - */ - - var gl = PIXI.gl; - - if(renderable.open) - { - gl.enable(gl.STENCIL_TEST); - - gl.colorMask(false, false, false, false); - gl.stencilFunc(gl.ALWAYS,1,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE); - - PIXI.WebGLGraphics.renderGraphics(renderable.mask, projection); - - // we know this is a render texture so enable alpha too.. - gl.colorMask(true, true, true, true); - gl.stencilFunc(gl.NOTEQUAL,0,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); - } - else - { - gl.disable(gl.STENCIL_TEST); - } - } -} - -/** - * Checks the visibility of a displayObject - * - * @method checkVisibility - * @param displayObject {DisplayObject} - * @param globalVisible {Boolean} - * @private - */ -PIXI.WebGLRenderGroup.prototype.checkVisibility = function(displayObject, globalVisible) -{ - // give the dp a reference to its renderGroup... - var children = displayObject.children; - //displayObject.worldVisible = globalVisible; - for (var i=0; i < children.length; i++) - { - var child = children[i]; - - // TODO optimize... should'nt need to loop through everything all the time - child.worldVisible = child.visible && globalVisible; - - // everything should have a batch! - // time to see whats new! - if(child.textureChange) - { - child.textureChange = false; - if(child.worldVisible)this.updateTexture(child); - // update texture!! - } - - if(child.children.length > 0) - { - this.checkVisibility(child, child.worldVisible); - } - }; -} - -/** - * Updates a webgl texture - * - * @method updateTexture - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.updateTexture = function(displayObject) -{ - - // TODO definitely can optimse this function.. - - this.removeObject(displayObject); - - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - var previousRenderable = displayObject.first; - while(previousRenderable != this.root) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.last; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - - this.insertObject(displayObject, previousRenderable, nextRenderable); -} - -/** - * Adds filter blocks - * - * @method addFilterBlocks - * @param start {FilterBlock} - * @param end {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.addFilterBlocks = function(start, end) -{ - start.__renderGroup = this; - end.__renderGroup = this; - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - var previousRenderable = start; - while(previousRenderable != this.root) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - this.insertAfter(start, previousRenderable); - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var previousRenderable2 = end; - while(previousRenderable2 != this.root) - { - previousRenderable2 = previousRenderable2._iPrev; - if(previousRenderable2.renderable && previousRenderable2.__renderGroup)break; - } - this.insertAfter(end, previousRenderable2); -} - -/** - * Remove filter blocks - * - * @method removeFilterBlocks - * @param start {FilterBlock} - * @param end {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeFilterBlocks = function(start, end) -{ - this.removeObject(start); - this.removeObject(end); -} - -/** - * Adds a display object and children to the webgl context - * - * @method addDisplayObjectAndChildren - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.addDisplayObjectAndChildren = function(displayObject) -{ - if(displayObject.__renderGroup)displayObject.__renderGroup.removeDisplayObjectAndChildren(displayObject); - - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - - var previousRenderable = displayObject.first; - while(previousRenderable != this.root.first) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.last; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - - // one the display object hits this. we can break the loop - - var tempObject = displayObject.first; - var testObject = displayObject.last._iNext; - do - { - tempObject.__renderGroup = this; - - if(tempObject.renderable) - { - - this.insertObject(tempObject, previousRenderable, nextRenderable); - previousRenderable = tempObject; - } - - tempObject = tempObject._iNext; - } - while(tempObject != testObject) -} - -/** - * Removes a display object and children to the webgl context - * - * @method removeDisplayObjectAndChildren - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeDisplayObjectAndChildren = function(displayObject) -{ - if(displayObject.__renderGroup != this)return; - -// var displayObject = displayObject.first; - var lastObject = displayObject.last; - do - { - displayObject.__renderGroup = null; - if(displayObject.renderable)this.removeObject(displayObject); - displayObject = displayObject._iNext; - } - while(displayObject) -} - -/** - * Inserts a displayObject into the linked list - * - * @method insertObject - * @param displayObject {DisplayObject} - * @param previousObject {DisplayObject} - * @param nextObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.insertObject = function(displayObject, previousObject, nextObject) -{ - // while looping below THE OBJECT MAY NOT HAVE BEEN ADDED - var previousSprite = previousObject; - var nextSprite = nextObject; - - /* - * so now we have the next renderable and the previous renderable - * - */ - if(displayObject instanceof PIXI.Sprite) - { - var previousBatch - var nextBatch - - if(previousSprite instanceof PIXI.Sprite) - { - previousBatch = previousSprite.batch; - if(previousBatch) - { - if(previousBatch.texture == displayObject.texture.baseTexture && previousBatch.blendMode == displayObject.blendMode) - { - previousBatch.insertAfter(displayObject, previousSprite); - return; - } - } - } - else - { - // TODO reword! - previousBatch = previousSprite; - } - - if(nextSprite) - { - if(nextSprite instanceof PIXI.Sprite) - { - nextBatch = nextSprite.batch; - - //batch may not exist if item was added to the display list but not to the webGL - if(nextBatch) - { - if(nextBatch.texture == displayObject.texture.baseTexture && nextBatch.blendMode == displayObject.blendMode) - { - nextBatch.insertBefore(displayObject, nextSprite); - return; - } - else - { - if(nextBatch == previousBatch) - { - // THERE IS A SPLIT IN THIS BATCH! // - var splitBatch = previousBatch.split(nextSprite); - // COOL! - // add it back into the array - /* - * OOPS! - * seems the new sprite is in the middle of a batch - * lets split it.. - */ - var batch = PIXI.WebGLRenderer.getBatch(); - - var index = this.batchs.indexOf( previousBatch ); - batch.init(displayObject); - this.batchs.splice(index+1, 0, batch, splitBatch); - - return; - } - } - } - } - else - { - // TODO re-word! - - nextBatch = nextSprite; - } - } - - /* - * looks like it does not belong to any batch! - * but is also not intersecting one.. - * time to create anew one! - */ - - var batch = PIXI.WebGLRenderer.getBatch(); - batch.init(displayObject); - - if(previousBatch) // if this is invalid it means - { - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, batch); - } - else - { - this.batchs.push(batch); - } - - return; - } - else if(displayObject instanceof PIXI.TilingSprite) - { - - // add to a batch!! - this.initTilingSprite(displayObject); - // this.batchs.push(displayObject); - - } - else if(displayObject instanceof PIXI.Strip) - { - // add to a batch!! - this.initStrip(displayObject); - // this.batchs.push(displayObject); - } - else if(displayObject)// instanceof PIXI.Graphics) - { - //displayObject.initWebGL(this); - - // add to a batch!! - //this.initStrip(displayObject); - //this.batchs.push(displayObject); - } - - this.insertAfter(displayObject, previousSprite); - - // insert and SPLIT! - -} - -/** - * Inserts a displayObject into the linked list - * - * @method insertAfter - * @param item {DisplayObject} - * @param displayObject {DisplayObject} The object to insert - * @private - */ -PIXI.WebGLRenderGroup.prototype.insertAfter = function(item, displayObject) -{ - if(displayObject instanceof PIXI.Sprite) - { - var previousBatch = displayObject.batch; - - if(previousBatch) - { - // so this object is in a batch! - - // is it not? need to split the batch - if(previousBatch.tail == displayObject) - { - // is it tail? insert in to batchs - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, item); - } - else - { - // TODO MODIFY ADD / REMOVE CHILD TO ACCOUNT FOR FILTERS (also get prev and next) // - - // THERE IS A SPLIT IN THIS BATCH! // - var splitBatch = previousBatch.split(displayObject.__next); - - // COOL! - // add it back into the array - /* - * OOPS! - * seems the new sprite is in the middle of a batch - * lets split it.. - */ - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, item, splitBatch); - } - } - else - { - this.batchs.push(item); - } - } - else - { - var index = this.batchs.indexOf( displayObject ); - this.batchs.splice(index+1, 0, item); - } -} - -/** - * Removes a displayObject from the linked list - * - * @method removeObject - * @param displayObject {DisplayObject} The object to remove - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeObject = function(displayObject) -{ - // loop through children.. - // display object // - - // add a child from the render group.. - // remove it and all its children! - //displayObject.cacheVisible = false;//displayObject.visible; - - /* - * removing is a lot quicker.. - * - */ - var batchToRemove; - - if(displayObject instanceof PIXI.Sprite) - { - // should always have a batch! - var batch = displayObject.batch; - if(!batch)return; // this means the display list has been altered befre rendering - - batch.remove(displayObject); - - if(batch.size==0) - { - batchToRemove = batch; - } - } - else - { - batchToRemove = displayObject; - } - - /* - * Looks like there is somthing that needs removing! - */ - if(batchToRemove) - { - var index = this.batchs.indexOf( batchToRemove ); - if(index == -1)return;// this means it was added then removed before rendered - - // ok so.. check to see if you adjacent batchs should be joined. - // TODO may optimise? - if(index == 0 || index == this.batchs.length-1) - { - // wha - eva! just get of the empty batch! - this.batchs.splice(index, 1); - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - - return; - } - - if(this.batchs[index-1] instanceof PIXI.WebGLBatch && this.batchs[index+1] instanceof PIXI.WebGLBatch) - { - if(this.batchs[index-1].texture == this.batchs[index+1].texture && this.batchs[index-1].blendMode == this.batchs[index+1].blendMode) - { - //console.log("MERGE") - this.batchs[index-1].merge(this.batchs[index+1]); - - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - PIXI.WebGLRenderer.returnBatch(this.batchs[index+1]); - this.batchs.splice(index, 2); - return; - } - } - - this.batchs.splice(index, 1); - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - } -} - -/** - * Initializes a tiling sprite - * - * @method initTilingSprite - * @param sprite {TilingSprite} The tiling sprite to initialize - * @private - */ -PIXI.WebGLRenderGroup.prototype.initTilingSprite = function(sprite) -{ - var gl = this.gl; - - // make the texture tilable.. - - sprite.verticies = new Float32Array([0, 0, - sprite.width, 0, - sprite.width, sprite.height, - 0, sprite.height]); - - sprite.uvs = new Float32Array([0, 0, - 1, 0, - 1, 1, - 0, 1]); - - sprite.colors = new Float32Array([1,1,1,1]); - - sprite.indices = new Uint16Array([0, 1, 3,2])//, 2]); - - sprite._vertexBuffer = gl.createBuffer(); - sprite._indexBuffer = gl.createBuffer(); - sprite._uvBuffer = gl.createBuffer(); - sprite._colorBuffer = gl.createBuffer(); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.verticies, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.uvs, gl.DYNAMIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.colors, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, sprite._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, sprite.indices, gl.STATIC_DRAW); - -// return ( (x > 0) && ((x & (x - 1)) == 0) ); - - if(sprite.texture.baseTexture._glTexture) - { - gl.bindTexture(gl.TEXTURE_2D, sprite.texture.baseTexture._glTexture); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); - sprite.texture.baseTexture._powerOf2 = true; - } - else - { - sprite.texture.baseTexture._powerOf2 = true; - } -} - -/** - * Renders a Strip - * - * @method renderStrip - * @param strip {Strip} The strip to render - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderStrip = function(strip, projection) -{ - var gl = this.gl; - var shaderProgram = PIXI.shaderProgram; -// mat - //var mat4Real = PIXI.mat3.toMat4(strip.worldTransform); - //PIXI.mat4.transpose(mat4Real); - //PIXI.mat4.multiply(projectionMatrix, mat4Real, mat4Real ) - - - gl.useProgram(PIXI.stripShaderProgram); - - var m = PIXI.mat3.clone(strip.worldTransform); - - PIXI.mat3.transpose(m); - - // set the matrix transform for the - gl.uniformMatrix3fv(PIXI.stripShaderProgram.translationMatrix, false, m); - gl.uniform2f(PIXI.stripShaderProgram.projectionVector, projection.x, projection.y); - gl.uniform1f(PIXI.stripShaderProgram.alpha, strip.worldAlpha); - -/* - if(strip.blendMode == PIXI.blendModes.NORMAL) - { - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - } - else - { - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR); - } - */ - - - if(!strip.dirty) - { - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferSubData(gl.ARRAY_BUFFER, 0, strip.verticies) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - } - else - { - strip.dirty = false; - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW); - - } - //console.log(gl.TRIANGLE_STRIP); - - gl.drawElements(gl.TRIANGLE_STRIP, strip.indices.length, gl.UNSIGNED_SHORT, 0); - - gl.useProgram(PIXI.shaderProgram); -} - -/** - * Renders a TilingSprite - * - * @method renderTilingSprite - * @param sprite {TilingSprite} The tiling sprite to render - * @param projectionMatrix {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderTilingSprite = function(sprite, projectionMatrix) -{ - var gl = this.gl; - var shaderProgram = PIXI.shaderProgram; - - var tilePosition = sprite.tilePosition; - var tileScale = sprite.tileScale; - - var offsetX = tilePosition.x/sprite.texture.baseTexture.width; - var offsetY = tilePosition.y/sprite.texture.baseTexture.height; - - var scaleX = (sprite.width / sprite.texture.baseTexture.width) / tileScale.x; - var scaleY = (sprite.height / sprite.texture.baseTexture.height) / tileScale.y; - - sprite.uvs[0] = 0 - offsetX; - sprite.uvs[1] = 0 - offsetY; - - sprite.uvs[2] = (1 * scaleX) -offsetX; - sprite.uvs[3] = 0 - offsetY; - - sprite.uvs[4] = (1 *scaleX) - offsetX; - sprite.uvs[5] = (1 *scaleY) - offsetY; - - sprite.uvs[6] = 0 - offsetX; - sprite.uvs[7] = (1 *scaleY) - offsetY; - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._uvBuffer); - gl.bufferSubData(gl.ARRAY_BUFFER, 0, sprite.uvs) - - this.renderStrip(sprite, projectionMatrix); -} - -/** - * Initializes a strip to be rendered - * - * @method initStrip - * @param strip {Strip} The strip to initialize - * @private - */ -PIXI.WebGLRenderGroup.prototype.initStrip = function(strip) -{ - // build the strip! - var gl = this.gl; - var shaderProgram = this.shaderProgram; - - strip._vertexBuffer = gl.createBuffer(); - strip._indexBuffer = gl.createBuffer(); - strip._uvBuffer = gl.createBuffer(); - strip._colorBuffer = gl.createBuffer(); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.DYNAMIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW); - - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW); -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * the CanvasRenderer draws the stage and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. - * Dont forget to add the view to your DOM or you will not see anything :) - * - * @class CanvasRenderer - * @constructor - * @param width=0 {Number} the width of the canvas view - * @param height=0 {Number} the height of the canvas view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - */ -PIXI.CanvasRenderer = function(width, height, view, transparent) -{ - this.transparent = transparent; - - /** - * The width of the canvas view - * - * @property width - * @type Number - * @default 800 - */ - this.width = width || 800; - - /** - * The height of the canvas view - * - * @property height - * @type Number - * @default 600 - */ - this.height = height || 600; - - /** - * The canvas element that the everything is drawn to - * - * @property view - * @type Canvas - */ - this.view = view || document.createElement( 'canvas' ); - - /** - * The canvas context that the everything is drawn to - * @property context - * @type Canvas 2d Context - */ - this.context = this.view.getContext("2d"); - - this.refresh = true; - // hack to enable some hardware acceleration! - //this.view.style["transform"] = "translatez(0)"; - - this.view.width = this.width; - this.view.height = this.height; - this.count = 0; -} - -// constructor -PIXI.CanvasRenderer.prototype.constructor = PIXI.CanvasRenderer; - -/** - * Renders the stage to its canvas view - * - * @method render - * @param stage {Stage} the Stage element to be rendered - */ -PIXI.CanvasRenderer.prototype.render = function(stage) -{ - // update children if need be - - //stage.__childrenAdded = []; - //stage.__childrenRemoved = []; - - // update textures if need be - PIXI.texturesToUpdate = []; - PIXI.texturesToDestroy = []; - - stage.updateTransform(); - - // update the background color - if(this.view.style.backgroundColor!=stage.backgroundColorString && !this.transparent)this.view.style.backgroundColor = stage.backgroundColorString; - - this.context.setTransform(1,0,0,1,0,0); - this.context.clearRect(0, 0, this.width, this.height) - this.renderDisplayObject(stage); - //as - - // run interaction! - if(stage.interactive) - { - //need to add some events! - if(!stage._interactiveEventsAdded) - { - stage._interactiveEventsAdded = true; - stage.interactionManager.setTarget(this); - } - } - - // remove frame updates.. - if(PIXI.Texture.frameUpdates.length > 0) - { - PIXI.Texture.frameUpdates = []; - } - - -} - -/** - * resizes the canvas view to the specified width and height - * - * @method resize - * @param width {Number} the new width of the canvas view - * @param height {Number} the new height of the canvas view - */ -PIXI.CanvasRenderer.prototype.resize = function(width, height) -{ - this.width = width; - this.height = height; - - this.view.width = width; - this.view.height = height; -} - -/** - * Renders a display object - * - * @method renderDisplayObject - * @param displayObject {DisplayObject} The displayObject to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject) -{ - // no loger recurrsive! - var transform; - var context = this.context; - - context.globalCompositeOperation = 'source-over'; - - // one the display object hits this. we can break the loop - var testObject = displayObject.last._iNext; - displayObject = displayObject.first; - - do - { - transform = displayObject.worldTransform; - - if(!displayObject.visible) - { - displayObject = displayObject.last._iNext; - continue; - } - - if(!displayObject.renderable) - { - displayObject = displayObject._iNext; - continue; - } - - if(displayObject instanceof PIXI.Sprite) - { - - var frame = displayObject.texture.frame; - - if(frame) - { - context.globalAlpha = displayObject.worldAlpha; - - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]); - - context.drawImage(displayObject.texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, - (displayObject.anchor.x) * -frame.width, - (displayObject.anchor.y) * -frame.height, - frame.width, - frame.height); - } - } - else if(displayObject instanceof PIXI.Strip) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - this.renderStrip(displayObject); - } - else if(displayObject instanceof PIXI.TilingSprite) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - this.renderTilingSprite(displayObject); - } - else if(displayObject instanceof PIXI.CustomRenderable) - { - displayObject.renderCanvas(this); - } - else if(displayObject instanceof PIXI.Graphics) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - PIXI.CanvasGraphics.renderGraphics(displayObject, context); - } - else if(displayObject instanceof PIXI.FilterBlock) - { - if(displayObject.open) - { - context.save(); - - var cacheAlpha = displayObject.mask.alpha; - var maskTransform = displayObject.mask.worldTransform; - - context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5]) - - displayObject.mask.worldAlpha = 0.5; - - context.worldAlpha = 0; - - PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, context); - // context.fillStyle = 0xFF0000; - // context.fillRect(0, 0, 200, 200); - context.clip(); - - displayObject.mask.worldAlpha = cacheAlpha; - //context.globalCompositeOperation = 'lighter'; - } - else - { - //context.globalCompositeOperation = 'source-over'; - context.restore(); - } - } - // count++ - displayObject = displayObject._iNext; - - - } - while(displayObject != testObject) - - -} - -/** - * Renders a flat strip - * - * @method renderStripFlat - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip) -{ - var context = this.context; - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - - context.beginPath(); - for (var i=1; i < length-2; i++) - { - - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - - }; - - context.fillStyle = "#FF0000"; - context.fill(); - context.closePath(); -} - -/** - * Renders a tiling sprite - * - * @method renderTilingSprite - * @param sprite {TilingSprite} The tilingsprite to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderTilingSprite = function(sprite) -{ - var context = this.context; - - context.globalAlpha = sprite.worldAlpha; - - if(!sprite.__tilePattern) sprite.__tilePattern = context.createPattern(sprite.texture.baseTexture.source, "repeat"); - - context.beginPath(); - - var tilePosition = sprite.tilePosition; - var tileScale = sprite.tileScale; - - // offset - context.scale(tileScale.x,tileScale.y); - context.translate(tilePosition.x, tilePosition.y); - - context.fillStyle = sprite.__tilePattern; - context.fillRect(-tilePosition.x,-tilePosition.y,sprite.width / tileScale.x, sprite.height / tileScale.y); - - context.scale(1/tileScale.x, 1/tileScale.y); - context.translate(-tilePosition.x, -tilePosition.y); - - context.closePath(); -} - -/** - * Renders a strip - * - * @method renderStrip - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStrip = function(strip) -{ - var context = this.context; - //context.globalCompositeOperation = 'lighter'; - // draw triangles!! - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - for (var i=1; i < length-2; i++) - { - - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; - var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height; - - - context.save(); - context.beginPath(); - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - context.closePath(); - - // context.fillStyle = "white"//rgb(1, 1, 1,1)); - // context.fill(); - context.clip(); - - - // Compute matrix transform - var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2; - var delta_a = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2; - var delta_b = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2; - var delta_c = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2; - var delta_d = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2; - var delta_e = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2; - var delta_f = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2; - - - - - context.transform(delta_a/delta, delta_d/delta, - delta_b/delta, delta_e/delta, - delta_c/delta, delta_f/delta); - - context.drawImage(strip.texture.baseTexture.source, 0, 0); - context.restore(); - }; - -// context.globalCompositeOperation = 'source-over'; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * A set of functions used by the canvas renderer to draw the primitive graphics data - * - * @class CanvasGraphics - */ -PIXI.CanvasGraphics = function() -{ - -} - - -/* - * Renders the graphics object - * - * @static - * @private - * @method renderGraphics - * @param graphics {Graphics} - * @param context {Context2D} - */ -PIXI.CanvasGraphics.renderGraphics = function(graphics, context) -{ - var worldAlpha = graphics.worldAlpha; - - for (var i=0; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - var points = data.points; - - context.strokeStyle = color = '#' + ('00000' + ( data.lineColor | 0).toString(16)).substr(-6); - - context.lineWidth = data.lineWidth; - - if(data.type == PIXI.Graphics.POLY) - { - //if(data.lineWidth <= 0)continue; - - context.beginPath(); - - context.moveTo(points[0], points[1]); - - for (var j=1; j < points.length/2; j++) - { - context.lineTo(points[j * 2], points[j * 2 + 1]); - } - - // if the first and last point are the same close the path - much neater :) - if(points[0] == points[points.length-2] && points[1] == points[points.length-1]) - { - context.closePath(); - } - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - else if(data.type == PIXI.Graphics.RECT) - { - - // TODO - need to be Undefined! - if(data.fillColor) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fillRect(points[0], points[1], points[2], points[3]); - - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.strokeRect(points[0], points[1], points[2], points[3]); - } - - } - else if(data.type == PIXI.Graphics.CIRC) - { - // TODO - need to be Undefined! - context.beginPath(); - context.arc(points[0], points[1], points[2],0,2*Math.PI); - context.closePath(); - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - else if(data.type == PIXI.Graphics.ELIP) - { - - // elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - - var elipseData = data.points; - - var w = elipseData[2] * 2; - var h = elipseData[3] * 2; - - var x = elipseData[0] - w/2; - var y = elipseData[1] - h/2; - - context.beginPath(); - - var kappa = .5522848, - ox = (w / 2) * kappa, // control point offset horizontal - oy = (h / 2) * kappa, // control point offset vertical - xe = x + w, // x-end - ye = y + h, // y-end - xm = x + w / 2, // x-middle - ym = y + h / 2; // y-middle - - context.moveTo(x, ym); - context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - - context.closePath(); - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - - }; -} - -/* - * Renders a graphics mask - * - * @static - * @private - * @method renderGraphicsMask - * @param graphics {Graphics} - * @param context {Context2D} - */ -PIXI.CanvasGraphics.renderGraphicsMask = function(graphics, context) -{ - var worldAlpha = graphics.worldAlpha; - - var len = graphics.graphicsData.length; - if(len > 1) - { - len = 1; - console.log("Pixi.js warning: masks in canvas can only mask using the first path in the graphics object") - } - - for (var i=0; i < 1; i++) - { - var data = graphics.graphicsData[i]; - var points = data.points; - - if(data.type == PIXI.Graphics.POLY) - { - //if(data.lineWidth <= 0)continue; - - context.beginPath(); - context.moveTo(points[0], points[1]); - - for (var j=1; j < points.length/2; j++) - { - context.lineTo(points[j * 2], points[j * 2 + 1]); - } - - // if the first and last point are the same close the path - much neater :) - if(points[0] == points[points.length-2] && points[1] == points[points.length-1]) - { - context.closePath(); - } - - } - else if(data.type == PIXI.Graphics.RECT) - { - context.beginPath(); - context.rect(points[0], points[1], points[2], points[3]); - context.closePath(); - } - else if(data.type == PIXI.Graphics.CIRC) - { - // TODO - need to be Undefined! - context.beginPath(); - context.arc(points[0], points[1], points[2],0,2*Math.PI); - context.closePath(); - } - else if(data.type == PIXI.Graphics.ELIP) - { - - // elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - var elipseData = data.points; - - var w = elipseData[2] * 2; - var h = elipseData[3] * 2; - - var x = elipseData[0] - w/2; - var y = elipseData[1] - h/2; - - context.beginPath(); - - var kappa = .5522848, - ox = (w / 2) * kappa, // control point offset horizontal - oy = (h / 2) * kappa, // control point offset vertical - xe = x + w, // x-end - ye = y + h, // y-end - xm = x + w / 2, // x-middle - ym = y + h / 2; // y-middle - - context.moveTo(x, ym); - context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - context.closePath(); - } - - - }; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * The Graphics class contains a set of methods that you can use to create primitive shapes and lines. - * It is important to know that with the webGL renderer only simple polys can be filled at this stage - * Complex polys will not be filled. Heres an example of a complex poly: http://www.goodboydigital.com/wp-content/uploads/2013/06/complexPolygon.png - * - * @class Graphics - * @extends DisplayObjectContainer - * @constructor - */ -PIXI.Graphics = function() -{ - PIXI.DisplayObjectContainer.call( this ); - - this.renderable = true; - - /** - * The alpha of the fill of this graphics object - * - * @property fillAlpha - * @type Number - */ - this.fillAlpha = 1; - - /** - * The width of any lines drawn - * - * @property lineWidth - * @type Number - */ - this.lineWidth = 0; - - /** - * The color of any lines drawn - * - * @property lineColor - * @type String - */ - this.lineColor = "black"; - - /** - * Graphics data - * - * @property graphicsData - * @type Array - * @private - */ - this.graphicsData = []; - - /** - * Current path - * - * @property currentPath - * @type Object - * @private - */ - this.currentPath = {points:[]}; -} - -// constructor -PIXI.Graphics.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Graphics.prototype.constructor = PIXI.Graphics; - -/** - * Specifies a line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method. - * - * @method lineStyle - * @param lineWidth {Number} width of the line to draw, will update the object's stored style - * @param color {Number} color of the line to draw, will update the object's stored style - * @param alpha {Number} alpha of the line to draw, will update the object's stored style - */ -PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.lineWidth = lineWidth || 0; - this.lineColor = color || 0; - this.lineAlpha = (alpha == undefined) ? 1 : alpha; - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; - - this.graphicsData.push(this.currentPath); -} - -/** - * Moves the current drawing position to (x, y). - * - * @method moveTo - * @param x {Number} the X coord to move to - * @param y {Number} the Y coord to move to - */ -PIXI.Graphics.prototype.moveTo = function(x, y) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; - - this.currentPath.points.push(x, y); - - this.graphicsData.push(this.currentPath); -} - -/** - * Draws a line using the current line style from the current drawing position to (x, y); - * the current drawing position is then set to (x, y). - * - * @method lineTo - * @param x {Number} the X coord to draw to - * @param y {Number} the Y coord to draw to - */ -PIXI.Graphics.prototype.lineTo = function(x, y) -{ - this.currentPath.points.push(x, y); - this.dirty = true; -} - -/** - * Specifies a simple one-color fill that subsequent calls to other Graphics methods - * (such as lineTo() or drawCircle()) use when drawing. - * - * @method beginFill - * @param color {uint} the color of the fill - * @param alpha {Number} the alpha - */ -PIXI.Graphics.prototype.beginFill = function(color, alpha) -{ - this.filling = true; - this.fillColor = color || 0; - this.fillAlpha = alpha || 1; -} - -/** - * Applies a fill to the lines and shapes that were added since the last call to the beginFill() method. - * - * @method endFill - */ -PIXI.Graphics.prototype.endFill = function() -{ - this.filling = false; - this.fillColor = null; - this.fillAlpha = 1; -} - -/** - * @method drawRect - * - * @param x {Number} The X coord of the top-left of the rectangle - * @param y {Number} The Y coord of the top-left of the rectangle - * @param width {Number} The width of the rectangle - * @param height {Number} The height of the rectangle - */ -PIXI.Graphics.prototype.drawRect = function( x, y, width, height ) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, width, height], type:PIXI.Graphics.RECT}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Draws a circle. - * - * @method drawCircle - * @param x {Number} The X coord of the center of the circle - * @param y {Number} The Y coord of the center of the circle - * @param radius {Number} The radius of the circle - */ -PIXI.Graphics.prototype.drawCircle = function( x, y, radius) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, radius, radius], type:PIXI.Graphics.CIRC}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Draws an elipse. - * - * @method drawElipse - * @param x {Number} - * @param y {Number} - * @param width {Number} - * @param height {Number} - */ -PIXI.Graphics.prototype.drawElipse = function( x, y, width, height) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, width, height], type:PIXI.Graphics.ELIP}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings. - * - * @method clear - */ -PIXI.Graphics.prototype.clear = function() -{ - this.lineWidth = 0; - this.filling = false; - - this.dirty = true; - this.clearDirty = true; - this.graphicsData = []; -} - -// SOME TYPES: -PIXI.Graphics.POLY = 0; -PIXI.Graphics.RECT = 1; -PIXI.Graphics.CIRC = 2; -PIXI.Graphics.ELIP = 3; - -/** - * @author Mat Groves http://matgroves.com/ - */ - -PIXI.Strip = function(texture, width, height) -{ - PIXI.DisplayObjectContainer.call( this ); - this.texture = texture; - this.blendMode = PIXI.blendModes.NORMAL; - - try - { - this.uvs = new Float32Array([0, 1, - 1, 1, - 1, 0, 0,1]); - - this.verticies = new Float32Array([0, 0, - 0,0, - 0,0, 0, - 0, 0]); - - this.colors = new Float32Array([1, 1, 1, 1]); - - this.indices = new Uint16Array([0, 1, 2, 3]); - } - catch(error) - { - this.uvs = [0, 1, - 1, 1, - 1, 0, 0,1]; - - this.verticies = [0, 0, - 0,0, - 0,0, 0, - 0, 0]; - - this.colors = [1, 1, 1, 1]; - - this.indices = [0, 1, 2, 3]; - } - - - /* - this.uvs = new Float32Array() - this.verticies = new Float32Array() - this.colors = new Float32Array() - this.indices = new Uint16Array() -*/ - this.width = width; - this.height = height; - - // load the texture! - if(texture.baseTexture.hasLoaded) - { - this.width = this.texture.frame.width; - this.height = this.texture.frame.height; - this.updateFrame = true; - } - else - { - this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); - } - - this.renderable = true; -} - -// constructor -PIXI.Strip.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Strip.prototype.constructor = PIXI.Strip; - -PIXI.Strip.prototype.setTexture = function(texture) -{ - //TODO SET THE TEXTURES - //TODO VISIBILITY - - // stop current texture - this.texture = texture; - this.width = texture.frame.width; - this.height = texture.frame.height; - this.updateFrame = true; -} - -PIXI.Strip.prototype.onTextureUpdate = function(event) -{ - this.updateFrame = true; -} -// some helper functions.. - - -/** - * @author Mat Groves http://matgroves.com/ - */ - - -PIXI.Rope = function(texture, points) -{ - PIXI.Strip.call( this, texture ); - this.points = points; - - try - { - this.verticies = new Float32Array( points.length * 4); - this.uvs = new Float32Array( points.length * 4); - this.colors = new Float32Array( points.length * 2); - this.indices = new Uint16Array( points.length * 2); - } - catch(error) - { - this.verticies = verticies - - this.uvs = uvs - this.colors = colors - this.indices = indices - } - - this.refresh(); -} - - -// constructor -PIXI.Rope.prototype = Object.create( PIXI.Strip.prototype ); -PIXI.Rope.prototype.constructor = PIXI.Rope; - -PIXI.Rope.prototype.refresh = function() -{ - var points = this.points; - if(points.length < 1)return; - - var uvs = this.uvs - var indices = this.indices; - var colors = this.colors; - - var lastPoint = points[0]; - var nextPoint; - var perp = {x:0, y:0}; - var point = points[0]; - - this.count-=0.2; - - - uvs[0] = 0 - uvs[1] = 1 - uvs[2] = 0 - uvs[3] = 1 - - colors[0] = 1; - colors[1] = 1; - - indices[0] = 0; - indices[1] = 1; - - var total = points.length; - - for (var i = 1; i < total; i++) - { - - var point = points[i]; - var index = i * 4; - // time to do some smart drawing! - var amount = i/(total-1) - - if(i%2) - { - uvs[index] = amount; - uvs[index+1] = 0; - - uvs[index+2] = amount - uvs[index+3] = 1 - - } - else - { - uvs[index] = amount - uvs[index+1] = 0 - - uvs[index+2] = amount - uvs[index+3] = 1 - } - - index = i * 2; - colors[index] = 1; - colors[index+1] = 1; - - index = i * 2; - indices[index] = index; - indices[index + 1] = index + 1; - - lastPoint = point; - } -} - -PIXI.Rope.prototype.updateTransform = function() -{ - - var points = this.points; - if(points.length < 1)return; - - var verticies = this.verticies - - var lastPoint = points[0]; - var nextPoint; - var perp = {x:0, y:0}; - var point = points[0]; - - this.count-=0.2; - - verticies[0] = point.x + perp.x - verticies[1] = point.y + perp.y //+ 200 - verticies[2] = point.x - perp.x - verticies[3] = point.y - perp.y//+200 - // time to do some smart drawing! - - var total = points.length; - - for (var i = 1; i < total; i++) - { - - var point = points[i]; - var index = i * 4; - - if(i < points.length-1) - { - nextPoint = points[i+1]; - } - else - { - nextPoint = point - } - - perp.y = -(nextPoint.x - lastPoint.x); - perp.x = nextPoint.y - lastPoint.y; - - var ratio = (1 - (i / (total-1))) * 10; - if(ratio > 1)ratio = 1; - - var perpLength = Math.sqrt(perp.x * perp.x + perp.y * perp.y); - var num = this.texture.height/2//(20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio; - perp.x /= perpLength; - perp.y /= perpLength; - - perp.x *= num; - perp.y *= num; - - verticies[index] = point.x + perp.x - verticies[index+1] = point.y + perp.y - verticies[index+2] = point.x - perp.x - verticies[index+3] = point.y - perp.y - - lastPoint = point; - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call( this ); -} - -PIXI.Rope.prototype.setTexture = function(texture) -{ - // stop current texture - this.texture = texture; - this.updateFrame = true; -} - - - - - -/** - * @author Mat Groves http://matgroves.com/ - */ - -/** - * A tiling sprite is a fast way of rendering a tiling image - * - * @class TilingSprite - * @extends DisplayObjectContainer - * @constructor - * @param texture {Texture} the texture of the tiling sprite - * @param width {Number} the width of the tiling sprite - * @param height {Number} the height of the tiling sprite - */ -PIXI.TilingSprite = function(texture, width, height) -{ - PIXI.DisplayObjectContainer.call( this ); - - /** - * The texture that the sprite is using - * - * @property texture - * @type Texture - */ - this.texture = texture; - - /** - * The width of the tiling sprite - * - * @property width - * @type Number - */ - this.width = width; - - /** - * The height of the tiling sprite - * - * @property height - * @type Number - */ - this.height = height; - - /** - * The scaling of the image that is being tiled - * - * @property tileScale - * @type Point - */ - this.tileScale = new PIXI.Point(1,1); - - /** - * The offset position of the image that is being tiled - * - * @property tilePosition - * @type Point - */ - this.tilePosition = new PIXI.Point(0,0); - - this.renderable = true; - - this.blendMode = PIXI.blendModes.NORMAL -} - -// constructor -PIXI.TilingSprite.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.TilingSprite.prototype.constructor = PIXI.TilingSprite; - -/** - * Sets the texture of the tiling sprite - * - * @method setTexture - * @param texture {Texture} The PIXI texture that is displayed by the sprite - */ -PIXI.TilingSprite.prototype.setTexture = function(texture) -{ - //TODO SET THE TEXTURES - //TODO VISIBILITY - - // stop current texture - this.texture = texture; - this.updateFrame = true; -} - -/** - * When the texture is updated, this event will fire to update the frame - * - * @method onTextureUpdate - * @param event - * @private - */ -PIXI.TilingSprite.prototype.onTextureUpdate = function(event) -{ - this.updateFrame = true; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi - * - * Awesome JS run time provided by EsotericSoftware - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -/** - * A class that enables the you to import and run your spine animations in pixi. - * Spine animation data needs to be loaded using the PIXI.AssetLoader or PIXI.SpineLoader before it can be used by this class - * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source - * - * @class Spine - * @extends DisplayObjectContainer - * @constructor - * @param url {String} The url of the spine anim file to be used - */ -PIXI.Spine = function(url) -{ - PIXI.DisplayObjectContainer.call(this); - - this.spineData = PIXI.AnimCache[url]; - - if(!this.spineData) - { - throw new Error("Spine data must be preloaded using PIXI.SpineLoader or PIXI.AssetLoader: " + url); - return; - } - - this.count = 0; - - this.sprites = []; - - this.skeleton = new spine.Skeleton(this.spineData); - this.skeleton.updateWorldTransform(); - - this.stateData = new spine.AnimationStateData(this.spineData); - this.state = new spine.AnimationState(this.stateData); - - // add the sprites.. - for (var i = 0; i < this.skeleton.drawOrder.length; i++) { - - var attachmentName = this.skeleton.drawOrder[i].data.attachmentName; - - // kind of an assumtion here. that its a png - if(!PIXI.TextureCache[attachmentName]) - { - attachmentName += ".png"; - } - - - var sprite = new PIXI.Sprite(PIXI.Texture.fromFrame(attachmentName)); - sprite.anchor.x = sprite.anchor.y = 0.5; - this.addChild(sprite); - this.sprites.push(sprite); - }; -} - -PIXI.Spine.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Spine.prototype.constructor = PIXI.Spine; - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.Spine.prototype.updateTransform = function() -{ - // TODO should make this time based really.. - this.state.update(1/60); - this.state.apply(this.skeleton); - this.skeleton.updateWorldTransform(); - - - for (var i = 0; i < this.skeleton.drawOrder.length; i++) - { - var slot = this.skeleton.drawOrder[i]; - - var x = slot.bone.worldX + slot.attachment.x * slot.bone.m00 + slot.attachment.y * slot.bone.m01 + slot.attachment.width * 0.5; - var y = slot.bone.worldY + slot.attachment.x * slot.bone.m10 + slot.attachment.y * slot.bone.m11 + slot.attachment.height * 0.5; - //console.log(x + ' : ' + y); - - - //console.log(slot.attachment.name) - if(slot.cacheName != slot.attachment.name) - { - var attachmentName = slot.attachment.name; - - if(!PIXI.TextureCache[attachmentName]) - { - attachmentName += ".png"; - } - - this.sprites[i].setTexture(PIXI.TextureCache[attachmentName]); - - slot.cacheName = slot.attachment.name; - } - - x += -((slot.attachment.width * (slot.bone.worldScaleX + slot.attachment.scaleX - 1))>>1); - y += -((slot.attachment.height * (slot.bone.worldScaleY + slot.attachment.scaleY - 1))>>1); - - - this.sprites[i].position.x = x; - this.sprites[i].position.y = y; - this.sprites[i].rotation = (-(slot.bone.worldRotation + slot.attachment.rotation)) * (Math.PI/180); - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call(this); -} - -/* - * Awesome JS run time provided by EsotericSoftware - * - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -var spine = {}; - -spine.BoneData = function (name, parent) { - this.name = name; - this.parent = parent; -}; -spine.BoneData.prototype = { - length: 0, - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1 -}; - -spine.SlotData = function (name, boneData) { - this.name = name; - this.boneData = boneData; -}; -spine.SlotData.prototype = { - r: 1, g: 1, b: 1, a: 1, - attachmentName: null -}; - -spine.Bone = function (boneData, parent) { - this.data = boneData; - this.parent = parent; - this.setToSetupPose(); -}; -spine.Bone.yDown = false; -spine.Bone.prototype = { - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1, - m00: 0, m01: 0, worldX: 0, // a b x - m10: 0, m11: 0, worldY: 0, // c d y - worldRotation: 0, - worldScaleX: 1, worldScaleY: 1, - updateWorldTransform: function (flipX, flipY) { - var parent = this.parent; - if (parent != null) { - this.worldX = this.x * parent.m00 + this.y * parent.m01 + parent.worldX; - this.worldY = this.x * parent.m10 + this.y * parent.m11 + parent.worldY; - this.worldScaleX = parent.worldScaleX * this.scaleX; - this.worldScaleY = parent.worldScaleY * this.scaleY; - this.worldRotation = parent.worldRotation + this.rotation; - } else { - this.worldX = this.x; - this.worldY = this.y; - this.worldScaleX = this.scaleX; - this.worldScaleY = this.scaleY; - this.worldRotation = this.rotation; - } - var radians = this.worldRotation * Math.PI / 180; - var cos = Math.cos(radians); - var sin = Math.sin(radians); - this.m00 = cos * this.worldScaleX; - this.m10 = sin * this.worldScaleX; - this.m01 = -sin * this.worldScaleY; - this.m11 = cos * this.worldScaleY; - if (flipX) { - this.m00 = -this.m00; - this.m01 = -this.m01; - } - if (flipY) { - this.m10 = -this.m10; - this.m11 = -this.m11; - } - if (spine.Bone.yDown) { - this.m10 = -this.m10; - this.m11 = -this.m11; - } - }, - setToSetupPose: function () { - var data = this.data; - this.x = data.x; - this.y = data.y; - this.rotation = data.rotation; - this.scaleX = data.scaleX; - this.scaleY = data.scaleY; - } -}; - -spine.Slot = function (slotData, skeleton, bone) { - this.data = slotData; - this.skeleton = skeleton; - this.bone = bone; - this.setToSetupPose(); -}; -spine.Slot.prototype = { - r: 1, g: 1, b: 1, a: 1, - _attachmentTime: 0, - attachment: null, - setAttachment: function (attachment) { - this.attachment = attachment; - this._attachmentTime = this.skeleton.time; - }, - setAttachmentTime: function (time) { - this._attachmentTime = this.skeleton.time - time; - }, - getAttachmentTime: function () { - return this.skeleton.time - this._attachmentTime; - }, - setToSetupPose: function () { - var data = this.data; - this.r = data.r; - this.g = data.g; - this.b = data.b; - this.a = data.a; - - var slotDatas = this.skeleton.data.slots; - for (var i = 0, n = slotDatas.length; i < n; i++) { - if (slotDatas[i] == data) { - this.setAttachment(!data.attachmentName ? null : this.skeleton.getAttachmentBySlotIndex(i, data.attachmentName)); - break; - } - } - } -}; - -spine.Skin = function (name) { - this.name = name; - this.attachments = {}; -}; -spine.Skin.prototype = { - addAttachment: function (slotIndex, name, attachment) { - this.attachments[slotIndex + ":" + name] = attachment; - }, - getAttachment: function (slotIndex, name) { - return this.attachments[slotIndex + ":" + name]; - }, - _attachAll: function (skeleton, oldSkin) { - for (var key in oldSkin.attachments) { - var colon = key.indexOf(":"); - var slotIndex = parseInt(key.substring(0, colon)); - var name = key.substring(colon + 1); - var slot = skeleton.slots[slotIndex]; - if (slot.attachment && slot.attachment.name == name) { - var attachment = this.getAttachment(slotIndex, name); - if (attachment) slot.setAttachment(attachment); - } - } - } -}; - -spine.Animation = function (name, timelines, duration) { - this.name = name; - this.timelines = timelines; - this.duration = duration; -}; -spine.Animation.prototype = { - apply: function (skeleton, time, loop) { - if (loop && this.duration != 0) time %= this.duration; - var timelines = this.timelines; - for (var i = 0, n = timelines.length; i < n; i++) - timelines[i].apply(skeleton, time, 1); - }, - mix: function (skeleton, time, loop, alpha) { - if (loop && this.duration != 0) time %= this.duration; - var timelines = this.timelines; - for (var i = 0, n = timelines.length; i < n; i++) - timelines[i].apply(skeleton, time, alpha); - } -}; - -spine.binarySearch = function (values, target, step) { - var low = 0; - var high = Math.floor(values.length / step) - 2; - if (high == 0) return step; - var current = high >>> 1; - while (true) { - if (values[(current + 1) * step] <= target) - low = current + 1; - else - high = current; - if (low == high) return (low + 1) * step; - current = (low + high) >>> 1; - } -}; -spine.linearSearch = function (values, target, step) { - for (var i = 0, last = values.length - step; i <= last; i += step) - if (values[i] > target) return i; - return -1; -}; - -spine.Curves = function (frameCount) { - this.curves = []; // dfx, dfy, ddfx, ddfy, dddfx, dddfy, ... - this.curves.length = (frameCount - 1) * 6; -}; -spine.Curves.prototype = { - setLinear: function (frameIndex) { - this.curves[frameIndex * 6] = 0/*LINEAR*/; - }, - setStepped: function (frameIndex) { - this.curves[frameIndex * 6] = -1/*STEPPED*/; - }, - /** Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next. - * cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of - * the difference between the keyframe's values. */ - setCurve: function (frameIndex, cx1, cy1, cx2, cy2) { - var subdiv_step = 1 / 10/*BEZIER_SEGMENTS*/; - var subdiv_step2 = subdiv_step * subdiv_step; - var subdiv_step3 = subdiv_step2 * subdiv_step; - var pre1 = 3 * subdiv_step; - var pre2 = 3 * subdiv_step2; - var pre4 = 6 * subdiv_step2; - var pre5 = 6 * subdiv_step3; - var tmp1x = -cx1 * 2 + cx2; - var tmp1y = -cy1 * 2 + cy2; - var tmp2x = (cx1 - cx2) * 3 + 1; - var tmp2y = (cy1 - cy2) * 3 + 1; - var i = frameIndex * 6; - var curves = this.curves; - curves[i] = cx1 * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3; - curves[i + 1] = cy1 * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3; - curves[i + 2] = tmp1x * pre4 + tmp2x * pre5; - curves[i + 3] = tmp1y * pre4 + tmp2y * pre5; - curves[i + 4] = tmp2x * pre5; - curves[i + 5] = tmp2y * pre5; - }, - getCurvePercent: function (frameIndex, percent) { - percent = percent < 0 ? 0 : (percent > 1 ? 1 : percent); - var curveIndex = frameIndex * 6; - var curves = this.curves; - var dfx = curves[curveIndex]; - if (!dfx/*LINEAR*/) return percent; - if (dfx == -1/*STEPPED*/) return 0; - var dfy = curves[curveIndex + 1]; - var ddfx = curves[curveIndex + 2]; - var ddfy = curves[curveIndex + 3]; - var dddfx = curves[curveIndex + 4]; - var dddfy = curves[curveIndex + 5]; - var x = dfx, y = dfy; - var i = 10/*BEZIER_SEGMENTS*/ - 2; - while (true) { - if (x >= percent) { - var lastX = x - dfx; - var lastY = y - dfy; - return lastY + (y - lastY) * (percent - lastX) / (x - lastX); - } - if (i == 0) break; - i--; - dfx += ddfx; - dfy += ddfy; - ddfx += dddfx; - ddfy += dddfy; - x += dfx; - y += dfy; - } - return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1. - } -}; - -spine.RotateTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, angle, ... - this.frames.length = frameCount * 2; -}; -spine.RotateTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, angle) { - frameIndex *= 2; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = angle; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 2]) { // Time is after last frame. - var amount = bone.data.rotation + frames[frames.length - 1] - bone.rotation; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - bone.rotation += amount * alpha; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 2); - var lastFrameValue = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex - 2/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 2 - 1, percent); - - var amount = frames[frameIndex + 1/*FRAME_VALUE*/] - lastFrameValue; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - amount = bone.data.rotation + (lastFrameValue + amount * percent) - bone.rotation; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - bone.rotation += amount * alpha; - } -}; - -spine.TranslateTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, x, y, ... - this.frames.length = frameCount * 3; -}; -spine.TranslateTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 3; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 3; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = x; - this.frames[frameIndex + 2] = y; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 3]) { // Time is after last frame. - bone.x += (bone.data.x + frames[frames.length - 2] - bone.x) * alpha; - bone.y += (bone.data.y + frames[frames.length - 1] - bone.y) * alpha; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 3); - var lastFrameX = frames[frameIndex - 2]; - var lastFrameY = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent); - bone.x += (bone.data.x + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.x) * alpha; - bone.y += (bone.data.y + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.y) * alpha; - } -}; - -spine.ScaleTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, x, y, ... - this.frames.length = frameCount * 3; -}; -spine.ScaleTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 3; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 3; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = x; - this.frames[frameIndex + 2] = y; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 3]) { // Time is after last frame. - bone.scaleX += (bone.data.scaleX - 1 + frames[frames.length - 2] - bone.scaleX) * alpha; - bone.scaleY += (bone.data.scaleY - 1 + frames[frames.length - 1] - bone.scaleY) * alpha; - - - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 3); - var lastFrameX = frames[frameIndex - 2]; - var lastFrameY = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent); - - bone.scaleX += (bone.data.scaleX - 1 + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.scaleX) * alpha; - bone.scaleY += (bone.data.scaleY - 1 + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.scaleY) * alpha; - } -}; - -spine.ColorTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, r, g, b, a, ... - this.frames.length = frameCount * 5; -}; -spine.ColorTimeline.prototype = { - slotIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 5; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = r; - this.frames[frameIndex + 2] = g; - this.frames[frameIndex + 3] = b; - this.frames[frameIndex + 4] = a; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - var slot = skeleton.slots[this.slotIndex]; - - if (time >= frames[frames.length - 5]) { // Time is after last frame. - var i = frames.length - 1; - slot.r = frames[i - 3]; - slot.g = frames[i - 2]; - slot.b = frames[i - 1]; - slot.a = frames[i]; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 5); - var lastFrameR = frames[frameIndex - 4]; - var lastFrameG = frames[frameIndex - 3]; - var lastFrameB = frames[frameIndex - 2]; - var lastFrameA = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex - 5/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 5 - 1, percent); - - var r = lastFrameR + (frames[frameIndex + 1/*FRAME_R*/] - lastFrameR) * percent; - var g = lastFrameG + (frames[frameIndex + 2/*FRAME_G*/] - lastFrameG) * percent; - var b = lastFrameB + (frames[frameIndex + 3/*FRAME_B*/] - lastFrameB) * percent; - var a = lastFrameA + (frames[frameIndex + 4/*FRAME_A*/] - lastFrameA) * percent; - if (alpha < 1) { - slot.r += (r - slot.r) * alpha; - slot.g += (g - slot.g) * alpha; - slot.b += (b - slot.b) * alpha; - slot.a += (a - slot.a) * alpha; - } else { - slot.r = r; - slot.g = g; - slot.b = b; - slot.a = a; - } - } -}; - -spine.AttachmentTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, ... - this.frames.length = frameCount; - this.attachmentNames = []; // time, ... - this.attachmentNames.length = frameCount; -}; -spine.AttachmentTimeline.prototype = { - slotIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, attachmentName) { - this.frames[frameIndex] = time; - this.attachmentNames[frameIndex] = attachmentName; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var frameIndex; - if (time >= frames[frames.length - 1]) // Time is after last frame. - frameIndex = frames.length - 1; - else - frameIndex = spine.binarySearch(frames, time, 1) - 1; - - var attachmentName = this.attachmentNames[frameIndex]; - //console.log(skeleton.slots[this.slotIndex]) - - // change the name! - // skeleton.slots[this.slotIndex].attachmentName = attachmentName; - - skeleton.slots[this.slotIndex].setAttachment(!attachmentName ? null : skeleton.getAttachmentBySlotIndex(this.slotIndex, attachmentName)); - } -}; - -spine.SkeletonData = function () { - this.bones = []; - this.slots = []; - this.skins = []; - this.animations = []; -}; -spine.SkeletonData.prototype = { - defaultSkin: null, - /** @return May be null. */ - findBone: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].name == boneName) return bones[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findBoneIndex: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].name == boneName) return i; - return -1; - }, - /** @return May be null. */ - findSlot: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) { - if (slots[i].name == slotName) return slot[i]; - } - return null; - }, - /** @return -1 if the bone was not found. */ - findSlotIndex: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].name == slotName) return i; - return -1; - }, - /** @return May be null. */ - findSkin: function (skinName) { - var skins = this.skins; - for (var i = 0, n = skins.length; i < n; i++) - if (skins[i].name == skinName) return skins[i]; - return null; - }, - /** @return May be null. */ - findAnimation: function (animationName) { - var animations = this.animations; - for (var i = 0, n = animations.length; i < n; i++) - if (animations[i].name == animationName) return animations[i]; - return null; - } -}; - -spine.Skeleton = function (skeletonData) { - this.data = skeletonData; - - this.bones = []; - for (var i = 0, n = skeletonData.bones.length; i < n; i++) { - var boneData = skeletonData.bones[i]; - var parent = !boneData.parent ? null : this.bones[skeletonData.bones.indexOf(boneData.parent)]; - this.bones.push(new spine.Bone(boneData, parent)); - } - - this.slots = []; - this.drawOrder = []; - for (var i = 0, n = skeletonData.slots.length; i < n; i++) { - var slotData = skeletonData.slots[i]; - var bone = this.bones[skeletonData.bones.indexOf(slotData.boneData)]; - var slot = new spine.Slot(slotData, this, bone); - this.slots.push(slot); - this.drawOrder.push(slot); - } -}; -spine.Skeleton.prototype = { - x: 0, y: 0, - skin: null, - r: 1, g: 1, b: 1, a: 1, - time: 0, - flipX: false, flipY: false, - /** Updates the world transform for each bone. */ - updateWorldTransform: function () { - var flipX = this.flipX; - var flipY = this.flipY; - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - bones[i].updateWorldTransform(flipX, flipY); - }, - /** Sets the bones and slots to their setup pose values. */ - setToSetupPose: function () { - this.setBonesToSetupPose(); - this.setSlotsToSetupPose(); - }, - setBonesToSetupPose: function () { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - bones[i].setToSetupPose(); - }, - setSlotsToSetupPose: function () { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - slots[i].setToSetupPose(i); - }, - /** @return May return null. */ - getRootBone: function () { - return this.bones.length == 0 ? null : this.bones[0]; - }, - /** @return May be null. */ - findBone: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].data.name == boneName) return bones[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findBoneIndex: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].data.name == boneName) return i; - return -1; - }, - /** @return May be null. */ - findSlot: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].data.name == slotName) return slots[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findSlotIndex: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].data.name == slotName) return i; - return -1; - }, - setSkinByName: function (skinName) { - var skin = this.data.findSkin(skinName); - if (!skin) throw "Skin not found: " + skinName; - this.setSkin(skin); - }, - /** Sets the skin used to look up attachments not found in the {@link SkeletonData#getDefaultSkin() default skin}. Attachments - * from the new skin are attached if the corresponding attachment from the old skin was attached. - * @param newSkin May be null. */ - setSkin: function (newSkin) { - if (this.skin && newSkin) newSkin._attachAll(this, this.skin); - this.skin = newSkin; - }, - /** @return May be null. */ - getAttachmentBySlotName: function (slotName, attachmentName) { - return this.getAttachmentBySlotIndex(this.data.findSlotIndex(slotName), attachmentName); - }, - /** @return May be null. */ - getAttachmentBySlotIndex: function (slotIndex, attachmentName) { - if (this.skin) { - var attachment = this.skin.getAttachment(slotIndex, attachmentName); - if (attachment) return attachment; - } - if (this.data.defaultSkin) return this.data.defaultSkin.getAttachment(slotIndex, attachmentName); - return null; - }, - /** @param attachmentName May be null. */ - setAttachment: function (slotName, attachmentName) { - var slots = this.slots; - for (var i = 0, n = slots.size; i < n; i++) { - var slot = slots[i]; - if (slot.data.name == slotName) { - var attachment = null; - if (attachmentName) { - - attachment = this.getAttachment(i, attachmentName); - if (attachment == null) throw "Attachment not found: " + attachmentName + ", for slot: " + slotName; - } - - slot.setAttachment(attachment); - return; - } - } - throw "Slot not found: " + slotName; - }, - update: function (delta) { - time += delta; - } -}; - -spine.AttachmentType = { - region: 0 -}; - -spine.RegionAttachment = function () { - this.offset = []; - this.offset.length = 8; - this.uvs = []; - this.uvs.length = 8; -}; -spine.RegionAttachment.prototype = { - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1, - width: 0, height: 0, - rendererObject: null, - regionOffsetX: 0, regionOffsetY: 0, - regionWidth: 0, regionHeight: 0, - regionOriginalWidth: 0, regionOriginalHeight: 0, - setUVs: function (u, v, u2, v2, rotate) { - var uvs = this.uvs; - if (rotate) { - uvs[2/*X2*/] = u; - uvs[3/*Y2*/] = v2; - uvs[4/*X3*/] = u; - uvs[5/*Y3*/] = v; - uvs[6/*X4*/] = u2; - uvs[7/*Y4*/] = v; - uvs[0/*X1*/] = u2; - uvs[1/*Y1*/] = v2; - } else { - uvs[0/*X1*/] = u; - uvs[1/*Y1*/] = v2; - uvs[2/*X2*/] = u; - uvs[3/*Y2*/] = v; - uvs[4/*X3*/] = u2; - uvs[5/*Y3*/] = v; - uvs[6/*X4*/] = u2; - uvs[7/*Y4*/] = v2; - } - }, - updateOffset: function () { - var regionScaleX = this.width / this.regionOriginalWidth * this.scaleX; - var regionScaleY = this.height / this.regionOriginalHeight * this.scaleY; - var localX = -this.width / 2 * this.scaleX + this.regionOffsetX * regionScaleX; - var localY = -this.height / 2 * this.scaleY + this.regionOffsetY * regionScaleY; - var localX2 = localX + this.regionWidth * regionScaleX; - var localY2 = localY + this.regionHeight * regionScaleY; - var radians = this.rotation * Math.PI / 180; - var cos = Math.cos(radians); - var sin = Math.sin(radians); - var localXCos = localX * cos + this.x; - var localXSin = localX * sin; - var localYCos = localY * cos + this.y; - var localYSin = localY * sin; - var localX2Cos = localX2 * cos + this.x; - var localX2Sin = localX2 * sin; - var localY2Cos = localY2 * cos + this.y; - var localY2Sin = localY2 * sin; - var offset = this.offset; - offset[0/*X1*/] = localXCos - localYSin; - offset[1/*Y1*/] = localYCos + localXSin; - offset[2/*X2*/] = localXCos - localY2Sin; - offset[3/*Y2*/] = localY2Cos + localXSin; - offset[4/*X3*/] = localX2Cos - localY2Sin; - offset[5/*Y3*/] = localY2Cos + localX2Sin; - offset[6/*X4*/] = localX2Cos - localYSin; - offset[7/*Y4*/] = localYCos + localX2Sin; - }, - computeVertices: function (x, y, bone, vertices) { - - x += bone.worldX; - y += bone.worldY; - var m00 = bone.m00; - var m01 = bone.m01; - var m10 = bone.m10; - var m11 = bone.m11; - var offset = this.offset; - vertices[0/*X1*/] = offset[0/*X1*/] * m00 + offset[1/*Y1*/] * m01 + x; - vertices[1/*Y1*/] = offset[0/*X1*/] * m10 + offset[1/*Y1*/] * m11 + y; - vertices[2/*X2*/] = offset[2/*X2*/] * m00 + offset[3/*Y2*/] * m01 + x; - vertices[3/*Y2*/] = offset[2/*X2*/] * m10 + offset[3/*Y2*/] * m11 + y; - vertices[4/*X3*/] = offset[4/*X3*/] * m00 + offset[5/*X3*/] * m01 + x; - vertices[5/*X3*/] = offset[4/*X3*/] * m10 + offset[5/*X3*/] * m11 + y; - vertices[6/*X4*/] = offset[6/*X4*/] * m00 + offset[7/*Y4*/] * m01 + x; - vertices[7/*Y4*/] = offset[6/*X4*/] * m10 + offset[7/*Y4*/] * m11 + y; - } -} - -spine.AnimationStateData = function (skeletonData) { - this.skeletonData = skeletonData; - this.animationToMixTime = {}; -}; -spine.AnimationStateData.prototype = { - setMixByName: function (fromName, toName, duration) { - var from = this.skeletonData.findAnimation(fromName); - if (!from) throw "Animation not found: " + fromName; - var to = this.skeletonData.findAnimation(toName); - if (!to) throw "Animation not found: " + toName; - this.setMix(from, to, duration); - }, - setMix: function (from, to, duration) { - this.animationToMixTime[from.name + ":" + to.name] = duration; - }, - getMix: function (from, to) { - var time = this.animationToMixTime[from.name + ":" + to.name]; - return time ? time : 0; - } -}; - -spine.AnimationState = function (stateData) { - this.data = stateData; - this.queue = []; -}; -spine.AnimationState.prototype = { - current: null, - previous: null, - currentTime: 0, - previousTime: 0, - currentLoop: false, - previousLoop: false, - mixTime: 0, - mixDuration: 0, - update: function (delta) { - this.currentTime += delta; - this.previousTime += delta; - this.mixTime += delta; - - if (this.queue.length > 0) { - var entry = this.queue[0]; - if (this.currentTime >= entry.delay) { - this._setAnimation(entry.animation, entry.loop); - this.queue.shift(); - } - } - }, - apply: function (skeleton) { - if (!this.current) return; - if (this.previous) { - this.previous.apply(skeleton, this.previousTime, this.previousLoop); - var alpha = this.mixTime / this.mixDuration; - if (alpha >= 1) { - alpha = 1; - this.previous = null; - } - this.current.mix(skeleton, this.currentTime, this.currentLoop, alpha); - } else - this.current.apply(skeleton, this.currentTime, this.currentLoop); - }, - clearAnimation: function () { - this.previous = null; - this.current = null; - this.queue.length = 0; - }, - _setAnimation: function (animation, loop) { - this.previous = null; - if (animation && this.current) { - this.mixDuration = this.data.getMix(this.current, animation); - if (this.mixDuration > 0) { - this.mixTime = 0; - this.previous = this.current; - this.previousTime = this.currentTime; - this.previousLoop = this.currentLoop; - } - } - this.current = animation; - this.currentLoop = loop; - this.currentTime = 0; - }, - /** @see #setAnimation(Animation, Boolean) */ - setAnimationByName: function (animationName, loop) { - var animation = this.data.skeletonData.findAnimation(animationName); - if (!animation) throw "Animation not found: " + animationName; - this.setAnimation(animation, loop); - }, - /** Set the current animation. Any queued animations are cleared and the current animation time is set to 0. - * @param animation May be null. */ - setAnimation: function (animation, loop) { - this.queue.length = 0; - this._setAnimation(animation, loop); - }, - /** @see #addAnimation(Animation, Boolean, Number) */ - addAnimationByName: function (animationName, loop, delay) { - var animation = this.data.skeletonData.findAnimation(animationName); - if (!animation) throw "Animation not found: " + animationName; - this.addAnimation(animation, loop, delay); - }, - /** Adds an animation to be played delay seconds after the current or last queued animation. - * @param delay May be <= 0 to use duration of previous animation minus any mix duration plus the negative delay. */ - addAnimation: function (animation, loop, delay) { - var entry = {}; - entry.animation = animation; - entry.loop = loop; - - if (!delay || delay <= 0) { - var previousAnimation = this.queue.length == 0 ? this.current : this.queue[this.queue.length - 1].animation; - if (previousAnimation != null) - delay = previousAnimation.duration - this.data.getMix(previousAnimation, animation) + (delay || 0); - else - delay = 0; - } - entry.delay = delay; - - this.queue.push(entry); - }, - /** Returns true if no animation is set or if the current time is greater than the animation duration, regardless of looping. */ - isComplete: function () { - return !this.current || this.currentTime >= this.current.duration; - } -}; - -spine.SkeletonJson = function (attachmentLoader) { - this.attachmentLoader = attachmentLoader; -}; -spine.SkeletonJson.prototype = { - scale: 1, - readSkeletonData: function (root) { - var skeletonData = new spine.SkeletonData(); - - // Bones. - var bones = root["bones"]; - for (var i = 0, n = bones.length; i < n; i++) { - var boneMap = bones[i]; - var parent = null; - if (boneMap["parent"]) { - parent = skeletonData.findBone(boneMap["parent"]); - if (!parent) throw "Parent bone not found: " + boneMap["parent"]; - } - var boneData = new spine.BoneData(boneMap["name"], parent); - boneData.length = (boneMap["length"] || 0) * this.scale; - boneData.x = (boneMap["x"] || 0) * this.scale; - boneData.y = (boneMap["y"] || 0) * this.scale; - boneData.rotation = (boneMap["rotation"] || 0); - boneData.scaleX = boneMap["scaleX"] || 1; - boneData.scaleY = boneMap["scaleY"] || 1; - skeletonData.bones.push(boneData); - } - - // Slots. - var slots = root["slots"]; - for (var i = 0, n = slots.length; i < n; i++) { - var slotMap = slots[i]; - var boneData = skeletonData.findBone(slotMap["bone"]); - if (!boneData) throw "Slot bone not found: " + slotMap["bone"]; - var slotData = new spine.SlotData(slotMap["name"], boneData); - - var color = slotMap["color"]; - if (color) { - slotData.r = spine.SkeletonJson.toColor(color, 0); - slotData.g = spine.SkeletonJson.toColor(color, 1); - slotData.b = spine.SkeletonJson.toColor(color, 2); - slotData.a = spine.SkeletonJson.toColor(color, 3); - } - - slotData.attachmentName = slotMap["attachment"]; - - skeletonData.slots.push(slotData); - } - - // Skins. - var skins = root["skins"]; - for (var skinName in skins) { - if (!skins.hasOwnProperty(skinName)) continue; - var skinMap = skins[skinName]; - var skin = new spine.Skin(skinName); - for (var slotName in skinMap) { - if (!skinMap.hasOwnProperty(slotName)) continue; - var slotIndex = skeletonData.findSlotIndex(slotName); - var slotEntry = skinMap[slotName]; - for (var attachmentName in slotEntry) { - if (!slotEntry.hasOwnProperty(attachmentName)) continue; - var attachment = this.readAttachment(skin, attachmentName, slotEntry[attachmentName]); - if (attachment != null) skin.addAttachment(slotIndex, attachmentName, attachment); - } - } - skeletonData.skins.push(skin); - if (skin.name == "default") skeletonData.defaultSkin = skin; - } - - // Animations. - var animations = root["animations"]; - for (var animationName in animations) { - if (!animations.hasOwnProperty(animationName)) continue; - this.readAnimation(animationName, animations[animationName], skeletonData); - } - - return skeletonData; - }, - readAttachment: function (skin, name, map) { - name = map["name"] || name; - - var type = spine.AttachmentType[map["type"] || "region"]; - - // @ekelokorpi - // var attachment = this.attachmentLoader.newAttachment(skin, type, name); - var attachment = new spine.RegionAttachment(); - - // @Doormat23 - // add the name of the attachment - attachment.name = name; - - if (type == spine.AttachmentType.region) { - attachment.x = (map["x"] || 0) * this.scale; - attachment.y = (map["y"] || 0) * this.scale; - attachment.scaleX = map["scaleX"] || 1; - attachment.scaleY = map["scaleY"] || 1; - attachment.rotation = map["rotation"] || 0; - attachment.width = (map["width"] || 32) * this.scale; - attachment.height = (map["height"] || 32) * this.scale; - attachment.updateOffset(); - } - - return attachment; - }, - readAnimation: function (name, map, skeletonData) { - var timelines = []; - var duration = 0; - - var bones = map["bones"]; - for (var boneName in bones) { - if (!bones.hasOwnProperty(boneName)) continue; - var boneIndex = skeletonData.findBoneIndex(boneName); - if (boneIndex == -1) throw "Bone not found: " + boneName; - var boneMap = bones[boneName]; - - for (var timelineName in boneMap) { - if (!boneMap.hasOwnProperty(timelineName)) continue; - var values = boneMap[timelineName]; - if (timelineName == "rotate") { - var timeline = new spine.RotateTimeline(values.length); - timeline.boneIndex = boneIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - timeline.setFrame(frameIndex, valueMap["time"], valueMap["angle"]); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 2 - 2]); - - } else if (timelineName == "translate" || timelineName == "scale") { - var timeline; - var timelineScale = 1; - if (timelineName == "scale") - timeline = new spine.ScaleTimeline(values.length); - else { - timeline = new spine.TranslateTimeline(values.length); - timelineScale = this.scale; - } - timeline.boneIndex = boneIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - var x = (valueMap["x"] || 0) * timelineScale; - var y = (valueMap["y"] || 0) * timelineScale; - timeline.setFrame(frameIndex, valueMap["time"], x, y); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 3 - 3]); - - } else - throw "Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")"; - } - } - var slots = map["slots"]; - for (var slotName in slots) { - if (!slots.hasOwnProperty(slotName)) continue; - var slotMap = slots[slotName]; - var slotIndex = skeletonData.findSlotIndex(slotName); - - for (var timelineName in slotMap) { - if (!slotMap.hasOwnProperty(timelineName)) continue; - var values = slotMap[timelineName]; - if (timelineName == "color") { - var timeline = new spine.ColorTimeline(values.length); - timeline.slotIndex = slotIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - var color = valueMap["color"]; - var r = spine.SkeletonJson.toColor(color, 0); - var g = spine.SkeletonJson.toColor(color, 1); - var b = spine.SkeletonJson.toColor(color, 2); - var a = spine.SkeletonJson.toColor(color, 3); - timeline.setFrame(frameIndex, valueMap["time"], r, g, b, a); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 5 - 5]); - - } else if (timelineName == "attachment") { - var timeline = new spine.AttachmentTimeline(values.length); - timeline.slotIndex = slotIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - timeline.setFrame(frameIndex++, valueMap["time"], valueMap["name"]); - } - timelines.push(timeline); - // PIXI FIX - duration = Math.max(duration, timeline.frames[Math.floor(timeline.getFrameCount()) - 1]); - } else - throw "Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")"; - } - } - skeletonData.animations.push(new spine.Animation(name, timelines, duration)); - } -}; -spine.SkeletonJson.readCurve = function (timeline, frameIndex, valueMap) { - var curve = valueMap["curve"]; - if (!curve) return; - if (curve == "stepped") - timeline.curves.setStepped(frameIndex); - else if (curve instanceof Array) - timeline.curves.setCurve(frameIndex, curve[0], curve[1], curve[2], curve[3]); -}; -spine.SkeletonJson.toColor = function (hexString, colorIndex) { - if (hexString.length != 8) throw "Color hexidecimal length must be 8, recieved: " + hexString; - return parseInt(hexString.substring(colorIndex * 2, 2), 16) / 255; -}; - -spine.Atlas = function (atlasText, textureLoader) { - this.textureLoader = textureLoader; - this.pages = []; - this.regions = []; - - var reader = new spine.AtlasReader(atlasText); - var tuple = []; - tuple.length = 4; - var page = null; - while (true) { - var line = reader.readLine(); - if (line == null) break; - line = reader.trim(line); - if (line.length == 0) - page = null; - else if (!page) { - page = new spine.AtlasPage(); - page.name = line; - - page.format = spine.Atlas.Format[reader.readValue()]; - - reader.readTuple(tuple); - page.minFilter = spine.Atlas.TextureFilter[tuple[0]]; - page.magFilter = spine.Atlas.TextureFilter[tuple[1]]; - - var direction = reader.readValue(); - page.uWrap = spine.Atlas.TextureWrap.clampToEdge; - page.vWrap = spine.Atlas.TextureWrap.clampToEdge; - if (direction == "x") - page.uWrap = spine.Atlas.TextureWrap.repeat; - else if (direction == "y") - page.vWrap = spine.Atlas.TextureWrap.repeat; - else if (direction == "xy") - page.uWrap = page.vWrap = spine.Atlas.TextureWrap.repeat; - - textureLoader.load(page, line); - - this.pages.push(page); - - } else { - var region = new spine.AtlasRegion(); - region.name = line; - region.page = page; - - region.rotate = reader.readValue() == "true"; - - reader.readTuple(tuple); - var x = parseInt(tuple[0]); - var y = parseInt(tuple[1]); - - reader.readTuple(tuple); - var width = parseInt(tuple[0]); - var height = parseInt(tuple[1]); - - region.u = x / page.width; - region.v = y / page.height; - if (region.rotate) { - region.u2 = (x + height) / page.width; - region.v2 = (y + width) / page.height; - } else { - region.u2 = (x + width) / page.width; - region.v2 = (y + height) / page.height; - } - region.x = x; - region.y = y; - region.width = Math.abs(width); - region.height = Math.abs(height); - - if (reader.readTuple(tuple) == 4) { // split is optional - region.splits = [parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])]; - - if (reader.readTuple(tuple) == 4) { // pad is optional, but only present with splits - region.pads = [parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])]; - - reader.readTuple(tuple); - } - } - - region.originalWidth = parseInt(tuple[0]); - region.originalHeight = parseInt(tuple[1]); - - reader.readTuple(tuple); - region.offsetX = parseInt(tuple[0]); - region.offsetY = parseInt(tuple[1]); - - region.index = parseInt(reader.readValue()); - - this.regions.push(region); - } - } -}; -spine.Atlas.prototype = { - findRegion: function (name) { - var regions = this.regions; - for (var i = 0, n = regions.length; i < n; i++) - if (regions[i].name == name) return regions[i]; - return null; - }, - dispose: function () { - var pages = this.pages; - for (var i = 0, n = pages.length; i < n; i++) - this.textureLoader.unload(pages[i].rendererObject); - }, - updateUVs: function (page) { - var regions = this.regions; - for (var i = 0, n = regions.length; i < n; i++) { - var region = regions[i]; - if (region.page != page) continue; - region.u = region.x / page.width; - region.v = region.y / page.height; - if (region.rotate) { - region.u2 = (region.x + region.height) / page.width; - region.v2 = (region.y + region.width) / page.height; - } else { - region.u2 = (region.x + region.width) / page.width; - region.v2 = (region.y + region.height) / page.height; - } - } - } -}; - -spine.Atlas.Format = { - alpha: 0, - intensity: 1, - luminanceAlpha: 2, - rgb565: 3, - rgba4444: 4, - rgb888: 5, - rgba8888: 6 -}; - -spine.Atlas.TextureFilter = { - nearest: 0, - linear: 1, - mipMap: 2, - mipMapNearestNearest: 3, - mipMapLinearNearest: 4, - mipMapNearestLinear: 5, - mipMapLinearLinear: 6 -}; - -spine.Atlas.TextureWrap = { - mirroredRepeat: 0, - clampToEdge: 1, - repeat: 2 -}; - -spine.AtlasPage = function () {}; -spine.AtlasPage.prototype = { - name: null, - format: null, - minFilter: null, - magFilter: null, - uWrap: null, - vWrap: null, - rendererObject: null, - width: 0, - height: 0 -}; - -spine.AtlasRegion = function () {}; -spine.AtlasRegion.prototype = { - page: null, - name: null, - x: 0, y: 0, - width: 0, height: 0, - u: 0, v: 0, u2: 0, v2: 0, - offsetX: 0, offsetY: 0, - originalWidth: 0, originalHeight: 0, - index: 0, - rotate: false, - splits: null, - pads: null, -}; - -spine.AtlasReader = function (text) { - this.lines = text.split(/\r\n|\r|\n/); -}; -spine.AtlasReader.prototype = { - index: 0, - trim: function (value) { - return value.replace(/^\s+|\s+$/g, ""); - }, - readLine: function () { - if (this.index >= this.lines.length) return null; - return this.lines[this.index++]; - }, - readValue: function () { - var line = this.readLine(); - var colon = line.indexOf(":"); - if (colon == -1) throw "Invalid line: " + line; - return this.trim(line.substring(colon + 1)); - }, - /** Returns the number of tuple values read (2 or 4). */ - readTuple: function (tuple) { - var line = this.readLine(); - var colon = line.indexOf(":"); - if (colon == -1) throw "Invalid line: " + line; - var i = 0, lastMatch= colon + 1; - for (; i < 3; i++) { - var comma = line.indexOf(",", lastMatch); - if (comma == -1) { - if (i == 0) throw "Invalid line: " + line; - break; - } - tuple[i] = this.trim(line.substr(lastMatch, comma - lastMatch)); - lastMatch = comma + 1; - } - tuple[i] = this.trim(line.substring(lastMatch)); - return i + 1; - } -} - -spine.AtlasAttachmentLoader = function (atlas) { - this.atlas = atlas; -} -spine.AtlasAttachmentLoader.prototype = { - newAttachment: function (skin, type, name) { - switch (type) { - case spine.AttachmentType.region: - var region = this.atlas.findRegion(name); - if (!region) throw "Region not found in atlas: " + name + " (" + type + ")"; - var attachment = new spine.RegionAttachment(name); - attachment.rendererObject = region; - attachment.setUVs(region.u, region.v, region.u2, region.v2, region.rotate); - attachment.regionOffsetX = region.offsetX; - attachment.regionOffsetY = region.offsetY; - attachment.regionWidth = region.width; - attachment.regionHeight = region.height; - attachment.regionOriginalWidth = region.originalWidth; - attachment.regionOriginalHeight = region.originalHeight; - return attachment; - } - throw "Unknown attachment type: " + type; - } -} - -PIXI.AnimCache = {}; -spine.Bone.yDown = true; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * This object is one that will allow you to specify custom rendering functions based on render type - * - * @class CustomRenderable - * @extends DisplayObject - * @constructor - */ -PIXI.CustomRenderable = function() -{ - PIXI.DisplayObject.call( this ); - -} - -// constructor -PIXI.CustomRenderable.prototype = Object.create( PIXI.DisplayObject.prototype ); -PIXI.CustomRenderable.prototype.constructor = PIXI.CustomRenderable; - -/** - * If this object is being rendered by a CanvasRenderer it will call this callback - * - * @method renderCanvas - * @param renderer {CanvasRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.renderCanvas = function(renderer) -{ - // override! -} - -/** - * If this object is being rendered by a WebGLRenderer it will call this callback to initialize - * - * @method initWebGL - * @param renderer {WebGLRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.initWebGL = function(renderer) -{ - // override! -} - -/** - * If this object is being rendered by a WebGLRenderer it will call this callback - * - * @method renderWebGL - * @param renderer {WebGLRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.renderWebGL = function(renderGroup, projectionMatrix) -{ - // not sure if both needed? but ya have for now! - // override! -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI.BaseTextureCache = {}; -PIXI.texturesToUpdate = []; -PIXI.texturesToDestroy = []; - -/** - * A texture stores the information that represents an image. All textures have a base texture - * - * @class BaseTexture - * @uses EventTarget - * @constructor - * @param source {String} the source object (image or canvas) - */ -PIXI.BaseTexture = function(source) -{ - PIXI.EventTarget.call( this ); - - /** - * [read-only] The width of the base texture set when the image has loaded - * - * @property width - * @type Number - * @readOnly - */ - this.width = 100; - - /** - * [read-only] The height of the base texture set when the image has loaded - * - * @property height - * @type Number - * @readOnly - */ - this.height = 100; - - /** - * [read-only] Describes if the base texture has loaded or not - * - * @property hasLoaded - * @type Boolean - * @readOnly - */ - this.hasLoaded = false; - - /** - * The source that is loaded to create the texture - * - * @property source - * @type Image - */ - this.source = source; - - if(!source)return; - - if(this.source instanceof Image || this.source instanceof HTMLImageElement) - { - if(this.source.complete) - { - this.hasLoaded = true; - this.width = this.source.width; - this.height = this.source.height; - - PIXI.texturesToUpdate.push(this); - } - else - { - - var scope = this; - this.source.onload = function(){ - - scope.hasLoaded = true; - scope.width = scope.source.width; - scope.height = scope.source.height; - - // add it to somewhere... - PIXI.texturesToUpdate.push(scope); - scope.dispatchEvent( { type: 'loaded', content: scope } ); - } - // this.image.src = imageUrl; - } - } - else - { - this.hasLoaded = true; - this.width = this.source.width; - this.height = this.source.height; - - PIXI.texturesToUpdate.push(this); - } - - this._powerOf2 = false; -} - -PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; - -/** - * Destroys this base texture - * - * @method destroy - */ -PIXI.BaseTexture.prototype.destroy = function() -{ - if(this.source instanceof Image) - { - this.source.src = null; - } - this.source = null; - PIXI.texturesToDestroy.push(this); -} - -/** - * Helper function that returns a base texture based on an image url - * If the image is not in the base texture cache it will be created and loaded - * - * @static - * @method fromImage - * @param imageUrl {String} The image url of the texture - * @return BaseTexture - */ -PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin) -{ - var baseTexture = PIXI.BaseTextureCache[imageUrl]; - if(!baseTexture) - { - // new Image() breaks tex loading in some versions of Chrome. - // See https://code.google.com/p/chromium/issues/detail?id=238071 - var image = new Image();//document.createElement('img'); - if (crossorigin) - { - image.crossOrigin = ''; - } - image.src = imageUrl; - baseTexture = new PIXI.BaseTexture(image); - PIXI.BaseTextureCache[imageUrl] = baseTexture; - } - - return baseTexture; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI.TextureCache = {}; -PIXI.FrameCache = {}; - -/** - * A texture stores the information that represents an image or part of an image. It cannot be added - * to the display list directly. To do this use PIXI.Sprite. If no frame is provided then the whole image is used - * - * @class Texture - * @uses EventTarget - * @constructor - * @param baseTexture {BaseTexture} The base texture source to create the texture from - * @param frmae {Rectangle} The rectangle frame of the texture to show - */ -PIXI.Texture = function(baseTexture, frame) -{ - PIXI.EventTarget.call( this ); - - if(!frame) - { - this.noFrame = true; - frame = new PIXI.Rectangle(0,0,1,1); - } - - if(baseTexture instanceof PIXI.Texture) - baseTexture = baseTexture.baseTexture; - - /** - * The base texture of this texture - * - * @property baseTexture - * @type BaseTexture - */ - this.baseTexture = baseTexture; - - /** - * The frame specifies the region of the base texture that this texture uses - * - * @property frame - * @type Rectangle - */ - this.frame = frame; - - /** - * The trim point - * - * @property trim - * @type Point - */ - this.trim = new PIXI.Point(); - - this.scope = this; - - if(baseTexture.hasLoaded) - { - if(this.noFrame)frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); - //console.log(frame) - - this.setFrame(frame); - } - else - { - var scope = this; - baseTexture.addEventListener( 'loaded', function(){ scope.onBaseTextureLoaded()} ); - } -} - -PIXI.Texture.prototype.constructor = PIXI.Texture; - -/** - * Called when the base texture is loaded - * - * @method onBaseTextureLoaded - * @param event - * @private - */ -PIXI.Texture.prototype.onBaseTextureLoaded = function(event) -{ - var baseTexture = this.baseTexture; - baseTexture.removeEventListener( 'loaded', this.onLoaded ); - - if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); - this.noFrame = false; - this.width = this.frame.width; - this.height = this.frame.height; - - this.scope.dispatchEvent( { type: 'update', content: this } ); -} - -/** - * Destroys this texture - * - * @method destroy - * @param destroyBase {Boolean} Whether to destroy the base texture as well - */ -PIXI.Texture.prototype.destroy = function(destroyBase) -{ - if(destroyBase)this.baseTexture.destroy(); -} - -/** - * Specifies the rectangle region of the baseTexture - * - * @method setFrame - * @param frame {Rectangle} The frame of the texture to set it to - */ -PIXI.Texture.prototype.setFrame = function(frame) -{ - this.frame = frame; - this.width = frame.width; - this.height = frame.height; - - if(frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error("Texture Error: frame does not fit inside the base Texture dimensions " + this); - } - - this.updateFrame = true; - - PIXI.Texture.frameUpdates.push(this); - //this.dispatchEvent( { type: 'update', content: this } ); -} - -/** - * Helper function that returns a texture based on an image url - * If the image is not in the texture cache it will be created and loaded - * - * @static - * @method fromImage - * @param imageUrl {String} The image url of the texture - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - * @return Texture - */ -PIXI.Texture.fromImage = function(imageUrl, crossorigin) -{ - var texture = PIXI.TextureCache[imageUrl]; - - if(!texture) - { - texture = new PIXI.Texture(PIXI.BaseTexture.fromImage(imageUrl, crossorigin)); - PIXI.TextureCache[imageUrl] = texture; - } - - return texture; -} - -/** - * Helper function that returns a texture based on a frame id - * If the frame id is not in the texture cache an error will be thrown - * - * @static - * @method fromFrame - * @param frameId {String} The frame id of the texture - * @return Texture - */ -PIXI.Texture.fromFrame = function(frameId) -{ - var texture = PIXI.TextureCache[frameId]; - if(!texture)throw new Error("The frameId '"+ frameId +"' does not exist in the texture cache " + this); - return texture; -} - -/** - * Helper function that returns a texture based on a canvas element - * If the canvas is not in the texture cache it will be created and loaded - * - * @static - * @method fromCanvas - * @param canvas {Canvas} The canvas element source of the texture - * @return Texture - */ -PIXI.Texture.fromCanvas = function(canvas) -{ - var baseTexture = new PIXI.BaseTexture(canvas); - return new PIXI.Texture(baseTexture); -} - - -/** - * Adds a texture to the textureCache. - * - * @static - * @method addTextureToCache - * @param texture {Texture} - * @param id {String} the id that the texture will be stored against. - */ -PIXI.Texture.addTextureToCache = function(texture, id) -{ - PIXI.TextureCache[id] = texture; -} - -/** - * Remove a texture from the textureCache. - * - * @static - * @method removeTextureFromCache - * @param id {String} the id of the texture to be removed - * @return {Texture} the texture that was removed - */ -PIXI.Texture.removeTextureFromCache = function(id) -{ - var texture = PIXI.TextureCache[id] - PIXI.TextureCache[id] = null; - return texture; -} - -// this is more for webGL.. it contains updated frames.. -PIXI.Texture.frameUpdates = []; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - A RenderTexture is a special texture that allows any pixi displayObject to be rendered to it. - - __Hint__: All DisplayObjects (exmpl. Sprites) that renders on RenderTexture should be preloaded. - Otherwise black rectangles will be drawn instead. - - RenderTexture takes snapshot of DisplayObject passed to render method. If DisplayObject is passed to render method, position and rotation of it will be ignored. For example: - - var renderTexture = new PIXI.RenderTexture(800, 600); - var sprite = PIXI.Sprite.fromImage("spinObj_01.png"); - sprite.position.x = 800/2; - sprite.position.y = 600/2; - sprite.anchor.x = 0.5; - sprite.anchor.y = 0.5; - renderTexture.render(sprite); - - Sprite in this case will be rendered to 0,0 position. To render this sprite at center DisplayObjectContainer should be used: - - var doc = new PIXI.DisplayObjectContainer(); - doc.addChild(sprite); - renderTexture.render(doc); // Renders to center of renderTexture - - @class RenderTexture - @extends Texture - @constructor - @param width {Number} The width of the render texture - @param height {Number} The height of the render texture - */ -PIXI.RenderTexture = function(width, height) -{ - PIXI.EventTarget.call( this ); - - this.width = width || 100; - this.height = height || 100; - - this.indetityMatrix = PIXI.mat3.create(); - - this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); - - if(PIXI.gl) - { - this.initWebGL(); - } - else - { - this.initCanvas(); - } -} - -PIXI.RenderTexture.prototype = Object.create( PIXI.Texture.prototype ); -PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture; - -/** - * Initializes the webgl data for this texture - * - * @method initWebGL - * @private - */ -PIXI.RenderTexture.prototype.initWebGL = function() -{ - var gl = PIXI.gl; - this.glFramebuffer = gl.createFramebuffer(); - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - - this.glFramebuffer.width = this.width; - this.glFramebuffer.height = this.height; - - this.baseTexture = new PIXI.BaseTexture(); - - this.baseTexture.width = this.width; - this.baseTexture.height = this.height; - - this.baseTexture._glTexture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); - - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - - this.baseTexture.isRender = true; - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0); - - // create a projection matrix.. - this.projection = new PIXI.Point(this.width/2 , this.height/2); -/* - this.projectionMatrix = PIXI.mat4.create(); - - this.projectionMatrix[5] = 2/this.height// * 0.5; - this.projectionMatrix[13] = -1; - - this.projectionMatrix[0] = 2/this.width; - this.projectionMatrix[12] = -1; -*/ - // set the correct render function.. - this.render = this.renderWebGL; - - -} - - -PIXI.RenderTexture.prototype.resize = function(width, height) -{ - - this.width = width; - this.height = height; - - //this.frame.width = this.width - //this.frame.height = this.height; - - - if(PIXI.gl) - { - this.projection.x = this.width/2 - this.projection.y = this.height/2; - - var gl = PIXI.gl; - gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - } - else - { - - this.frame.width = this.width - this.frame.height = this.height; - this.renderer.resize(this.width, this.height); - } -} - -/** - * Initializes the canvas data for this texture - * - * @method initCanvas - * @private - */ -PIXI.RenderTexture.prototype.initCanvas = function() -{ - this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, 0); - - this.baseTexture = new PIXI.BaseTexture(this.renderer.view); - this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); - - this.render = this.renderCanvas; -} - -/** - * This function will draw the display object to the texture. - * - * @method renderWebGL - * @param displayObject {DisplayObject} The display object to render this texture on - * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn - * @private - */ -PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear) -{ - var gl = PIXI.gl; - - // enable the alpha color mask.. - gl.colorMask(true, true, true, true); - - gl.viewport(0, 0, this.width, this.height); - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - - if(clear) - { - gl.clearColor(0,0,0, 0); - gl.clear(gl.COLOR_BUFFER_BIT); - } - - // THIS WILL MESS WITH HIT TESTING! - var children = displayObject.children; - - //TODO -? create a new one??? dont think so! - displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix; - // modify to flip... - displayObject.worldTransform[4] = -1; - displayObject.worldTransform[5] = this.projection.y * 2; - - - if(position) - { - displayObject.worldTransform[2] = position.x; - displayObject.worldTransform[5] -= position.y; - } - - - - for(var i=0,j=children.length; i} assetURLs an array of image/sprite sheet urls that you would like loaded - * supported. Supported image formats include "jpeg", "jpg", "png", "gif". Supported - * sprite sheet data formats only include "JSON" at this time. Supported bitmap font - * data formats include "xml" and "fnt". - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.AssetLoader = function(assetURLs, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The array of asset URLs that are going to be loaded - * - * @property assetURLs - * @type Array - */ - this.assetURLs = assetURLs; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * Maps file extension to loader types - * - * @property loadersByType - * @type Object - */ - this.loadersByType = { - "jpg": PIXI.ImageLoader, - "jpeg": PIXI.ImageLoader, - "png": PIXI.ImageLoader, - "gif": PIXI.ImageLoader, - "json": PIXI.JsonLoader, - "anim": PIXI.SpineLoader, - "xml": PIXI.BitmapFontLoader, - "fnt": PIXI.BitmapFontLoader - }; - - -}; - -/** - * Fired when an item has loaded - * @event onProgress - */ - -/** - * Fired when all the assets have loaded - * @event onComplete - */ - -// constructor -PIXI.AssetLoader.prototype.constructor = PIXI.AssetLoader; - -/** - * Starts loading the assets sequentially - * - * @method load - */ -PIXI.AssetLoader.prototype.load = function() -{ - var scope = this; - - this.loadCount = this.assetURLs.length; - - for (var i=0; i < this.assetURLs.length; i++) - { - var fileName = this.assetURLs[i]; - var fileType = fileName.split(".").pop().toLowerCase(); - - var loaderClass = this.loadersByType[fileType]; - if(!loaderClass) - throw new Error(fileType + " is an unsupported file type"); - - var loader = new loaderClass(fileName, this.crossorigin); - - loader.addEventListener("loaded", function() - { - scope.onAssetLoaded(); - }); - loader.load(); - } -}; - -/** - * Invoked after each file is loaded - * - * @method onAssetLoaded - * @private - */ -PIXI.AssetLoader.prototype.onAssetLoaded = function() -{ - this.loadCount--; - this.dispatchEvent({type: "onProgress", content: this}); - if(this.onProgress) this.onProgress(); - - if(this.loadCount == 0) - { - this.dispatchEvent({type: "onComplete", content: this}); - if(this.onComplete) this.onComplete(); - } -}; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The json file loader is used to load in JSON data and parsing it - * When loaded this class will dispatch a "loaded" event - * If load failed this class will dispatch a "error" event - * - * @class JsonLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.JsonLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * [read-only] Whether the data has loaded yet - * - * @property loaded - * @type Boolean - * @readOnly - */ - this.loaded = false; - -}; - -// constructor -PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader; - -/** - * Loads the JSON data - * - * @method load - */ -PIXI.JsonLoader.prototype.load = function () { - this.ajaxRequest = new AjaxRequest(); - var scope = this; - this.ajaxRequest.onreadystatechange = function () { - scope.onJSONLoaded(); - }; - - this.ajaxRequest.open("GET", this.url, true); - if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json"); - this.ajaxRequest.send(null); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.JsonLoader.prototype.onJSONLoaded = function () { - if (this.ajaxRequest.readyState == 4) { - if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) { - this.json = JSON.parse(this.ajaxRequest.responseText); - - if(this.json.frames) - { - // sprite sheet - var scope = this; - var textureUrl = this.baseUrl + this.json.meta.image; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - var frameData = this.json.frames; - - this.texture = image.texture.baseTexture; - image.addEventListener("loaded", function (event) { - scope.onLoaded(); - }); - - for (var i in frameData) { - var rect = frameData[i].frame; - if (rect) { - PIXI.TextureCache[i] = new PIXI.Texture(this.texture, { - x: rect.x, - y: rect.y, - width: rect.w, - height: rect.h - }); - if (frameData[i].trimmed) { - //var realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w) - // calculate the offset! - } - } - } - - image.load(); - - } - else if(this.json.bones) - { - // spine animation - var spineJsonParser = new spine.SkeletonJson(); - var skeletonData = spineJsonParser.readSkeletonData(this.json); - PIXI.AnimCache[this.url] = skeletonData; - this.onLoaded(); - } - else - { - this.onLoaded(); - } - } - else - { - this.onError(); - } - } -}; - -/** - * Invoke when json file loaded - * - * @method onLoaded - * @private - */ -PIXI.JsonLoader.prototype.onLoaded = function () { - this.loaded = true; - this.dispatchEvent({ - type: "loaded", - content: this - }); -}; - -/** - * Invoke when error occured - * - * @method onError - * @private - */ -PIXI.JsonLoader.prototype.onError = function () { - this.dispatchEvent({ - type: "error", - content: this - }); -}; -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The sprite sheet loader is used to load in JSON sprite sheet data - * To generate the data you can use http://www.codeandweb.com/texturepacker and publish the "JSON" format - * There is a free version so thats nice, although the paid version is great value for money. - * It is highly recommended to use Sprite sheets (also know as texture atlas") as it means sprite"s can be batched and drawn together for highly increased rendering speed. - * Once the data has been loaded the frames are stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId() - * This loader will also load the image file that the Spritesheet points to as well as the data. - * When loaded this class will dispatch a "loaded" event - * - * @class SpriteSheetLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the sprite sheet JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ - -PIXI.SpriteSheetLoader = function (url, crossorigin) { - /* - * i use texture packer to load the assets.. - * http://www.codeandweb.com/texturepacker - * make sure to set the format as "JSON" - */ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * The texture being loaded - * - * @property texture - * @type Texture - */ - this.texture = null; - - /** - * The frames of the sprite sheet - * - * @property frames - * @type Object - */ - this.frames = {}; -}; - -// constructor -PIXI.SpriteSheetLoader.prototype.constructor = PIXI.SpriteSheetLoader; - -/** - * This will begin loading the JSON file - * - * @method load - */ -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; - scope.onJSONLoaded(); - }); - jsonLoader.load(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () { - var scope = this; - var textureUrl = this.baseUrl + this.json.meta.image; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - var frameData = this.json.frames; - - this.texture = image.texture.baseTexture; - image.addEventListener("loaded", function (event) { - scope.onLoaded(); - }); - - for (var i in frameData) { - var rect = frameData[i].frame; - if (rect) { - PIXI.TextureCache[i] = new PIXI.Texture(this.texture, { - x: rect.x, - y: rect.y, - width: rect.w, - height: rect.h - }); - if (frameData[i].trimmed) { - //var realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w) - // calculate the offset! - } - } - } - - image.load(); -}; -/** - * Invoke when all files are loaded (json and texture) - * - * @method onLoaded - * @private - */ -PIXI.SpriteSheetLoader.prototype.onLoaded = function () { - this.dispatchEvent({ - type: "loaded", - content: this - }); -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The image loader class is responsible for loading images file formats ("jpeg", "jpg", "png" and "gif") - * Once the image has been loaded it is stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId() - * When loaded this class will dispatch a 'loaded' event - * - * @class ImageLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the image - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.ImageLoader = function(url, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The texture being loaded - * - * @property texture - * @type Texture - */ - this.texture = PIXI.Texture.fromImage(url, crossorigin); -}; - -// constructor -PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader; - -/** - * Loads image or takes it from cache - * - * @method load - */ -PIXI.ImageLoader.prototype.load = function() -{ - if(!this.texture.baseTexture.hasLoaded) - { - var scope = this; - this.texture.baseTexture.addEventListener("loaded", function() - { - scope.onLoaded(); - }); - } - else - { - this.onLoaded(); - } -}; - -/** - * Invoked when image file is loaded or it is already cached and ready to use - * - * @method onLoaded - * @private - */ -PIXI.ImageLoader.prototype.onLoaded = function() -{ - this.dispatchEvent({type: "loaded", content: this}); -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The xml loader is used to load in XML bitmap font data ("xml" or "fnt") - * To generate the data you can use http://www.angelcode.com/products/bmfont/ - * This loader will also load the image file as the data. - * When loaded this class will dispatch a "loaded" event - * - * @class BitmapFontLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the sprite sheet JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.BitmapFontLoader = function(url, crossorigin) -{ - /* - * i use texture packer to load the assets.. - * http://www.codeandweb.com/texturepacker - * make sure to set the format as "JSON" - */ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * [read-only] The texture of the bitmap font - * - * @property baseUrl - * @type String - */ - this.texture = null; -}; - -// constructor -PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; - -/** - * Loads the XML font data - * - * @method load - */ -PIXI.BitmapFontLoader.prototype.load = function() -{ - this.ajaxRequest = new XMLHttpRequest(); - var scope = this; - this.ajaxRequest.onreadystatechange = function() - { - scope.onXMLLoaded(); - }; - - this.ajaxRequest.open("GET", this.url, true); - if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/xml"); - this.ajaxRequest.send(null) -}; - -/** - * Invoked when XML file is loaded, parses the data - * - * @method onXMLLoaded - * @private - */ -PIXI.BitmapFontLoader.prototype.onXMLLoaded = function() -{ - if (this.ajaxRequest.readyState == 4) - { - if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) - { - var textureUrl = this.baseUrl + this.ajaxRequest.responseXML.getElementsByTagName("page")[0].attributes.getNamedItem("file").nodeValue; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - this.texture = image.texture.baseTexture; - - var data = {}; - var info = this.ajaxRequest.responseXML.getElementsByTagName("info")[0]; - var common = this.ajaxRequest.responseXML.getElementsByTagName("common")[0]; - data.font = info.attributes.getNamedItem("face").nodeValue; - data.size = parseInt(info.attributes.getNamedItem("size").nodeValue, 10); - data.lineHeight = parseInt(common.attributes.getNamedItem("lineHeight").nodeValue, 10); - data.chars = {}; - - //parse letters - var letters = this.ajaxRequest.responseXML.getElementsByTagName("char"); - - for (var i = 0; i < letters.length; i++) - { - var charCode = parseInt(letters[i].attributes.getNamedItem("id").nodeValue, 10); - - var textureRect = { - x: parseInt(letters[i].attributes.getNamedItem("x").nodeValue, 10), - y: parseInt(letters[i].attributes.getNamedItem("y").nodeValue, 10), - width: parseInt(letters[i].attributes.getNamedItem("width").nodeValue, 10), - height: parseInt(letters[i].attributes.getNamedItem("height").nodeValue, 10) - }; - PIXI.TextureCache[charCode] = new PIXI.Texture(this.texture, textureRect); - - data.chars[charCode] = { - xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), - yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), - xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), - kerning: {}, - texture:new PIXI.Texture(this.texture, textureRect) - - }; - } - - //parse kernings - var kernings = this.ajaxRequest.responseXML.getElementsByTagName("kerning"); - for (i = 0; i < kernings.length; i++) - { - var first = parseInt(kernings[i].attributes.getNamedItem("first").nodeValue, 10); - var second = parseInt(kernings[i].attributes.getNamedItem("second").nodeValue, 10); - var amount = parseInt(kernings[i].attributes.getNamedItem("amount").nodeValue, 10); - - data.chars[second].kerning[first] = amount; - - } - - PIXI.BitmapText.fonts[data.font] = data; - - var scope = this; - image.addEventListener("loaded", function() { - scope.onLoaded(); - }); - image.load(); - } - } -}; - -/** - * Invoked when all files are loaded (xml/fnt and texture) - * - * @method onLoaded - * @private - */ -PIXI.BitmapFontLoader.prototype.onLoaded = function() -{ - this.dispatchEvent({type: "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 - * - * Awesome JS run time provided by EsotericSoftware - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -/** - * The Spine loader is used to load in JSON spine data - * To generate the data you need to use http://esotericsoftware.com/ and export the "JSON" format - * Due to a clash of names You will need to change the extension of the spine file from *.json to *.anim for it to load - * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source - * You will need to generate a sprite sheet to accompany the spine data - * When loaded this class will dispatch a "loaded" event - * - * @class Spine - * @uses EventTarget - * @constructor - * @param url {String} The url of the JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.SpineLoader = function(url, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] Whether the data has loaded yet - * - * @property loaded - * @type Boolean - * @readOnly - */ - this.loaded = false; -} - -PIXI.SpineLoader.prototype.constructor = PIXI.SpineLoader; - -/** - * Loads the JSON data - * - * @method load - */ -PIXI.SpineLoader.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; - scope.onJSONLoaded(); - }); - jsonLoader.load(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.SpineLoader.prototype.onJSONLoaded = function (event) { - var spineJsonParser = new spine.SkeletonJson(); - var skeletonData = spineJsonParser.readSkeletonData(this.json); - - PIXI.AnimCache[this.url] = skeletonData; - - this.onLoaded(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onLoaded - * @private - */ -PIXI.SpineLoader.prototype.onLoaded = function () { - this.loaded = true; - this.dispatchEvent({type: "loaded", content: this}); -}; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - if (typeof exports !== 'undefined') { - if (typeof module !== 'undefined' && module.exports) { - exports = module.exports = PIXI; - } - exports.PIXI = PIXI; - } else { - root.PIXI = PIXI; - } - - -}).call(this); \ No newline at end of file diff --git a/examples/example 14 - Masking/Copy of index.html b/examples/example 14 - Masking/Copy of index.html index e50c395..874e4ba 100644 --- a/examples/example 14 - Masking/Copy of index.html +++ b/examples/example 14 - Masking/Copy of index.html @@ -9,58 +9,58 @@ background-color: #000000; } - - + + + + + + + + + + diff --git a/examples/example 14 - Masking/index.html b/examples/example 14 - Masking/index.html index 6c0af87..230cbe8 100644 --- a/examples/example 14 - Masking/index.html +++ b/examples/example 14 - Masking/index.html @@ -9,81 +9,81 @@ background-color: #000000; } - - + + + + + + + + diff --git a/examples/example 15 - Filters/indexAll.html b/examples/example 15 - Filters/indexAll.html new file mode 100644 index 0000000..63fa2a2 --- /dev/null +++ b/examples/example 15 - Filters/indexAll.html @@ -0,0 +1,286 @@ + + + + pixi.js example 15 - Filters + + + + + + + + + + +
    + + + + + +
    + + + diff --git a/examples/example 15 - Filters/indexBlur.html b/examples/example 15 - Filters/indexBlur.html new file mode 100644 index 0000000..a2815b1 --- /dev/null +++ b/examples/example 15 - Filters/indexBlur.html @@ -0,0 +1,111 @@ + + + + pixi.js example 15 - Filters + + + + + + + + + + diff --git a/examples/example 15 - Filters/indexDisplacement.html b/examples/example 15 - Filters/indexDisplacement.html new file mode 100644 index 0000000..ad732b7 --- /dev/null +++ b/examples/example 15 - Filters/indexDisplacement.html @@ -0,0 +1,161 @@ + + + + pixi.js example 15 - Filters + + + + + + + + + + diff --git a/examples/example 15 - Filters/indexDisplacement_2.html b/examples/example 15 - Filters/indexDisplacement_2.html new file mode 100644 index 0000000..a20409b --- /dev/null +++ b/examples/example 15 - Filters/indexDisplacement_2.html @@ -0,0 +1,162 @@ + + + + pixi.js example 15 - Filters + + + + + + + + + + diff --git a/examples/example 15 - Filters/panda.png b/examples/example 15 - Filters/panda.png new file mode 100644 index 0000000..215a4a9 Binary files /dev/null and b/examples/example 15 - Filters/panda.png differ diff --git a/examples/example 15 - Filters/zeldaWaves.png b/examples/example 15 - Filters/zeldaWaves.png new file mode 100644 index 0000000..01552c0 Binary files /dev/null and b/examples/example 15 - Filters/zeldaWaves.png differ diff --git a/examples/example 2 - SpriteSheet/index.html b/examples/example 2 - SpriteSheet/index.html index 5d7a32c..18e838c 100644 --- a/examples/example 2 - SpriteSheet/index.html +++ b/examples/example 2 - SpriteSheet/index.html @@ -9,63 +9,63 @@ background-color: #000000; } - + - - - + - + @@ -39,7 +39,7 @@ renderer = PIXI.autoDetectRenderer(w, h); stage = new PIXI.Stage; - + document.body.appendChild(renderer.view); for (var i = 0; i < starCount; i++) @@ -77,10 +77,10 @@ { w = $(window).width() - 16; h = $(window).height() - 16; - + slideX = w / 2; slideY = h / 2; - + renderer.resize(w, h); } diff --git a/examples/example 4 - Balls/pixi.js b/examples/example 4 - Balls/pixi.js deleted file mode 100644 index a6e7055..0000000 --- a/examples/example 4 - Balls/pixi.js +++ /dev/null @@ -1,10438 +0,0 @@ -/** - * @license - * Pixi.JS - v1.3.0 - * Copyright (c) 2012, Mat Groves - * http://goodboydigital.com/ - * - * Compiled: 2013-07-24 - * - * Pixi.JS is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license.php - */ -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -(function(){ - - var root = this; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * @module PIXI - */ -var PIXI = PIXI || {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis. - * - * @class Point - * @constructor - * @param x {Number} position of the point - * @param y {Number} position of the point - */ -PIXI.Point = function(x, y) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; -} - -/** - * Creates a clone of this point - * - * @method clone - * @return {Point} a copy of the point - */ -PIXI.Point.prototype.clone = function() -{ - return new PIXI.Point(this.x, this.y); -} - -// constructor -PIXI.Point.prototype.constructor = PIXI.Point; - - -/** - * @author Mat Groves http://matgroves.com/ - */ - -/** - * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. - * - * @class Rectangle - * @constructor - * @param x {Number} The X coord of the upper-left corner of the rectangle - * @param y {Number} The Y coord of the upper-left corner of the rectangle - * @param width {Number} The overall wisth of this rectangle - * @param height {Number} The overall height of this rectangle - */ -PIXI.Rectangle = function(x, y, width, height) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property width - * @type Number - * @default 0 - */ - this.width = width || 0; - - /** - * @property height - * @type Number - * @default 0 - */ - this.height = height || 0; -} - -/** - * Creates a clone of this Rectangle - * - * @method clone - * @return {Rectangle} a copy of the rectangle - */ -PIXI.Rectangle.prototype.clone = function() -{ - return new PIXI.Rectangle(this.x, this.y, this.width, this.height); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this Rectangle - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this Rectangle - */ -PIXI.Rectangle.prototype.contains = function(x, y) -{ - if(this.width <= 0 || this.height <= 0) - return false; - - var x1 = this.x; - if(x > x1 && x < x1 + this.width) - { - var y1 = this.y; - - if(y > y1 && y < y1 + this.height) - { - return true; - } - } - - return false; -} - -// constructor -PIXI.Rectangle.prototype.constructor = PIXI.Rectangle; - - -/** - * @author Adrien Brault - */ - -/** - * @class Polygon - * @constructor - * @param points* {Array|Array|Point...|Number...} This can be an array of Points that form the polygon, - * a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arugments passed can be - * all the points of the polygon e.g. `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the - * arguments passed can be flat x,y values e.g. `new PIXI.Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are - * Numbers. - */ -PIXI.Polygon = function(points) -{ - //if points isn't an array, use arguments as the array - if(!(points instanceof Array)) - points = Array.prototype.slice.call(arguments); - - //if this is a flat array of numbers, convert it to points - if(typeof points[0] === 'number') { - var p = []; - for(var i = 0, il = points.length; i < il; i+=2) { - p.push( - new PIXI.Point(points[i], points[i + 1]) - ); - } - - points = p; - } - - this.points = points; -} - -/** - * Creates a clone of this polygon - * - * @method clone - * @return {Polygon} a copy of the polygon - */ -PIXI.Polygon.prototype.clone = function() -{ - var points = []; - for (var i=0; i y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi); - - if(intersect) inside = !inside; - } - - return inside; -} - -PIXI.Polygon.prototype.constructor = PIXI.Polygon; - - -/** - * @author Chad Engler - */ - -/** - * The Circle object can be used to specify a hit area for displayobjects - * - * @class Circle - * @constructor - * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this circle - * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this circle - * @param radius {Number} The radius of the circle - */ -PIXI.Circle = function(x, y, radius) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property radius - * @type Number - * @default 0 - */ - this.radius = radius || 0; -} - -/** - * Creates a clone of this Circle instance - * - * @method clone - * @return {Circle} a copy of the polygon - */ -PIXI.Circle.prototype.clone = function() -{ - return new PIXI.Circle(this.x, this.y, this.radius); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this circle - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this polygon - */ -PIXI.Circle.prototype.contains = function(x, y) -{ - if(this.radius <= 0) - return false; - - var dx = (this.x - x), - dy = (this.y - y), - r2 = this.radius * this.radius; - - dx *= dx; - dy *= dy; - - return (dx + dy <= r2); -} - -PIXI.Circle.prototype.constructor = PIXI.Circle; - - -/** - * @author Chad Engler - */ - -/** - * The Ellipse object can be used to specify a hit area for displayobjects - * - * @class Ellipse - * @constructor - * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this ellipse - * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this ellipse - * @param width {Number} The overall height of this ellipse - * @param height {Number} The overall width of this ellipse - */ -PIXI.Ellipse = function(x, y, width, height) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property width - * @type Number - * @default 0 - */ - this.width = width || 0; - - /** - * @property height - * @type Number - * @default 0 - */ - this.height = height || 0; -} - -/** - * Creates a clone of this Ellipse instance - * - * @method clone - * @return {Ellipse} a copy of the ellipse - */ -PIXI.Ellipse.prototype.clone = function() -{ - return new PIXI.Ellipse(this.x, this.y, this.width, this.height); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this ellipse - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this ellipse - */ -PIXI.Ellipse.prototype.contains = function(x, y) -{ - if(this.width <= 0 || this.height <= 0) - return false; - - //normalize the coords to an ellipse with center 0,0 - //and a radius of 0.5 - var normx = ((x - this.x) / this.width) - 0.5, - normy = ((y - this.y) / this.height) - 0.5; - - normx *= normx; - normy *= normy; - - return (normx + normy < 0.25); -} - -PIXI.Ellipse.getBounds = function() -{ - return new PIXI.Rectangle(this.x, this.y, this.width, this.height); -} - -PIXI.Ellipse.prototype.constructor = PIXI.Ellipse; - - - - -/* - * A lighter version of the rad gl-matrix created by Brandon Jones, Colin MacKenzie IV - * you both rock! - */ - -function determineMatrixArrayType() { - PIXI.Matrix = (typeof Float32Array !== 'undefined') ? Float32Array : Array; - return PIXI.Matrix; -} - -determineMatrixArrayType(); - -PIXI.mat3 = {}; - -PIXI.mat3.create = function() -{ - var matrix = new PIXI.Matrix(9); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 1; - matrix[5] = 0; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 1; - - return matrix; -} - - -PIXI.mat3.identity = function(matrix) -{ - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 1; - matrix[5] = 0; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 1; - - return matrix; -} - - -PIXI.mat4 = {}; - -PIXI.mat4.create = function() -{ - var matrix = new PIXI.Matrix(16); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 0; - matrix[5] = 1; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 0; - matrix[9] = 0; - matrix[10] = 1; - matrix[11] = 0; - matrix[12] = 0; - matrix[13] = 0; - matrix[14] = 0; - matrix[15] = 1; - - return matrix; -} - -PIXI.mat3.multiply = function (mat, mat2, dest) -{ - if (!dest) { dest = mat; } - - // Cache the matrix values (makes for huge speed increases!) - var a00 = mat[0], a01 = mat[1], a02 = mat[2], - a10 = mat[3], a11 = mat[4], a12 = mat[5], - a20 = mat[6], a21 = mat[7], a22 = mat[8], - - b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], - b10 = mat2[3], b11 = mat2[4], b12 = mat2[5], - b20 = mat2[6], b21 = mat2[7], b22 = mat2[8]; - - dest[0] = b00 * a00 + b01 * a10 + b02 * a20; - dest[1] = b00 * a01 + b01 * a11 + b02 * a21; - dest[2] = b00 * a02 + b01 * a12 + b02 * a22; - - dest[3] = b10 * a00 + b11 * a10 + b12 * a20; - dest[4] = b10 * a01 + b11 * a11 + b12 * a21; - dest[5] = b10 * a02 + b11 * a12 + b12 * a22; - - dest[6] = b20 * a00 + b21 * a10 + b22 * a20; - dest[7] = b20 * a01 + b21 * a11 + b22 * a21; - dest[8] = b20 * a02 + b21 * a12 + b22 * a22; - - return dest; -} - -PIXI.mat3.clone = function(mat) -{ - var matrix = new PIXI.Matrix(9); - - matrix[0] = mat[0]; - matrix[1] = mat[1]; - matrix[2] = mat[2]; - matrix[3] = mat[3]; - matrix[4] = mat[4]; - matrix[5] = mat[5]; - matrix[6] = mat[6]; - matrix[7] = mat[7]; - matrix[8] = mat[8]; - - return matrix; -} - -PIXI.mat3.transpose = function (mat, dest) -{ - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (!dest || mat === dest) { - var a01 = mat[1], a02 = mat[2], - a12 = mat[5]; - - mat[1] = mat[3]; - mat[2] = mat[6]; - mat[3] = a01; - mat[5] = mat[7]; - mat[6] = a02; - mat[7] = a12; - return mat; - } - - dest[0] = mat[0]; - dest[1] = mat[3]; - dest[2] = mat[6]; - dest[3] = mat[1]; - dest[4] = mat[4]; - dest[5] = mat[7]; - dest[6] = mat[2]; - dest[7] = mat[5]; - dest[8] = mat[8]; - return dest; -} - -PIXI.mat3.toMat4 = function (mat, dest) -{ - if (!dest) { dest = PIXI.mat4.create(); } - - dest[15] = 1; - dest[14] = 0; - dest[13] = 0; - dest[12] = 0; - - dest[11] = 0; - dest[10] = mat[8]; - dest[9] = mat[7]; - dest[8] = mat[6]; - - dest[7] = 0; - dest[6] = mat[5]; - dest[5] = mat[4]; - dest[4] = mat[3]; - - dest[3] = 0; - dest[2] = mat[2]; - dest[1] = mat[1]; - dest[0] = mat[0]; - - return dest; -} - - -///// - - -PIXI.mat4.create = function() -{ - var matrix = new PIXI.Matrix(16); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 0; - matrix[5] = 1; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 0; - matrix[9] = 0; - matrix[10] = 1; - matrix[11] = 0; - matrix[12] = 0; - matrix[13] = 0; - matrix[14] = 0; - matrix[15] = 1; - - return matrix; -} - -PIXI.mat4.transpose = function (mat, dest) -{ - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (!dest || mat === dest) - { - var a01 = mat[1], a02 = mat[2], a03 = mat[3], - a12 = mat[6], a13 = mat[7], - a23 = mat[11]; - - mat[1] = mat[4]; - mat[2] = mat[8]; - mat[3] = mat[12]; - mat[4] = a01; - mat[6] = mat[9]; - mat[7] = mat[13]; - mat[8] = a02; - mat[9] = a12; - mat[11] = mat[14]; - mat[12] = a03; - mat[13] = a13; - mat[14] = a23; - return mat; - } - - dest[0] = mat[0]; - dest[1] = mat[4]; - dest[2] = mat[8]; - dest[3] = mat[12]; - dest[4] = mat[1]; - dest[5] = mat[5]; - dest[6] = mat[9]; - dest[7] = mat[13]; - dest[8] = mat[2]; - dest[9] = mat[6]; - dest[10] = mat[10]; - dest[11] = mat[14]; - dest[12] = mat[3]; - dest[13] = mat[7]; - dest[14] = mat[11]; - dest[15] = mat[15]; - return dest; -} - -PIXI.mat4.multiply = function (mat, mat2, dest) -{ - if (!dest) { dest = mat; } - - // Cache the matrix values (makes for huge speed increases!) - var a00 = mat[ 0], a01 = mat[ 1], a02 = mat[ 2], a03 = mat[3]; - var a10 = mat[ 4], a11 = mat[ 5], a12 = mat[ 6], a13 = mat[7]; - var a20 = mat[ 8], a21 = mat[ 9], a22 = mat[10], a23 = mat[11]; - var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15]; - - // Cache only the current line of the second matrix - var b0 = mat2[0], b1 = mat2[1], b2 = mat2[2], b3 = mat2[3]; - dest[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[4]; - b1 = mat2[5]; - b2 = mat2[6]; - b3 = mat2[7]; - dest[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[8]; - b1 = mat2[9]; - b2 = mat2[10]; - b3 = mat2[11]; - dest[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[12]; - b1 = mat2[13]; - b2 = mat2[14]; - b3 = mat2[15]; - dest[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - return dest; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The base class for all objects that are rendered on the screen. - * - * @class DisplayObject - * @constructor - */ -PIXI.DisplayObject = function() -{ - this.last = this; - this.first = this; - - /** - * The coordinate of the object relative to the local coordinates of the parent. - * - * @property position - * @type Point - */ - this.position = new PIXI.Point(); - - /** - * The scale factor of the object. - * - * @property scale - * @type Point - */ - this.scale = new PIXI.Point(1,1);//{x:1, y:1}; - - /** - * The pivot point of the displayObject that it rotates around - * - * @property pivot - * @type Point - */ - this.pivot = new PIXI.Point(0,0); - - /** - * The rotation of the object in radians. - * - * @property rotation - * @type Number - */ - this.rotation = 0; - - /** - * The opacity of the object. - * - * @property alpha - * @type Number - */ - this.alpha = 1; - - /** - * The visibility of the object. - * - * @property visible - * @type Boolean - */ - this.visible = true; - - /** - * This is the defined area that will pick up mouse / touch events. It is null by default. - * Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children) - * - * @property hitArea - * @type Rectangle|Circle|Ellipse|Polygon - */ - this.hitArea = null; - - /** - * This is used to indicate if the displayObject should display a mouse hand cursor on rollover - * - * @property buttonMode - * @type Boolean - */ - this.buttonMode = false; - - /** - * Can this object be rendered - * - * @property renderable - * @type Boolean - */ - this.renderable = false; - - /** - * [read-only] The visibility of the object based on world (parent) factors. - * - * @property worldVisible - * @type Boolean - * @readOnly - */ - this.worldVisible = false; - - /** - * [read-only] The display object container that contains this display object. - * - * @property parent - * @type DisplayObjectContainer - * @readOnly - */ - this.parent = null; - - /** - * [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage. - * - * @property stage - * @type Stage - * @readOnly - */ - this.stage = null; - - /** - * [read-only] The index of this object in the parent's `children` array - * - * @property childIndex - * @type Number - * @readOnly - */ - this.childIndex = 0; - - /** - * [read-only] The multiplied alpha of the displayobject - * - * @property worldAlpha - * @type Number - * @readOnly - */ - this.worldAlpha = 1; - - /** - * [read-only] Whether or not the object is interactive, do not toggle directly! use the `interactive` property - * - * @property _interactive - * @type Boolean - * @readOnly - * @private - */ - this._interactive = false; - - /** - * [read-only] Current transform of the object based on world (parent) factors - * - * @property worldTransform - * @type Mat3 - * @readOnly - * @private - */ - this.worldTransform = PIXI.mat3.create()//mat3.identity(); - - /** - * [read-only] Current transform of the object locally - * - * @property localTransform - * @type Mat3 - * @readOnly - * @private - */ - this.localTransform = PIXI.mat3.create()//mat3.identity(); - - /** - * [NYI] Unkown - * - * @property color - * @type Array<> - * @private - */ - this.color = []; - - /** - * [NYI] Holds whether or not this object is dynamic, for rendering optimization - * - * @property dynamic - * @type Boolean - * @private - */ - this.dynamic = true; - - // chach that puppy! - this._sr = 0; - this._cr = 1; - - /* - * MOUSE Callbacks - */ - - /** - * A callback that is used when the users clicks on the displayObject with their mouse - * @method click - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user clicks the mouse down over the sprite - * @method mousedown - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the mouse that was over the displayObject - * for this callback to be fired the mouse must have been pressed down over the displayObject - * @method mouseup - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject - * for this callback to be fired, The touch must have started over the displayObject - * @method mouseupoutside - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the users mouse rolls over the displayObject - * @method mouseover - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the users mouse leaves the displayObject - * @method mouseout - * @param interactionData {InteractionData} - */ - - - /* - * TOUCH Callbacks - */ - - /** - * A callback that is used when the users taps on the sprite with their finger - * basically a touch version of click - * @method tap - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user touch's over the displayObject - * @method touchstart - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases a touch over the displayObject - * @method touchend - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the touch that was over the displayObject - * for this callback to be fired, The touch must have started over the sprite - * @method touchendoutside - * @param interactionData {InteractionData} - */ -} - -// constructor -PIXI.DisplayObject.prototype.constructor = PIXI.DisplayObject; - -//TODO make visible a getter setter -/* -Object.defineProperty(PIXI.DisplayObject.prototype, 'visible', { - get: function() { - return this._visible; - }, - set: function(value) { - this._visible = value; - } -});*/ - -/** - * [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default - * Instead of using this function you can now simply set the interactive property to true or false - * - * @method setInteractive - * @param interactive {Boolean} - * @deprecated Simply set the `interactive` property directly - */ -PIXI.DisplayObject.prototype.setInteractive = function(interactive) -{ - this.interactive = interactive; -} - -/** - * Indicates if the sprite will have touch and mouse interactivity. It is false by default - * - * @property interactive - * @type Boolean - * @default false - */ -Object.defineProperty(PIXI.DisplayObject.prototype, 'interactive', { - get: function() { - return this._interactive; - }, - set: function(value) { - this._interactive = value; - - // TODO more to be done here.. - // need to sort out a re-crawl! - if(this.stage)this.stage.dirty = true; - } -}); - -/** - * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. - * In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. - * To remove a mask, set this property to null. - * - * @property mask - * @type Graphics - */ -Object.defineProperty(PIXI.DisplayObject.prototype, 'mask', { - get: function() { - return this._mask; - }, - set: function(value) { - - this._mask = value; - - if(value) - { - this.addFilter(value) - } - else - { - this.removeFilter(); - } - } -}); - -/* - * Adds a filter to this displayObject - * - * @method addFilter - * @param mask {Graphics} the graphics object to use as a filter - * @private - */ -PIXI.DisplayObject.prototype.addFilter = function(mask) -{ - if(this.filter)return; - this.filter = true; - - - // insert a filter block.. - var start = new PIXI.FilterBlock(); - var end = new PIXI.FilterBlock(); - - - start.mask = mask; - end.mask = mask; - - start.first = start.last = this; - end.first = end.last = this; - - start.open = true; - - /* - * - * insert start - * - */ - - var childFirst = start - var childLast = start - var nextObject; - var previousObject; - - previousObject = this.first._iPrev; - - if(previousObject) - { - nextObject = previousObject._iNext; - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - } - else - { - nextObject = this; - } - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - - // now insert the end filter block.. - - /* - * - * insert end filter - * - */ - var childFirst = end - var childLast = end - var nextObject = null; - var previousObject = null; - - previousObject = this.last; - nextObject = previousObject._iNext; - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - var updateLast = this; - - var prevLast = this.last; - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = end; - } - updateLast = updateLast.parent; - } - - this.first = start; - - // if webGL... - if(this.__renderGroup) - { - this.__renderGroup.addFilterBlocks(start, end); - } - - mask.renderable = false; - -} - -/* - * Removes the filter to this displayObject - * - * @method removeFilter - * @private - */ -PIXI.DisplayObject.prototype.removeFilter = function() -{ - if(!this.filter)return; - this.filter = false; - - // modify the list.. - var startBlock = this.first; - - var nextObject = startBlock._iNext; - var previousObject = startBlock._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - if(previousObject)previousObject._iNext = nextObject; - - this.first = startBlock._iNext; - - - // remove the end filter - var lastBlock = this.last; - - var nextObject = lastBlock._iNext; - var previousObject = lastBlock._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - previousObject._iNext = nextObject; - - // this is always true too! -// if(this.last == lastBlock) - //{ - var tempLast = lastBlock._iPrev; - // need to make sure the parents last is updated too - var updateLast = this; - while(updateLast.last == lastBlock) - { - updateLast.last = tempLast; - updateLast = updateLast.parent; - if(!updateLast)break; - } - - var mask = startBlock.mask - mask.renderable = true; - - // if webGL... - if(this.__renderGroup) - { - this.__renderGroup.removeFilterBlocks(startBlock, lastBlock); - } - //} -} - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.DisplayObject.prototype.updateTransform = function() -{ - // TODO OPTIMIZE THIS!! with dirty - if(this.rotation != this.rotationCache) - { - this.rotationCache = this.rotation; - this._sr = Math.sin(this.rotation); - this._cr = Math.cos(this.rotation); - } - - var localTransform = this.localTransform; - var parentTransform = this.parent.worldTransform; - var worldTransform = this.worldTransform; - //console.log(localTransform) - localTransform[0] = this._cr * this.scale.x; - localTransform[1] = -this._sr * this.scale.y - localTransform[3] = this._sr * this.scale.x; - localTransform[4] = this._cr * this.scale.y; - - // TODO --> do we even need a local matrix??? - - var px = this.pivot.x; - var py = this.pivot.y; - - // Cache the matrix values (makes for huge speed increases!) - var a00 = localTransform[0], a01 = localTransform[1], a02 = this.position.x - localTransform[0] * px - py * localTransform[1], - a10 = localTransform[3], a11 = localTransform[4], a12 = this.position.y - localTransform[4] * py - px * localTransform[3], - - b00 = parentTransform[0], b01 = parentTransform[1], b02 = parentTransform[2], - b10 = parentTransform[3], b11 = parentTransform[4], b12 = parentTransform[5]; - - localTransform[2] = a02 - localTransform[5] = a12 - - worldTransform[0] = b00 * a00 + b01 * a10; - worldTransform[1] = b00 * a01 + b01 * a11; - worldTransform[2] = b00 * a02 + b01 * a12 + b02; - - worldTransform[3] = b10 * a00 + b11 * a10; - worldTransform[4] = b10 * a01 + b11 * a11; - worldTransform[5] = b10 * a02 + b11 * a12 + b12; - - // because we are using affine transformation, we can optimise the matrix concatenation process.. wooo! - // mat3.multiply(this.localTransform, this.parent.worldTransform, this.worldTransform); - this.worldAlpha = this.alpha * this.parent.worldAlpha; - -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * A DisplayObjectContainer represents a collection of display objects. - * It is the base class of all display objects that act as a container for other objects. - * - * @class DisplayObjectContainer - * @extends DisplayObject - * @constructor - */ -PIXI.DisplayObjectContainer = function() -{ - PIXI.DisplayObject.call( this ); - - /** - * [read-only] The of children of this container. - * - * @property children - * @type Array - * @readOnly - */ - this.children = []; -} - -// constructor -PIXI.DisplayObjectContainer.prototype = Object.create( PIXI.DisplayObject.prototype ); -PIXI.DisplayObjectContainer.prototype.constructor = PIXI.DisplayObjectContainer; - -//TODO make visible a getter setter -/* -Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'visible', { - get: function() { - return this._visible; - }, - set: function(value) { - this._visible = value; - - } -});*/ - -/** - * Adds a child to the container. - * - * @method addChild - * @param child {DisplayObject} The DisplayObject to add to the container - */ -PIXI.DisplayObjectContainer.prototype.addChild = function(child) -{ - if(child.parent != undefined) - { - - //// COULD BE THIS??? - child.parent.removeChild(child); - // return; - } - - child.parent = this; - child.childIndex = this.children.length; - - this.children.push(child); - - // updae the stage refference.. - - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = this.stage; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // LINKED LIST // - - // modify the list.. - var childFirst = child.first - var childLast = child.last; - var nextObject; - var previousObject; - - // this could be wrong if there is a filter?? - if(this.filter) - { - previousObject = this.last._iPrev; - } - else - { - previousObject = this.last; - } - - nextObject = previousObject._iNext; - - // always true in this case - //this.last = child.last; - // need to make sure the parents last is updated too - var updateLast = this; - var prevLast = previousObject; - - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = child.last; - } - updateLast = updateLast.parent; - } - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - // need to remove any render groups.. - if(this.__renderGroup) - { - // being used by a renderTexture.. if it exists then it must be from a render texture; - if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child); - // add them to the new render group.. - this.__renderGroup.addDisplayObjectAndChildren(child); - } - -} - -/** - * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown - * - * @method addChildAt - * @param child {DisplayObject} The child to add - * @param index {Number} The index to place the child in - */ -PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index) -{ - if(index >= 0 && index <= this.children.length) - { - if(child.parent != undefined) - { - child.parent.removeChild(child); - } - child.parent = this; - - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = this.stage; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // modify the list.. - var childFirst = child.first - var childLast = child.last; - var nextObject; - var previousObject; - - if(index == this.children.length) - { - previousObject = this.last; - var updateLast = this;//.parent; - var prevLast = this.last; - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = child.last; - } - updateLast = updateLast.parent; - } - } - else if(index == 0) - { - previousObject = this; - } - else - { - previousObject = this.children[index-1].last; - } - - nextObject = previousObject._iNext; - - // always true in this case - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - this.children.splice(index, 0, child); - // need to remove any render groups.. - if(this.__renderGroup) - { - // being used by a renderTexture.. if it exists then it must be from a render texture; - if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child); - // add them to the new render group.. - this.__renderGroup.addDisplayObjectAndChildren(child); - } - - } - else - { - throw new Error(child + " The index "+ index +" supplied is out of bounds " + this.children.length); - } -} - -/** - * [NYI] Swaps the depth of 2 displayObjects - * - * @method swapChildren - * @param child {DisplayObject} - * @param child2 {DisplayObject} - * @private - */ -PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2) -{ - /* - * this funtion needs to be recoded.. - * can be done a lot faster.. - */ - return; - - // need to fix this function :/ - /* - // TODO I already know this?? - var index = this.children.indexOf( child ); - var index2 = this.children.indexOf( child2 ); - - if ( index !== -1 && index2 !== -1 ) - { - // cool - - /* - if(this.stage) - { - // this is to satisfy the webGL batching.. - // TODO sure there is a nicer way to achieve this! - this.stage.__removeChild(child); - this.stage.__removeChild(child2); - - this.stage.__addChild(child); - this.stage.__addChild(child2); - } - - // swap the positions.. - this.children[index] = child2; - this.children[index2] = child; - - } - else - { - throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this); - }*/ -} - -/** - * Returns the Child at the specified index - * - * @method getChildAt - * @param index {Number} The index to get the child from - */ -PIXI.DisplayObjectContainer.prototype.getChildAt = function(index) -{ - if(index >= 0 && index < this.children.length) - { - return this.children[index]; - } - else - { - throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this); - } -} - -/** - * Removes a child from the container. - * - * @method removeChild - * @param child {DisplayObject} The DisplayObject to remove - */ -PIXI.DisplayObjectContainer.prototype.removeChild = function(child) -{ - var index = this.children.indexOf( child ); - if ( index !== -1 ) - { - // unlink // - // modify the list.. - var childFirst = child.first - var childLast = child.last; - - var nextObject = childLast._iNext; - var previousObject = childFirst._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - previousObject._iNext = nextObject; - - if(this.last == childLast) - { - var tempLast = childFirst._iPrev; - // need to make sure the parents last is updated too - var updateLast = this; - while(updateLast.last == childLast.last) - { - updateLast.last = tempLast; - updateLast = updateLast.parent; - if(!updateLast)break; - } - } - - childLast._iNext = null; - childFirst._iPrev = null; - - // update the stage reference.. - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = null; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // webGL trim - if(child.__renderGroup) - { - child.__renderGroup.removeDisplayObjectAndChildren(child); - } - - child.parent = undefined; - this.children.splice( index, 1 ); - } - else - { - throw new Error(child + " The supplied DisplayObject must be a child of the caller " + this); - } -} - -/* - * Updates the container's children's transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.DisplayObjectContainer.prototype.updateTransform = function() -{ - if(!this.visible)return; - - PIXI.DisplayObject.prototype.updateTransform.call( this ); - - for(var i=0,j=this.children.length; i} an array of {Texture} objects that make up the animation - */ -PIXI.MovieClip = function(textures) -{ - PIXI.Sprite.call(this, textures[0]); - - /** - * The array of textures that make up the animation - * - * @property textures - * @type Array - */ - this.textures = textures; - - /** - * The speed that the MovieClip will play at. Higher is faster, lower is slower - * - * @property animationSpeed - * @type Number - * @default 1 - */ - this.animationSpeed = 1; - - /** - * Whether or not the movie clip repeats after playing. - * - * @property loop - * @type Boolean - * @default true - */ - this.loop = true; - - /** - * Function to call when a MovieClip finishes playing - * - * @property onComplete - * @type Function - */ - this.onComplete = null; - - /** - * [read-only] The index MovieClips current frame (this may not have to be a whole number) - * - * @property currentFrame - * @type Number - * @default 0 - * @readOnly - */ - this.currentFrame = 0; - - /** - * [read-only] Indicates if the MovieClip is currently playing - * - * @property playing - * @type Boolean - * @readOnly - */ - this.playing = false; -} - -// constructor -PIXI.MovieClip.prototype = Object.create( PIXI.Sprite.prototype ); -PIXI.MovieClip.prototype.constructor = PIXI.MovieClip; - -/** - * Stops the MovieClip - * - * @method stop - */ -PIXI.MovieClip.prototype.stop = function() -{ - this.playing = false; -} - -/** - * Plays the MovieClip - * - * @method play - */ -PIXI.MovieClip.prototype.play = function() -{ - this.playing = true; -} - -/** - * Stops the MovieClip and goes to a specific frame - * - * @method gotoAndStop - * @param frameNumber {Number} frame index to stop at - */ -PIXI.MovieClip.prototype.gotoAndStop = function(frameNumber) -{ - this.playing = false; - this.currentFrame = frameNumber; - var round = (this.currentFrame + 0.5) | 0; - this.setTexture(this.textures[round % this.textures.length]); -} - -/** - * Goes to a specific frame and begins playing the MovieClip - * - * @method gotoAndPlay - * @param frameNumber {Number} frame index to start at - */ -PIXI.MovieClip.prototype.gotoAndPlay = function(frameNumber) -{ - this.currentFrame = frameNumber; - this.playing = true; -} - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.MovieClip.prototype.updateTransform = function() -{ - PIXI.Sprite.prototype.updateTransform.call(this); - - if(!this.playing)return; - - this.currentFrame += this.animationSpeed; - var round = (this.currentFrame + 0.5) | 0; - if(this.loop || round < this.textures.length) - { - this.setTexture(this.textures[round % this.textures.length]); - } - else if(round >= this.textures.length) - { - this.gotoAndStop(this.textures.length - 1); - if(this.onComplete) - { - this.onComplete(); - } - } -} -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - - -PIXI.FilterBlock = function(mask) -{ - this.graphics = mask - this.visible = true; - this.renderable = true; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Text Object will create a line(s) of text to split a line you can use "\n" - * - * @class Text - * @extends Sprite - * @constructor - * @param text {String} The copy that you would like the text to display - * @param [style] {Object} The style parameters - * @param [style.font] {String} default "bold 20pt Arial" The style and size of the font - * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00" - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - * @param [style.stroke] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00" - * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke) - * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used - * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap - */ -PIXI.Text = function(text, style) -{ - this.canvas = document.createElement("canvas"); - this.context = this.canvas.getContext("2d"); - PIXI.Sprite.call(this, PIXI.Texture.fromCanvas(this.canvas)); - - this.setText(text); - this.setStyle(style); - - this.updateText(); - this.dirty = false; -}; - -// constructor -PIXI.Text.prototype = Object.create(PIXI.Sprite.prototype); -PIXI.Text.prototype.constructor = PIXI.Text; - -/** - * Set the style of the text - * - * @method setStyle - * @param [style] {Object} The style parameters - * @param [style.font="bold 20pt Arial"] {String} The style and size of the font - * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00" - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - * @param [style.stroke="black"] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00" - * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke) - * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used - * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap - */ -PIXI.Text.prototype.setStyle = function(style) -{ - style = style || {}; - style.font = style.font || "bold 20pt Arial"; - style.fill = style.fill || "black"; - style.align = style.align || "left"; - style.stroke = style.stroke || "black"; //provide a default, see: https://github.com/GoodBoyDigital/pixi.js/issues/136 - style.strokeThickness = style.strokeThickness || 0; - style.wordWrap = style.wordWrap || false; - style.wordWrapWidth = style.wordWrapWidth || 100; - this.style = style; - this.dirty = true; -}; - -/** - * Set the copy for the text object. To split a line you can use "\n" - * - * @methos setText - * @param {String} text The copy that you would like the text to display - */ -PIXI.Sprite.prototype.setText = function(text) -{ - this.text = text.toString() || " "; - this.dirty = true; -}; - -/** - * Renders text - * - * @method updateText - * @private - */ -PIXI.Text.prototype.updateText = function() -{ - this.context.font = this.style.font; - - var outputText = this.text; - - // word wrap - // preserve original text - if(this.style.wordWrap)outputText = this.wordWrap(this.text); - - //split text into lines - var lines = outputText.split(/(?:\r\n|\r|\n)/); - - //calculate text width - var lineWidths = []; - var maxLineWidth = 0; - for (var i = 0; i < lines.length; i++) - { - var lineWidth = this.context.measureText(lines[i]).width; - lineWidths[i] = lineWidth; - maxLineWidth = Math.max(maxLineWidth, lineWidth); - } - this.canvas.width = maxLineWidth + this.style.strokeThickness; - - //calculate text height - var lineHeight = this.determineFontHeight("font: " + this.style.font + ";") + this.style.strokeThickness; - this.canvas.height = lineHeight * lines.length; - - //set canvas text styles - this.context.fillStyle = this.style.fill; - this.context.font = this.style.font; - - this.context.strokeStyle = this.style.stroke; - this.context.lineWidth = this.style.strokeThickness; - - this.context.textBaseline = "top"; - - //draw lines line by line - for (i = 0; i < lines.length; i++) - { - var linePosition = new PIXI.Point(this.style.strokeThickness / 2, this.style.strokeThickness / 2 + i * lineHeight); - - if(this.style.align == "right") - { - linePosition.x += maxLineWidth - lineWidths[i]; - } - else if(this.style.align == "center") - { - linePosition.x += (maxLineWidth - lineWidths[i]) / 2; - } - - if(this.style.stroke && this.style.strokeThickness) - { - this.context.strokeText(lines[i], linePosition.x, linePosition.y); - } - - if(this.style.fill) - { - this.context.fillText(lines[i], linePosition.x, linePosition.y); - } - } - - this.updateTexture(); -}; - -/** - * Updates texture size based on canvas size - * - * @method updateTexture - * @private - */ -PIXI.Text.prototype.updateTexture = function() -{ - this.texture.baseTexture.width = this.canvas.width; - this.texture.baseTexture.height = this.canvas.height; - this.texture.frame.width = this.canvas.width; - this.texture.frame.height = this.canvas.height; - - this._width = this.canvas.width; - this._height = this.canvas.height; - - PIXI.texturesToUpdate.push(this.texture.baseTexture); -}; - -/** - * Updates the transfor of this object - * - * @method updateTransform - * @private - */ -PIXI.Text.prototype.updateTransform = function() -{ - if(this.dirty) - { - this.updateText(); - this.dirty = false; - } - - PIXI.Sprite.prototype.updateTransform.call(this); -}; - -/* - * http://stackoverflow.com/users/34441/ellisbben - * great solution to the problem! - * - * @method determineFontHeight - * @param fontStyle {Object} - * @private - */ -PIXI.Text.prototype.determineFontHeight = function(fontStyle) -{ - // build a little reference dictionary so if the font style has been used return a - // cached version... - var result = PIXI.Text.heightCache[fontStyle]; - - if(!result) - { - var body = document.getElementsByTagName("body")[0]; - var dummy = document.createElement("div"); - var dummyText = document.createTextNode("M"); - dummy.appendChild(dummyText); - dummy.setAttribute("style", fontStyle + ';position:absolute;top:0;left:0'); - body.appendChild(dummy); - - result = dummy.offsetHeight; - PIXI.Text.heightCache[fontStyle] = result; - - body.removeChild(dummy); - } - - return result; -}; - -/** - * A Text Object will apply wordwrap - * - * @method wordWrap - * @param text {String} - * @private - */ -PIXI.Text.prototype.wordWrap = function(text) -{ - // search good wrap position - var searchWrapPos = function(ctx, text, start, end, wrapWidth) - { - var p = Math.floor((end-start) / 2) + start; - if(p == start) { - return 1; - } - - if(ctx.measureText(text.substring(0,p)).width <= wrapWidth) - { - if(ctx.measureText(text.substring(0,p+1)).width > wrapWidth) - { - return p; - } - else - { - return arguments.callee(ctx, text, p, end, wrapWidth); - } - } - else - { - return arguments.callee(ctx, text, start, p, wrapWidth); - } - }; - - var lineWrap = function(ctx, text, wrapWidth) - { - if(ctx.measureText(text).width <= wrapWidth || text.length < 1) - { - return text; - } - var pos = searchWrapPos(ctx, text, 0, text.length, wrapWidth); - return text.substring(0, pos) + "\n" + arguments.callee(ctx, text.substring(pos), wrapWidth); - }; - - var result = ""; - var lines = text.split("\n"); - for (var i = 0; i < lines.length; i++) - { - result += lineWrap(this.context, lines[i], this.style.wordWrapWidth) + "\n"; - } - - return result; -}; - -/** - * Destroys this text object - * - * @method destroy - * @param destroyTexture {Boolean} - */ -PIXI.Text.prototype.destroy = function(destroyTexture) -{ - if(destroyTexture) - { - this.texture.destroy(); - } - -}; - -PIXI.Text.heightCache = {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Text Object will create a line(s) of text using bitmap font. To split a line you can use "\n", "\r" or "\r\n" - * You can generate the fnt files using - * http://www.angelcode.com/products/bmfont/ for windows or - * http://www.bmglyph.com/ for mac. - * - * @class BitmapText - * @extends DisplayObjectContainer - * @constructor - * @param text {String} The copy that you would like the text to display - * @param style {Object} The style parameters - * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously) - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - */ -PIXI.BitmapText = function(text, style) -{ - PIXI.DisplayObjectContainer.call(this); - - this.setText(text); - this.setStyle(style); - this.updateText(); - this.dirty = false - -}; - -// constructor -PIXI.BitmapText.prototype = Object.create(PIXI.DisplayObjectContainer.prototype); -PIXI.BitmapText.prototype.constructor = PIXI.BitmapText; - -/** - * Set the copy for the text object - * - * @method setText - * @param text {String} The copy that you would like the text to display - */ -PIXI.BitmapText.prototype.setText = function(text) -{ - this.text = text || " "; - this.dirty = true; -}; - -/** - * Set the style of the text - * - * @method setStyle - * @param style {Object} The style parameters - * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously) - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - */ -PIXI.BitmapText.prototype.setStyle = function(style) -{ - style = style || {}; - style.align = style.align || "left"; - this.style = style; - - var font = style.font.split(" "); - this.fontName = font[font.length - 1]; - this.fontSize = font.length >= 2 ? parseInt(font[font.length - 2], 10) : PIXI.BitmapText.fonts[this.fontName].size; - - this.dirty = true; -}; - -/** - * Renders text - * - * @method updateText - * @private - */ -PIXI.BitmapText.prototype.updateText = function() -{ - var data = PIXI.BitmapText.fonts[this.fontName]; - var pos = new PIXI.Point(); - var prevCharCode = null; - var chars = []; - var maxLineWidth = 0; - var lineWidths = []; - var line = 0; - var scale = this.fontSize / data.size; - for(var i = 0; i < this.text.length; i++) - { - var charCode = this.text.charCodeAt(i); - if(/(?:\r\n|\r|\n)/.test(this.text.charAt(i))) - { - lineWidths.push(pos.x); - maxLineWidth = Math.max(maxLineWidth, pos.x); - line++; - - pos.x = 0; - pos.y += data.lineHeight; - prevCharCode = null; - continue; - } - - var charData = data.chars[charCode]; - if(!charData) continue; - - if(prevCharCode && charData[prevCharCode]) - { - pos.x += charData.kerning[prevCharCode]; - } - chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); - pos.x += charData.xAdvance; - - prevCharCode = charCode; - } - - lineWidths.push(pos.x); - maxLineWidth = Math.max(maxLineWidth, pos.x); - - var lineAlignOffsets = []; - for(i = 0; i <= line; i++) - { - var alignOffset = 0; - if(this.style.align == "right") - { - alignOffset = maxLineWidth - lineWidths[i]; - } - else if(this.style.align == "center") - { - alignOffset = (maxLineWidth - lineWidths[i]) / 2; - } - lineAlignOffsets.push(alignOffset); - } - - for(i = 0; i < chars.length; i++) - { - var c = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode); - c.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; - c.position.y = chars[i].position.y * scale; - c.scale.x = c.scale.y = scale; - this.addChild(c); - } - - this.width = pos.x * scale; - this.height = (pos.y + data.lineHeight) * scale; -}; - -/** - * Updates the transfor of this object - * - * @method updateTransform - * @private - */ -PIXI.BitmapText.prototype.updateTransform = function() -{ - if(this.dirty) - { - while(this.children.length > 0) - { - this.removeChild(this.getChildAt(0)); - } - this.updateText(); - - this.dirty = false; - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call(this); -}; - -PIXI.BitmapText.fonts = {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - - -/** - * The interaction manager deals with mouse and touch events. Any DisplayObject can be interactive - * This manager also supports multitouch. - * - * @class InteractionManager - * @constructor - * @param stage {Stage} The stage to handle interactions - */ -PIXI.InteractionManager = function(stage) -{ - /** - * a refference to the stage - * - * @property stage - * @type Stage - */ - this.stage = stage; - - /** - * the mouse data - * - * @property mouse - * @type InteractionData - */ - this.mouse = new PIXI.InteractionData(); - - /** - * an object that stores current touches (InteractionData) by id reference - * - * @property touchs - * @type Object - */ - this.touchs = {}; - - // helpers - this.tempPoint = new PIXI.Point(); - //this.tempMatrix = mat3.create(); - - this.mouseoverEnabled = true; - - //tiny little interactiveData pool! - this.pool = []; - - this.interactiveItems = []; - - this.last = 0; -} - -// constructor -PIXI.InteractionManager.prototype.constructor = PIXI.InteractionManager; - -/** - * Collects an interactive sprite recursively to have their interactions managed - * - * @method collectInteractiveSprite - * @param displayObject {DisplayObject} the displayObject to collect - * @param iParent {DisplayObject} - * @private - */ -PIXI.InteractionManager.prototype.collectInteractiveSprite = function(displayObject, iParent) -{ - var children = displayObject.children; - var length = children.length; - - /// make an interaction tree... {item.__interactiveParent} - for (var i = length-1; i >= 0; i--) - { - var child = children[i]; - - if(child.visible) { - // push all interactive bits - if(child.interactive) - { - iParent.interactiveChildren = true; - //child.__iParent = iParent; - this.interactiveItems.push(child); - - if(child.children.length > 0) - { - this.collectInteractiveSprite(child, child); - } - } - else - { - child.__iParent = null; - - if(child.children.length > 0) - { - this.collectInteractiveSprite(child, iParent); - } - } - } - } -} - -/** - * Sets the target for event delegation - * - * @method setTarget - * @param target {WebGLRenderer|CanvasRenderer} the renderer to bind events to - * @private - */ -PIXI.InteractionManager.prototype.setTarget = function(target) -{ - if (window.navigator.msPointerEnabled) - { - // time to remove some of that zoom in ja.. - target.view.style["-ms-content-zooming"] = "none"; - target.view.style["-ms-touch-action"] = "none" - - // DO some window specific touch! - } - - this.target = target; - target.view.addEventListener('mousemove', this.onMouseMove.bind(this), true); - target.view.addEventListener('mousedown', this.onMouseDown.bind(this), true); - document.body.addEventListener('mouseup', this.onMouseUp.bind(this), true); - target.view.addEventListener('mouseout', this.onMouseUp.bind(this), true); - - // aint no multi touch just yet! - target.view.addEventListener("touchstart", this.onTouchStart.bind(this), true); - target.view.addEventListener("touchend", this.onTouchEnd.bind(this), true); - target.view.addEventListener("touchmove", this.onTouchMove.bind(this), true); -} - -/** - * updates the state of interactive objects - * - * @method update - * @private - */ -PIXI.InteractionManager.prototype.update = function() -{ - if(!this.target)return; - - // frequency of 30fps?? - var now = Date.now(); - var diff = now - this.last; - diff = (diff * 30) / 1000; - if(diff < 1)return; - this.last = now; - // - - // ok.. so mouse events?? - // yes for now :) - // OPTIMSE - how often to check?? - if(this.dirty) - { - this.dirty = false; - - var len = this.interactiveItems.length; - - for (var i=0; i < len; i++) { - this.interactiveItems[i].interactiveChildren = false; - } - - this.interactiveItems = []; - - if(this.stage.interactive)this.interactiveItems.push(this.stage); - // go through and collect all the objects that are interactive.. - this.collectInteractiveSprite(this.stage, this.stage); - } - - // loop through interactive objects! - var length = this.interactiveItems.length; - - this.target.view.style.cursor = "default"; - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - if(!item.visible)continue; - - // OPTIMISATION - only calculate every time if the mousemove function exists.. - // OK so.. does the object have any other interactive functions? - // hit-test the clip! - - - if(item.mouseover || item.mouseout || item.buttonMode) - { - // ok so there are some functions so lets hit test it.. - item.__hit = this.hitTest(item, this.mouse); - this.mouse.target = item; - // ok so deal with interactions.. - // loks like there was a hit! - if(item.__hit) - { - if(item.buttonMode)this.target.view.style.cursor = "pointer"; - - if(!item.__isOver) - { - - if(item.mouseover)item.mouseover(this.mouse); - item.__isOver = true; - } - } - else - { - if(item.__isOver) - { - // roll out! - if(item.mouseout)item.mouseout(this.mouse); - item.__isOver = false; - } - } - } - - // ---> - } -} - -/** - * Is called when the mouse moves accross the renderer element - * - * @method onMouseMove - * @param event {Event} The DOM event of the mouse moving - * @private - */ -PIXI.InteractionManager.prototype.onMouseMove = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - // TODO optimize by not check EVERY TIME! maybe half as often? // - var rect = this.target.view.getBoundingClientRect(); - - this.mouse.global.x = (event.clientX - rect.left) * (this.target.width / rect.width); - this.mouse.global.y = (event.clientY - rect.top) * ( this.target.height / rect.height); - - var length = this.interactiveItems.length; - var global = this.mouse.global; - - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mousemove) - { - //call the function! - item.mousemove(this.mouse); - } - } -} - -/** - * Is called when the mouse button is pressed down on the renderer element - * - * @method onMouseDown - * @param event {Event} The DOM event of a mouse button being pressed down - * @private - */ -PIXI.InteractionManager.prototype.onMouseDown = function(event) -{ - event.preventDefault(); - this.mouse.originalEvent = event || window.event; //IE uses window.event - - // loop through inteaction tree... - // hit test each item! -> - // get interactive items under point?? - //stage.__i - var length = this.interactiveItems.length; - var global = this.mouse.global; - - var index = 0; - var parent = this.stage; - - // while - // hit test - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mousedown || item.click) - { - item.__mouseIsDown = true; - item.__hit = this.hitTest(item, this.mouse); - - if(item.__hit) - { - //call the function! - if(item.mousedown)item.mousedown(this.mouse); - item.__isDown = true; - - // just the one! - if(!item.interactiveChildren)break; - } - } - } -} - -/** - * Is called when the mouse button is released on the renderer element - * - * @method onMouseUp - * @param event {Event} The DOM event of a mouse button being released - * @private - */ -PIXI.InteractionManager.prototype.onMouseUp = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - - var global = this.mouse.global; - - - var length = this.interactiveItems.length; - var up = false; - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mouseup || item.mouseupoutside || item.click) - { - item.__hit = this.hitTest(item, this.mouse); - - if(item.__hit && !up) - { - //call the function! - if(item.mouseup) - { - item.mouseup(this.mouse); - } - if(item.__isDown) - { - if(item.click)item.click(this.mouse); - } - - if(!item.interactiveChildren)up = true; - } - else - { - if(item.__isDown) - { - if(item.mouseupoutside)item.mouseupoutside(this.mouse); - } - } - - item.__isDown = false; - } - } -} - -/** - * Tests if the current mouse coords hit a sprite - * - * @method hitTest - * @param item {DisplayObject} The displayObject to test for a hit - * @param interactionData {InteractionData} The interactiondata object to update in the case of a hit - * @private - */ -PIXI.InteractionManager.prototype.hitTest = function(item, interactionData) -{ - var global = interactionData.global; - - if(!item.visible)return false; - - var isSprite = (item instanceof PIXI.Sprite), - worldTransform = item.worldTransform, - a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2], - a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5], - id = 1 / (a00 * a11 + a01 * -a10), - x = a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id, - y = a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id; - - interactionData.target = item; - - //a sprite or display object with a hit area defined - if(item.hitArea && item.hitArea.contains) { - if(item.hitArea.contains(x, y)) { - //if(isSprite) - interactionData.target = item; - - return true; - } - - return false; - } - // a sprite with no hitarea defined - else if(isSprite) - { - var width = item.texture.frame.width, - height = item.texture.frame.height, - x1 = -width * item.anchor.x, - y1; - - if(x > x1 && x < x1 + width) - { - y1 = -height * item.anchor.y; - - if(y > y1 && y < y1 + height) - { - // set the target property if a hit is true! - interactionData.target = item - return true; - } - } - } - - var length = item.children.length; - - for (var i = 0; i < length; i++) - { - var tempItem = item.children[i]; - var hit = this.hitTest(tempItem, interactionData); - if(hit) - { - // hmm.. TODO SET CORRECT TARGET? - interactionData.target = item - return true; - } - } - - return false; -} - -/** - * Is called when a touch is moved accross the renderer element - * - * @method onTouchMove - * @param event {Event} The DOM event of a touch moving accross the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchMove = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - var rect = this.target.view.getBoundingClientRect(); - var changedTouches = event.changedTouches; - - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - var touchData = this.touchs[touchEvent.identifier]; - - // update the touch position - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - } - - var length = this.interactiveItems.length; - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - if(item.touchmove)item.touchmove(touchData); - } -} - -/** - * Is called when a touch is started on the renderer element - * - * @method onTouchStart - * @param event {Event} The DOM event of a touch starting on the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchStart = function(event) -{ - event.preventDefault(); - this.mouse.originalEvent = event || window.event; //IE uses window.event - - var rect = this.target.view.getBoundingClientRect(); - - var changedTouches = event.changedTouches; - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - - var touchData = this.pool.pop(); - if(!touchData)touchData = new PIXI.InteractionData(); - - this.touchs[touchEvent.identifier] = touchData; - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - - var length = this.interactiveItems.length; - - for (var j = 0; j < length; j++) - { - var item = this.interactiveItems[j]; - - if(item.touchstart || item.tap) - { - item.__hit = this.hitTest(item, touchData); - - if(item.__hit) - { - //call the function! - if(item.touchstart)item.touchstart(touchData); - item.__isDown = true; - item.__touchData = touchData; - - if(!item.interactiveChildren)break; - } - } - } - } -} - -/** - * Is called when a touch is ended on the renderer element - * - * @method onTouchEnd - * @param event {Event} The DOM event of a touch ending on the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchEnd = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - var rect = this.target.view.getBoundingClientRect(); - var changedTouches = event.changedTouches; - - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - var touchData = this.touchs[touchEvent.identifier]; - var up = false; - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - - var length = this.interactiveItems.length; - for (var j = 0; j < length; j++) - { - var item = this.interactiveItems[j]; - var itemTouchData = item.__touchData; // <-- Here! - item.__hit = this.hitTest(item, touchData); - - if(itemTouchData == touchData) - { - // so this one WAS down... - - // hitTest?? - - if(item.touchend || item.tap) - { - if(item.__hit && !up) - { - if(item.touchend)item.touchend(touchData); - if(item.__isDown) - { - if(item.tap)item.tap(touchData); - } - - if(!item.interactiveChildren)up = true; - } - else - { - if(item.__isDown) - { - if(item.touchendoutside)item.touchendoutside(touchData); - } - } - - item.__isDown = false; - } - - item.__touchData = null; - - } - else - { - - } - } - // remove the touch.. - this.pool.push(touchData); - this.touchs[touchEvent.identifier] = null; - } -} - -/** - * Holds all information related to an Interaction event - * - * @class InteractionData - * @constructor - */ -PIXI.InteractionData = function() -{ - /** - * This point stores the global coords of where the touch/mouse event happened - * - * @property global - * @type Point - */ - this.global = new PIXI.Point(); - - // this is here for legacy... but will remove - this.local = new PIXI.Point(); - - /** - * The target Sprite that was interacted with - * - * @property target - * @type Sprite - */ - this.target; - - /** - * When passed to an event handler, this will be the original DOM Event that was captured - * - * @property originalEvent - * @type Event - */ - this.originalEvent; -} - -/** - * This will return the local coords of the specified displayObject for this InteractionData - * - * @method getLocalPosition - * @param displayObject {DisplayObject} The DisplayObject that you would like the local coords off - * @return {Point} A point containing the coords of the InteractionData position relative to the DisplayObject - */ -PIXI.InteractionData.prototype.getLocalPosition = function(displayObject) -{ - var worldTransform = displayObject.worldTransform; - var global = this.global; - - // do a cheeky transform to get the mouse coords; - var a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2], - a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5], - id = 1 / (a00 * a11 + a01 * -a10); - // set the mouse coords... - return new PIXI.Point(a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id, - a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id) -} - -// constructor -PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Stage represents the root of the display tree. Everything connected to the stage is rendered - * - * @class Stage - * @extends DisplayObjectContainer - * @constructor - * @param backgroundColor {Number} the background color of the stage, easiest way to pass this in is in hex format - * like: 0xFFFFFF for white - * @param interactive {Boolean} enable / disable interaction (default is false) - */ -PIXI.Stage = function(backgroundColor, interactive) -{ - PIXI.DisplayObjectContainer.call( this ); - - /** - * [read-only] Current transform of the object based on world (parent) factors - * - * @property worldTransform - * @type Mat3 - * @readOnly - * @private - */ - this.worldTransform = PIXI.mat3.create(); - - /** - * Whether or not the stage is interactive - * - * @property interactive - * @type Boolean - */ - this.interactive = interactive; - - /** - * The interaction manage for this stage, manages all interactive activity on the stage - * - * @property interactive - * @type InteractionManager - */ - this.interactionManager = new PIXI.InteractionManager(this); - - /** - * Whether the stage is dirty and needs to have interactions updated - * - * @property dirty - * @type Boolean - * @private - */ - this.dirty = true; - - this.__childrenAdded = []; - this.__childrenRemoved = []; - - //the stage is it's own stage - this.stage = this; - - //optimize hit detection a bit - this.stage.hitArea = new PIXI.Rectangle(0,0,100000, 100000); - - this.setBackgroundColor(backgroundColor); - this.worldVisible = true; -} - -// constructor -PIXI.Stage.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Stage.prototype.constructor = PIXI.Stage; - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.Stage.prototype.updateTransform = function() -{ - this.worldAlpha = 1; - - for(var i=0,j=this.children.length; i> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; -} - -/** - * A polyfill for Function.prototype.bind - * - * @method bind - */ -if (typeof Function.prototype.bind != 'function') { - Function.prototype.bind = (function () { - var slice = Array.prototype.slice; - return function (thisArg) { - var target = this, boundArgs = slice.call(arguments, 1); - - if (typeof target != 'function') throw new TypeError(); - - function bound() { - var args = boundArgs.concat(slice.call(arguments)); - target.apply(this instanceof bound ? this : thisArg, args); - } - - bound.prototype = (function F(proto) { - proto && (F.prototype = proto); - if (!(this instanceof F)) return new F; - })(target.prototype); - - return bound; - }; - })(); -} - -/** - * A wrapper for ajax requests to be handled cross browser - * - * @class AjaxRequest - * @constructor - */ -var AjaxRequest = PIXI.AjaxRequest = function() -{ - var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE - - if (window.ActiveXObject) - { //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken) - for (var i=0; i>>>>>>>>") - console.log("_") - var safe = 0; - var tmp = item.first; - console.log(tmp); - - while(tmp._iNext) - { - safe++; -// console.log(tmp.childIndex + tmp); - tmp = tmp._iNext; - console.log(tmp);//.childIndex); - // console.log(tmp); - - if(safe > 100) - { - console.log("BREAK") - break - } - } -} - - - - - - -/** - * https://github.com/mrdoob/eventtarget.js/ - * THankS mr DOob! - */ - -/** - * Adds event emitter functionality to a class - * - * @class EventTarget - * @example - * function MyEmitter() { - * PIXI.EventTarget.call(this); //mixes in event target stuff - * } - * - * var em = new MyEmitter(); - * em.emit({ type: 'eventName', data: 'some data' }); - */ -PIXI.EventTarget = function () { - - var listeners = {}; - - this.addEventListener = this.on = function ( type, listener ) { - - - if ( listeners[ type ] === undefined ) { - - listeners[ type ] = []; - - } - - if ( listeners[ type ].indexOf( listener ) === - 1 ) { - - listeners[ type ].push( listener ); - } - - }; - - this.dispatchEvent = this.emit = function ( event ) { - - for ( var listener in listeners[ event.type ] ) { - - listeners[ event.type ][ listener ]( event ); - - } - - }; - - this.removeEventListener = this.off = function ( type, listener ) { - - var index = listeners[ type ].indexOf( listener ); - - if ( index !== - 1 ) { - - listeners[ type ].splice( index, 1 ); - - } - - }; - -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * This helper function will automatically detect which renderer you should be using. - * WebGL is the preferred renderer as it is a lot fastest. If webGL is not supported by - * the browser then this function will return a canvas renderer - * - * @method autoDetectRenderer - * @static - * @param width {Number} the width of the renderers view - * @param height {Number} the height of the renderers view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - */ -PIXI.autoDetectRenderer = function(width, height, view, transparent) -{ - if(!width)width = 800; - if(!height)height = 600; - - // BORROWED from Mr Doob (mrdoob.com) - var webgl = ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )(); - - //console.log(webgl); - if( webgl ) - { - return new PIXI.WebGLRenderer(width, height, view, transparent); - } - - return new PIXI.CanvasRenderer(width, height, view, transparent); -}; - - - -/* - PolyK library - url: http://polyk.ivank.net - Released under MIT licence. - - Copyright (c) 2012 Ivan Kuckir - - 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. - - This is an amazing lib! - - slightly modified by mat groves (matgroves.com); -*/ - -PIXI.PolyK = {}; - -/** - * Triangulates shapes for webGL graphic fills - * - * @method Triangulate - * @namespace PolyK - * @constructor - */ -PIXI.PolyK.Triangulate = function(p) -{ - var sign = true; - - var n = p.length>>1; - if(n<3) return []; - var tgs = []; - var avl = []; - for(var i=0; i 3) - { - var i0 = avl[(i+0)%al]; - var i1 = avl[(i+1)%al]; - var i2 = avl[(i+2)%al]; - - var ax = p[2*i0], ay = p[2*i0+1]; - var bx = p[2*i1], by = p[2*i1+1]; - var cx = p[2*i2], cy = p[2*i2+1]; - - var earFound = false; - if(PIXI.PolyK._convex(ax, ay, bx, by, cx, cy, sign)) - { - earFound = true; - for(var j=0; j 3*al) - { - // need to flip flip reverse it! - // reset! - if(sign) - { - var tgs = []; - avl = []; - for(var i=0; i= 0) && (v >= 0) && (u + v < 1); -} - -/** - * Checks if a shape is convex - * - * @class _convex - * @namespace PolyK - * @private - */ -PIXI.PolyK._convex = function(ax, ay, bx, by, cx, cy, sign) -{ - return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) == sign; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/* - * the default suoer fast shader! - */ - -PIXI.shaderFragmentSrc = [ - "precision mediump float;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "uniform sampler2D uSampler;", - "void main(void) {", - "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));", - "gl_FragColor = gl_FragColor * vColor;", - "}" -]; - -PIXI.shaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec2 aTextureCoord;", - "attribute float aColor;", - //"uniform mat4 uMVMatrix;", - - "uniform vec2 projectionVector;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "void main(void) {", - // "gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0, 1.0);", - "gl_Position = vec4( aVertexPosition.x / projectionVector.x -1.0, aVertexPosition.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vTextureCoord = aTextureCoord;", - "vColor = aColor;", - "}" -]; - -/* - * the triangle strip shader.. - */ - -PIXI.stripShaderFragmentSrc = [ - "precision mediump float;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "uniform float alpha;", - "uniform sampler2D uSampler;", - "void main(void) {", - "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));", - "gl_FragColor = gl_FragColor * alpha;", - "}" -]; - - -PIXI.stripShaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec2 aTextureCoord;", - "attribute float aColor;", - "uniform mat3 translationMatrix;", - "uniform vec2 projectionVector;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "void main(void) {", - "vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);", - "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vTextureCoord = aTextureCoord;", - "vColor = aColor;", - "}" -]; - - -/* - * primitive shader.. - */ - -PIXI.primitiveShaderFragmentSrc = [ - "precision mediump float;", - "varying vec4 vColor;", - "void main(void) {", - "gl_FragColor = vColor;", - "}" -]; - -PIXI.primitiveShaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec4 aColor;", - "uniform mat3 translationMatrix;", - "uniform vec2 projectionVector;", - "uniform float alpha;", - "varying vec4 vColor;", - "void main(void) {", - "vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);", - "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vColor = aColor * alpha;", - "}" -]; - -PIXI.initPrimitiveShader = function() -{ - var gl = PIXI.gl; - - var shaderProgram = PIXI.compileProgram(PIXI.primitiveShaderVertexSrc, PIXI.primitiveShaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, "translationMatrix"); - - shaderProgram.alpha = gl.getUniformLocation(shaderProgram, "alpha"); - - PIXI.primitiveProgram = shaderProgram; -} - -PIXI.initDefaultShader = function() -{ - var gl = this.gl; - var shaderProgram = PIXI.compileProgram(PIXI.shaderVertexSrc, PIXI.shaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord"); - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - // shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix"); - shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler"); - - PIXI.shaderProgram = shaderProgram; -} - -PIXI.initDefaultStripShader = function() -{ - var gl = this.gl; - var shaderProgram = PIXI.compileProgram(PIXI.stripShaderVertexSrc, PIXI.stripShaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord"); - shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, "translationMatrix"); - shaderProgram.alpha = gl.getUniformLocation(shaderProgram, "alpha"); - - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - - shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler"); - - PIXI.stripShaderProgram = shaderProgram; -} - -PIXI.CompileVertexShader = function(gl, shaderSrc) -{ - return PIXI._CompileShader(gl, shaderSrc, gl.VERTEX_SHADER); -} - -PIXI.CompileFragmentShader = function(gl, shaderSrc) -{ - return PIXI._CompileShader(gl, shaderSrc, gl.FRAGMENT_SHADER); -} - -PIXI._CompileShader = function(gl, shaderSrc, shaderType) -{ - var src = shaderSrc.join("\n"); - var shader = gl.createShader(shaderType); - gl.shaderSource(shader, src); - gl.compileShader(shader); - - if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { - alert(gl.getShaderInfoLog(shader)); - return null; - } - - return shader; -} - - -PIXI.compileProgram = function(vertexSrc, fragmentSrc) -{ - var gl = PIXI.gl; - var fragmentShader = PIXI.CompileFragmentShader(gl, fragmentSrc); - var vertexShader = PIXI.CompileVertexShader(gl, vertexSrc); - - var shaderProgram = gl.createProgram(); - - gl.attachShader(shaderProgram, vertexShader); - gl.attachShader(shaderProgram, fragmentShader); - gl.linkProgram(shaderProgram); - - if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) { - alert("Could not initialise shaders"); - } - - return shaderProgram; -} - - -PIXI.activateDefaultShader = function() -{ - var gl = PIXI.gl; - var shaderProgram = PIXI.shaderProgram; - - gl.useProgram(shaderProgram); - - - gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute); - gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute); - gl.enableVertexAttribArray(shaderProgram.colorAttribute); -} - - - -PIXI.activatePrimitiveShader = function() -{ - var gl = PIXI.gl; - - gl.disableVertexAttribArray(PIXI.shaderProgram.textureCoordAttribute); - gl.disableVertexAttribArray(PIXI.shaderProgram.colorAttribute); - - gl.useProgram(PIXI.primitiveProgram); - - gl.enableVertexAttribArray(PIXI.primitiveProgram.vertexPositionAttribute); - gl.enableVertexAttribArray(PIXI.primitiveProgram.colorAttribute); -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A set of functions used by the webGL renderer to draw the primitive graphics data - * - * @class CanvasGraphics - */ -PIXI.WebGLGraphics = function() -{ - -} - -/** - * Renders the graphics object - * - * @static - * @private - * @method renderGraphics - * @param graphics {Graphics} - * @param projection {Object} - */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) -{ - var gl = PIXI.gl; - - if(!graphics._webGL)graphics._webGL = {points:[], indices:[], lastIndex:0, - buffer:gl.createBuffer(), - indexBuffer:gl.createBuffer()}; - - if(graphics.dirty) - { - graphics.dirty = false; - - if(graphics.clearDirty) - { - graphics.clearDirty = false; - - graphics._webGL.lastIndex = 0; - graphics._webGL.points = []; - graphics._webGL.indices = []; - - } - - PIXI.WebGLGraphics.updateGraphics(graphics); - } - - - PIXI.activatePrimitiveShader(); - - // This could be speeded up fo sure! - var m = PIXI.mat3.clone(graphics.worldTransform); - - PIXI.mat3.transpose(m); - - // set the matrix transform for the - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - - gl.uniformMatrix3fv(PIXI.primitiveProgram.translationMatrix, false, m); - - gl.uniform2f(PIXI.primitiveProgram.projectionVector, projection.x, projection.y); - - gl.uniform1f(PIXI.primitiveProgram.alpha, graphics.worldAlpha); - - gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer); - - // WHY DOES THIS LINE NEED TO BE THERE??? - gl.vertexAttribPointer(PIXI.shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - // its not even used.. but need to be set or it breaks? - // only on pc though.. - - gl.vertexAttribPointer(PIXI.primitiveProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 4 * 6, 0); - gl.vertexAttribPointer(PIXI.primitiveProgram.colorAttribute, 4, gl.FLOAT, false,4 * 6, 2 * 4); - - // set the index buffer! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer); - - gl.drawElements(gl.TRIANGLE_STRIP, graphics._webGL.indices.length, gl.UNSIGNED_SHORT, 0 ); - - // return to default shader... - PIXI.activateDefaultShader(); -} - -/** - * Updates the graphics object - * - * @static - * @private - * @method updateGraphics - * @param graphics {Graphics} - */ -PIXI.WebGLGraphics.updateGraphics = function(graphics) -{ - for (var i=graphics._webGL.lastIndex; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - - if(data.type == PIXI.Graphics.POLY) - { - if(data.fill) - { - if(data.points.length>3) - PIXI.WebGLGraphics.buildPoly(data, graphics._webGL); - } - - if(data.lineWidth > 0) - { - PIXI.WebGLGraphics.buildLine(data, graphics._webGL); - } - } - else if(data.type == PIXI.Graphics.RECT) - { - PIXI.WebGLGraphics.buildRectangle(data, graphics._webGL); - } - else if(data.type == PIXI.Graphics.CIRC || data.type == PIXI.Graphics.ELIP) - { - PIXI.WebGLGraphics.buildCircle(data, graphics._webGL); - } - }; - - graphics._webGL.lastIndex = graphics.graphicsData.length; - - var gl = PIXI.gl; - - graphics._webGL.glPoints = new Float32Array(graphics._webGL.points); - - gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer); - gl.bufferData(gl.ARRAY_BUFFER, graphics._webGL.glPoints, gl.STATIC_DRAW); - - graphics._webGL.glIndicies = new Uint16Array(graphics._webGL.indices); - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.glIndicies, gl.STATIC_DRAW); -} - -/** - * Builds a rectangle to draw - * - * @static - * @private - * @method buildRectangle - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData) -{ - // --- // - // need to convert points to a nice regular data - // - var rectData = graphicsData.points; - var x = rectData[0]; - var y = rectData[1]; - var width = rectData[2]; - var height = rectData[3]; - - - if(graphicsData.fill) - { - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vertPos = verts.length/6; - - // start - verts.push(x, y); - verts.push(r, g, b, alpha); - - verts.push(x + width, y); - verts.push(r, g, b, alpha); - - verts.push(x , y + height); - verts.push(r, g, b, alpha); - - verts.push(x + width, y + height); - verts.push(r, g, b, alpha); - - // insert 2 dead triangles.. - indices.push(vertPos, vertPos, vertPos+1, vertPos+2, vertPos+3, vertPos+3) - } - - if(graphicsData.lineWidth) - { - graphicsData.points = [x, y, - x + width, y, - x + width, y + height, - x, y + height, - x, y]; - - PIXI.WebGLGraphics.buildLine(graphicsData, webGLData); - } - -} - -/** - * Builds a circle to draw - * - * @static - * @private - * @method buildCircle - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildCircle = function(graphicsData, webGLData) -{ - // --- // - // need to convert points to a nice regular data - // - var rectData = graphicsData.points; - var x = rectData[0]; - var y = rectData[1]; - var width = rectData[2]; - var height = rectData[3]; - - var totalSegs = 40; - var seg = (Math.PI * 2) / totalSegs ; - - if(graphicsData.fill) - { - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vecPos = verts.length/6; - - indices.push(vecPos); - - for (var i=0; i < totalSegs + 1 ; i++) - { - verts.push(x,y, r, g, b, alpha); - - verts.push(x + Math.sin(seg * i) * width, - y + Math.cos(seg * i) * height, - r, g, b, alpha); - - indices.push(vecPos++, vecPos++); - }; - - indices.push(vecPos-1); - } - - if(graphicsData.lineWidth) - { - graphicsData.points = []; - - for (var i=0; i < totalSegs + 1; i++) - { - graphicsData.points.push(x + Math.sin(seg * i) * width, - y + Math.cos(seg * i) * height) - }; - - PIXI.WebGLGraphics.buildLine(graphicsData, webGLData); - } - -} - -/** - * Builds a line to draw - * - * @static - * @private - * @method buildLine - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData) -{ - // TODO OPTIMISE! - - var wrap = true; - var points = graphicsData.points; - if(points.length == 0)return; - - // get first and last point.. figure out the middle! - var firstPoint = new PIXI.Point( points[0], points[1] ); - var lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] ); - - // if the first point is the last point - goona have issues :) - if(firstPoint.x == lastPoint.x && firstPoint.y == lastPoint.y) - { - points.pop(); - points.pop(); - - lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] ); - - var midPointX = lastPoint.x + (firstPoint.x - lastPoint.x) *0.5; - var midPointY = lastPoint.y + (firstPoint.y - lastPoint.y) *0.5; - - points.unshift(midPointX, midPointY); - points.push(midPointX, midPointY) - } - - var verts = webGLData.points; - var indices = webGLData.indices; - var length = points.length / 2; - var indexCount = points.length; - var indexStart = verts.length/6; - - // DRAW the Line - var width = graphicsData.lineWidth / 2; - - // sort color - var color = HEXtoRGB(graphicsData.lineColor); - var alpha = graphicsData.lineAlpha; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var p1x, p1y, p2x, p2y, p3x, p3y; - var perpx, perpy, perp2x, perp2y, perp3x, perp3y; - var ipx, ipy; - var a1, b1, c1, a2, b2, c2; - var denom, pdist, dist; - - p1x = points[0]; - p1y = points[1]; - - p2x = points[2]; - p2y = points[3]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - // start - verts.push(p1x - perpx , p1y - perpy, - r, g, b, alpha); - - verts.push(p1x + perpx , p1y + perpy, - r, g, b, alpha); - - for (var i = 1; i < length-1; i++) - { - p1x = points[(i-1)*2]; - p1y = points[(i-1)*2 + 1]; - - p2x = points[(i)*2] - p2y = points[(i)*2 + 1] - - p3x = points[(i+1)*2]; - p3y = points[(i+1)*2 + 1]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - perp2x = -(p2y - p3y); - perp2y = p2x - p3x; - - dist = Math.sqrt(perp2x*perp2x + perp2y*perp2y); - perp2x /= dist; - perp2y /= dist; - perp2x *= width; - perp2y *= width; - - a1 = (-perpy + p1y) - (-perpy + p2y); - b1 = (-perpx + p2x) - (-perpx + p1x); - c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y); - a2 = (-perp2y + p3y) - (-perp2y + p2y); - b2 = (-perp2x + p2x) - (-perp2x + p3x); - c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y); - - denom = a1*b2 - a2*b1; - - if (denom == 0) { - denom+=1; - } - - px = (b1*c2 - b2*c1)/denom; - py = (a2*c1 - a1*c2)/denom; - - pdist = (px -p2x) * (px -p2x) + (py -p2y) + (py -p2y); - - if(pdist > 140 * 140) - { - perp3x = perpx - perp2x; - perp3y = perpy - perp2y; - - dist = Math.sqrt(perp3x*perp3x + perp3y*perp3y); - perp3x /= dist; - perp3y /= dist; - perp3x *= width; - perp3y *= width; - - verts.push(p2x - perp3x, p2y -perp3y); - verts.push(r, g, b, alpha); - - verts.push(p2x + perp3x, p2y +perp3y); - verts.push(r, g, b, alpha); - - verts.push(p2x - perp3x, p2y -perp3y); - verts.push(r, g, b, alpha); - - indexCount++; - } - else - { - verts.push(px , py); - verts.push(r, g, b, alpha); - - verts.push(p2x - (px-p2x), p2y - (py - p2y));//, 4); - verts.push(r, g, b, alpha); - } - } - - p1x = points[(length-2)*2] - p1y = points[(length-2)*2 + 1] - - p2x = points[(length-1)*2] - p2y = points[(length-1)*2 + 1] - - perpx = -(p1y - p2y) - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - verts.push(p2x - perpx , p2y - perpy) - verts.push(r, g, b, alpha); - - verts.push(p2x + perpx , p2y + perpy) - verts.push(r, g, b, alpha); - - indices.push(indexStart); - - for (var i=0; i < indexCount; i++) - { - indices.push(indexStart++); - }; - - indices.push(indexStart-1); -} - -/** - * Builds a polygon to draw - * - * @static - * @private - * @method buildPoly - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildPoly = function(graphicsData, webGLData) -{ - var points = graphicsData.points; - if(points.length < 6)return; - - // get first and last point.. figure out the middle! - var verts = webGLData.points; - var indices = webGLData.indices; - - var length = points.length / 2; - - // sort color - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var triangles = PIXI.PolyK.Triangulate(points); - - var vertPos = verts.length / 6; - - for (var i=0; i < triangles.length; i+=3) - { - indices.push(triangles[i] + vertPos); - indices.push(triangles[i] + vertPos); - indices.push(triangles[i+1] + vertPos); - indices.push(triangles[i+2] +vertPos); - indices.push(triangles[i+2] + vertPos); - }; - - for (var i = 0; i < length; i++) - { - verts.push(points[i * 2], points[i * 2 + 1], - r, g, b, alpha); - }; -} - -function HEXtoRGB(hex) { - return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; -} - - - - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI._defaultFrame = new PIXI.Rectangle(0,0,1,1); - -// an instance of the gl context.. -// only one at the moment :/ -PIXI.gl; - -/** - * the WebGLRenderer is draws the stage and all its content onto a webGL enabled canvas. This renderer - * should be used for browsers support webGL. This Render works by automatically managing webGLBatchs. - * So no need for Sprite Batch's or Sprite Cloud's - * Dont forget to add the view to your DOM or you will not see anything :) - * - * @class WebGLRenderer - * @constructor - * @param width=0 {Number} the width of the canvas view - * @param height=0 {Number} the height of the canvas view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - * - */ -PIXI.WebGLRenderer = function(width, height, view, transparent) -{ - // do a catch.. only 1 webGL renderer.. - - this.transparent = !!transparent; - - this.width = width || 800; - this.height = height || 600; - - this.view = view || document.createElement( 'canvas' ); - this.view.width = this.width; - this.view.height = this.height; - - // deal with losing context.. - var scope = this; - this.view.addEventListener('webglcontextlost', function(event) { scope.handleContextLost(event); }, false) - this.view.addEventListener('webglcontextrestored', function(event) { scope.handleContextRestored(event); }, false) - - this.batchs = []; - - try - { - PIXI.gl = this.gl = this.view.getContext("experimental-webgl", { - alpha: this.transparent, - antialias:true, // SPEED UP?? - premultipliedAlpha:false, - stencil:true - }); - } - catch (e) - { - throw new Error(" This browser does not support webGL. Try using the canvas renderer" + this); - } - - PIXI.initPrimitiveShader(); - PIXI.initDefaultShader(); - PIXI.initDefaultStripShader(); - - PIXI.activateDefaultShader(); - - var gl = this.gl; - PIXI.WebGLRenderer.gl = gl; - - this.batch = new PIXI.WebGLBatch(gl); - gl.disable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); - - gl.enable(gl.BLEND); - gl.colorMask(true, true, true, this.transparent); - - PIXI.projection = new PIXI.Point(400, 300); - - this.resize(this.width, this.height); - this.contextLost = false; - - this.stageRenderGroup = new PIXI.WebGLRenderGroup(this.gl); -} - -// constructor -PIXI.WebGLRenderer.prototype.constructor = PIXI.WebGLRenderer; - -/** - * Gets a new WebGLBatch from the pool - * - * @static - * @method getBatch - * @return {WebGLBatch} - * @private - */ -PIXI.WebGLRenderer.getBatch = function() -{ - if(PIXI._batchs.length == 0) - { - return new PIXI.WebGLBatch(PIXI.WebGLRenderer.gl); - } - else - { - return PIXI._batchs.pop(); - } -} - -/** - * Puts a batch back into the pool - * - * @static - * @method returnBatch - * @param batch {WebGLBatch} The batch to return - * @private - */ -PIXI.WebGLRenderer.returnBatch = function(batch) -{ - batch.clean(); - PIXI._batchs.push(batch); -} - -/** - * Renders the stage to its webGL view - * - * @method render - * @param stage {Stage} the Stage element to be rendered - */ -PIXI.WebGLRenderer.prototype.render = function(stage) -{ - if(this.contextLost)return; - - - // if rendering a new stage clear the batchs.. - if(this.__stage !== stage) - { - // TODO make this work - // dont think this is needed any more? - //if(this.__stage)this.checkVisibility(this.__stage, false) - - this.__stage = stage; - this.stageRenderGroup.setRenderable(stage); - } - - // TODO not needed now... - // update children if need be - // best to remove first! - /*for (var i=0; i < stage.__childrenRemoved.length; i++) - { - var group = stage.__childrenRemoved[i].__renderGroup - if(group)group.removeDisplayObject(stage.__childrenRemoved[i]); - }*/ - - // update any textures - PIXI.WebGLRenderer.updateTextures(); - - // recursivly loop through all items! - //this.checkVisibility(stage, true); - - // update the scene graph - stage.updateTransform(); - - var gl = this.gl; - - // -- Does this need to be set every frame? -- // - gl.colorMask(true, true, true, this.transparent); - gl.viewport(0, 0, this.width, this.height); - - // set the correct matrix.. - // gl.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform, false, this.projectionMatrix); - - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - - gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); - gl.clear(gl.COLOR_BUFFER_BIT); - - // HACK TO TEST - //PIXI.projectionMatrix = this.projectionMatrix; - - this.stageRenderGroup.backgroundColor = stage.backgroundColorSplit; - this.stageRenderGroup.render(PIXI.projection); - - // interaction - // run interaction! - if(stage.interactive) - { - //need to add some events! - if(!stage._interactiveEventsAdded) - { - stage._interactiveEventsAdded = true; - stage.interactionManager.setTarget(this); - } - } - - // after rendering lets confirm all frames that have been uodated.. - if(PIXI.Texture.frameUpdates.length > 0) - { - for (var i=0; i < PIXI.Texture.frameUpdates.length; i++) - { - PIXI.Texture.frameUpdates[i].updateFrame = false; - }; - - PIXI.Texture.frameUpdates = []; - } -} - -/** - * Updates the textures loaded into this webgl renderer - * - * @static - * @method updateTextures - * @private - */ -PIXI.WebGLRenderer.updateTextures = function() -{ - for (var i=0; i < PIXI.texturesToUpdate.length; i++) this.updateTexture(PIXI.texturesToUpdate[i]); - for (var i=0; i < PIXI.texturesToDestroy.length; i++) this.destroyTexture(PIXI.texturesToDestroy[i]); - PIXI.texturesToUpdate = []; - PIXI.texturesToDestroy = []; -} - -/** - * Updates a loaded webgl texture - * - * @static - * @method updateTexture - * @param texture {Texture} The texture to update - * @private - */ -PIXI.WebGLRenderer.updateTexture = function(texture) -{ - var gl = PIXI.gl; - - if(!texture._glTexture) - { - texture._glTexture = gl.createTexture(); - } - - if(texture.hasLoaded) - { - gl.bindTexture(gl.TEXTURE_2D, texture._glTexture); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true); - - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - - // reguler... - - if(!texture._powerOf2) - { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - } - else - { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); - } - - gl.bindTexture(gl.TEXTURE_2D, null); - } -} - -/** - * Destroys a loaded webgl texture - * - * @method destroyTexture - * @param texture {Texture} The texture to update - * @private - */ -PIXI.WebGLRenderer.prototype.destroyTexture = function(texture) -{ - var gl = this.gl; - - if(texture._glTexture) - { - texture._glTexture = gl.createTexture(); - gl.deleteTexture(gl.TEXTURE_2D, texture._glTexture); - } -} - -/** - * resizes the webGL view to the specified width and height - * - * @method resize - * @param width {Number} the new width of the webGL view - * @param height {Number} the new height of the webGL view - */ -PIXI.WebGLRenderer.prototype.resize = function(width, height) -{ - this.width = width; - this.height = height; - - this.view.width = width; - this.view.height = height; - - this.gl.viewport(0, 0, this.width, this.height); - - //var projectionMatrix = this.projectionMatrix; - - PIXI.projection.x = this.width/2; - PIXI.projection.y = this.height/2; - -// projectionMatrix[0] = 2/this.width; -// projectionMatrix[5] = -2/this.height; -// projectionMatrix[12] = -1; -// projectionMatrix[13] = 1; -} - -/** - * Handles a lost webgl context - * - * @method handleContextLost - * @param event {Event} - * @private - */ -PIXI.WebGLRenderer.prototype.handleContextLost = function(event) -{ - event.preventDefault(); - this.contextLost = true; -} - -/** - * Handles a restored webgl context - * - * @method handleContextRestored - * @param event {Event} - * @private - */ -PIXI.WebGLRenderer.prototype.handleContextRestored = function(event) -{ - this.gl = this.view.getContext("experimental-webgl", { - alpha: true - }); - - this.initShaders(); - - for(var key in PIXI.TextureCache) - { - var texture = PIXI.TextureCache[key].baseTexture; - texture._glTexture = null; - PIXI.WebGLRenderer.updateTexture(texture); - }; - - for (var i=0; i < this.batchs.length; i++) - { - this.batchs[i].restoreLostContext(this.gl)// - this.batchs[i].dirty = true; - }; - - PIXI._restoreBatchs(this.gl); - - this.contextLost = false; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI._batchs = []; - -/** - * @private - */ -PIXI._getBatch = function(gl) -{ - if(PIXI._batchs.length == 0) - { - return new PIXI.WebGLBatch(gl); - } - else - { - return PIXI._batchs.pop(); - } -} - -/** - * @private - */ -PIXI._returnBatch = function(batch) -{ - batch.clean(); - PIXI._batchs.push(batch); -} - -/** - * @private - */ -PIXI._restoreBatchs = function(gl) -{ - for (var i=0; i < PIXI._batchs.length; i++) - { - PIXI._batchs[i].restoreLostContext(gl); - }; -} - -/** - * A WebGLBatch Enables a group of sprites to be drawn using the same settings. - * if a group of sprites all have the same baseTexture and blendMode then they can be grouped into a batch. - * All the sprites in a batch can then be drawn in one go by the GPU which is hugely efficient. ALL sprites - * in the webGL renderer are added to a batch even if the batch only contains one sprite. Batching is handled - * automatically by the webGL renderer. A good tip is: the smaller the number of batchs there are, the faster - * the webGL renderer will run. - * - * @class WebGLBatch - * @constructor - * @param gl {WebGLContext} an instance of the webGL context - */ -PIXI.WebGLBatch = function(gl) -{ - this.gl = gl; - - this.size = 0; - - this.vertexBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - this.uvBuffer = gl.createBuffer(); - this.colorBuffer = gl.createBuffer(); - this.blendMode = PIXI.blendModes.NORMAL; - this.dynamicSize = 1; -} - -// constructor -PIXI.WebGLBatch.prototype.constructor = PIXI.WebGLBatch; - -/** - * Cleans the batch so that is can be returned to an object pool and reused - * - * @method clean - */ -PIXI.WebGLBatch.prototype.clean = function() -{ - this.verticies = []; - this.uvs = []; - this.indices = []; - this.colors = []; - //this.sprites = []; - this.dynamicSize = 1; - this.texture = null; - this.last = null; - this.size = 0; - this.head; - this.tail; -} - -/** - * Recreates the buffers in the event of a context loss - * - * @method restoreLostContext - * @param gl {WebGLContext} - */ -PIXI.WebGLBatch.prototype.restoreLostContext = function(gl) -{ - this.gl = gl; - this.vertexBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - this.uvBuffer = gl.createBuffer(); - this.colorBuffer = gl.createBuffer(); -} - -/** - * inits the batch's texture and blend mode based if the supplied sprite - * - * @method init - * @param sprite {Sprite} the first sprite to be added to the batch. Only sprites with - * the same base texture and blend mode will be allowed to be added to this batch - */ -PIXI.WebGLBatch.prototype.init = function(sprite) -{ - sprite.batch = this; - this.dirty = true; - this.blendMode = sprite.blendMode; - this.texture = sprite.texture.baseTexture; -// this.sprites.push(sprite); - this.head = sprite; - this.tail = sprite; - this.size = 1; - - this.growBatch(); -} - -/** - * inserts a sprite before the specified sprite - * - * @method insertBefore - * @param sprite {Sprite} the sprite to be added - * @param nextSprite {nextSprite} the first sprite will be inserted before this sprite - */ -PIXI.WebGLBatch.prototype.insertBefore = function(sprite, nextSprite) -{ - this.size++; - - sprite.batch = this; - this.dirty = true; - var tempPrev = nextSprite.__prev; - nextSprite.__prev = sprite; - sprite.__next = nextSprite; - - if(tempPrev) - { - sprite.__prev = tempPrev; - tempPrev.__next = sprite; - } - else - { - this.head = sprite; - //this.head.__prev = null - } -} - -/** - * inserts a sprite after the specified sprite - * - * @method insertAfter - * @param sprite {Sprite} the sprite to be added - * @param previousSprite {Sprite} the first sprite will be inserted after this sprite - */ -PIXI.WebGLBatch.prototype.insertAfter = function(sprite, previousSprite) -{ - this.size++; - - sprite.batch = this; - this.dirty = true; - - var tempNext = previousSprite.__next; - previousSprite.__next = sprite; - sprite.__prev = previousSprite; - - if(tempNext) - { - sprite.__next = tempNext; - tempNext.__prev = sprite; - } - else - { - this.tail = sprite - } -} - -/** - * removes a sprite from the batch - * - * @method remove - * @param sprite {Sprite} the sprite to be removed - */ -PIXI.WebGLBatch.prototype.remove = function(sprite) -{ - this.size--; - - if(this.size == 0) - { - sprite.batch = null; - sprite.__prev = null; - sprite.__next = null; - return; - } - - if(sprite.__prev) - { - sprite.__prev.__next = sprite.__next; - } - else - { - this.head = sprite.__next; - this.head.__prev = null; - } - - if(sprite.__next) - { - sprite.__next.__prev = sprite.__prev; - } - else - { - this.tail = sprite.__prev; - this.tail.__next = null - } - - sprite.batch = null; - sprite.__next = null; - sprite.__prev = null; - this.dirty = true; -} - -/** - * Splits the batch into two with the specified sprite being the start of the new batch. - * - * @method split - * @param sprite {Sprite} the sprite that indicates where the batch should be split - * @return {WebGLBatch} the new batch - */ -PIXI.WebGLBatch.prototype.split = function(sprite) -{ - this.dirty = true; - - var batch = new PIXI.WebGLBatch(this.gl);//PIXI._getBatch(this.gl); - batch.init(sprite); - batch.texture = this.texture; - batch.tail = this.tail; - - this.tail = sprite.__prev; - this.tail.__next = null; - - sprite.__prev = null; - // return a splite batch! - //sprite.__prev.__next = null; - //sprite.__prev = null; - - // TODO this size is wrong! - // need to recalculate :/ problem with a linked list! - // unless it gets calculated in the "clean"? - - // need to loop through items as there is no way to know the length on a linked list :/ - var tempSize = 0; - while(sprite) - { - tempSize++; - sprite.batch = batch; - sprite = sprite.__next; - } - - batch.size = tempSize; - this.size -= tempSize; - - return batch; -} - -/** - * Merges two batchs together - * - * @method merge - * @param batch {WebGLBatch} the batch that will be merged - */ -PIXI.WebGLBatch.prototype.merge = function(batch) -{ - this.dirty = true; - - this.tail.__next = batch.head; - batch.head.__prev = this.tail; - - this.size += batch.size; - - this.tail = batch.tail; - - var sprite = batch.head; - while(sprite) - { - sprite.batch = this; - sprite = sprite.__next; - } -} - -/** - * Grows the size of the batch. As the elements in the batch cannot have a dynamic size this - * function is used to increase the size of the batch. It also creates a little extra room so - * that the batch does not need to be resized every time a sprite is added - * - * @method growBatch - */ -PIXI.WebGLBatch.prototype.growBatch = function() -{ - var gl = this.gl; - if( this.size == 1) - { - this.dynamicSize = 1; - } - else - { - this.dynamicSize = this.size * 1.5 - } - // grow verts - this.verticies = new Float32Array(this.dynamicSize * 8); - - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER,this.verticies , gl.DYNAMIC_DRAW); - - this.uvs = new Float32Array( this.dynamicSize * 8 ) - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, this.uvs , gl.DYNAMIC_DRAW); - - this.dirtyUVS = true; - - this.colors = new Float32Array( this.dynamicSize * 4 ) - gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, this.colors , gl.DYNAMIC_DRAW); - - this.dirtyColors = true; - - this.indices = new Uint16Array(this.dynamicSize * 6); - var length = this.indices.length/6; - - for (var i=0; i < length; i++) - { - var index2 = i * 6; - var index3 = i * 4; - this.indices[index2 + 0] = index3 + 0; - this.indices[index2 + 1] = index3 + 1; - this.indices[index2 + 2] = index3 + 2; - this.indices[index2 + 3] = index3 + 0; - this.indices[index2 + 4] = index3 + 2; - this.indices[index2 + 5] = index3 + 3; - }; - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW); -} - -/** - * Refresh's all the data in the batch and sync's it with the webGL buffers - * - * @method refresh - */ -PIXI.WebGLBatch.prototype.refresh = function() -{ - var gl = this.gl; - - if (this.dynamicSize < this.size) - { - this.growBatch(); - } - - var indexRun = 0; - var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index; - var a, b, c, d, tx, ty; - - var displayObject = this.head; - - while(displayObject) - { - index = indexRun * 8; - - var texture = displayObject.texture; - - var frame = texture.frame; - var tw = texture.baseTexture.width; - var th = texture.baseTexture.height; - - this.uvs[index + 0] = frame.x / tw; - this.uvs[index +1] = frame.y / th; - - this.uvs[index +2] = (frame.x + frame.width) / tw; - this.uvs[index +3] = frame.y / th; - - this.uvs[index +4] = (frame.x + frame.width) / tw; - this.uvs[index +5] = (frame.y + frame.height) / th; - - this.uvs[index +6] = frame.x / tw; - this.uvs[index +7] = (frame.y + frame.height) / th; - - displayObject.updateFrame = false; - - colorIndex = indexRun * 4; - this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha; - - displayObject = displayObject.__next; - - indexRun ++; - } - - this.dirtyUVS = true; - this.dirtyColors = true; -} - -/** - * Updates all the relevant geometry and uploads the data to the GPU - * - * @method update - */ -PIXI.WebGLBatch.prototype.update = function() -{ - var gl = this.gl; - var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, index2, index3 - - var a, b, c, d, tx, ty; - - var indexRun = 0; - - var displayObject = this.head; - - while(displayObject) - { - if(displayObject.worldVisible) - { - width = displayObject.texture.frame.width; - height = displayObject.texture.frame.height; - - // TODO trim?? - aX = displayObject.anchor.x;// - displayObject.texture.trim.x - aY = displayObject.anchor.y; //- displayObject.texture.trim.y - w0 = width * (1-aX); - w1 = width * -aX; - - h0 = height * (1-aY); - h1 = height * -aY; - - index = indexRun * 8; - - worldTransform = displayObject.worldTransform; - - a = worldTransform[0]; - b = worldTransform[3]; - c = worldTransform[1]; - d = worldTransform[4]; - tx = worldTransform[2]; - ty = worldTransform[5]; - - this.verticies[index + 0 ] = a * w1 + c * h1 + tx; - this.verticies[index + 1 ] = d * h1 + b * w1 + ty; - - this.verticies[index + 2 ] = a * w0 + c * h1 + tx; - this.verticies[index + 3 ] = d * h1 + b * w0 + ty; - - this.verticies[index + 4 ] = a * w0 + c * h0 + tx; - this.verticies[index + 5 ] = d * h0 + b * w0 + ty; - - this.verticies[index + 6] = a * w1 + c * h0 + tx; - this.verticies[index + 7] = d * h0 + b * w1 + ty; - - if(displayObject.updateFrame || displayObject.texture.updateFrame) - { - this.dirtyUVS = true; - - var texture = displayObject.texture; - - var frame = texture.frame; - var tw = texture.baseTexture.width; - var th = texture.baseTexture.height; - - this.uvs[index + 0] = frame.x / tw; - this.uvs[index +1] = frame.y / th; - - this.uvs[index +2] = (frame.x + frame.width) / tw; - this.uvs[index +3] = frame.y / th; - - this.uvs[index +4] = (frame.x + frame.width) / tw; - this.uvs[index +5] = (frame.y + frame.height) / th; - - this.uvs[index +6] = frame.x / tw; - this.uvs[index +7] = (frame.y + frame.height) / th; - - displayObject.updateFrame = false; - } - - // TODO this probably could do with some optimisation.... - if(displayObject.cacheAlpha != displayObject.worldAlpha) - { - displayObject.cacheAlpha = displayObject.worldAlpha; - - var colorIndex = indexRun * 4; - this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha; - this.dirtyColors = true; - } - } - else - { - index = indexRun * 8; - - this.verticies[index + 0 ] = 0; - this.verticies[index + 1 ] = 0; - - this.verticies[index + 2 ] = 0; - this.verticies[index + 3 ] = 0; - - this.verticies[index + 4 ] = 0; - this.verticies[index + 5 ] = 0; - - this.verticies[index + 6] = 0; - this.verticies[index + 7] = 0; - } - - indexRun++; - displayObject = displayObject.__next; - } -} - -/** - * Draws the batch to the frame buffer - * - * @method render - */ -PIXI.WebGLBatch.prototype.render = function(start, end) -{ - start = start || 0; - //end = end || this.size; - if(end == undefined)end = this.size; - - if(this.dirty) - { - this.refresh(); - this.dirty = false; - } - - if (this.size == 0)return; - - this.update(); - var gl = this.gl; - - //TODO optimize this! - - var shaderProgram = PIXI.shaderProgram; - gl.useProgram(shaderProgram); - - // update the verts.. - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - // ok.. - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.verticies) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - - if(this.dirtyUVS) - { - this.dirtyUVS = false; - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvs); - } - - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, this.texture._glTexture); - - // update color! - gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer); - - if(this.dirtyColors) - { - this.dirtyColors = false; - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.colors); - } - - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - - //var startIndex = 0//1; - var len = end - start; - // console.log(this.size) - // DRAW THAT this! - gl.drawElements(gl.TRIANGLES, len * 6, gl.UNSIGNED_SHORT, start * 2 * 6 ); -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A WebGLBatch Enables a group of sprites to be drawn using the same settings. - * if a group of sprites all have the same baseTexture and blendMode then they can be - * grouped into a batch. All the sprites in a batch can then be drawn in one go by the - * GPU which is hugely efficient. ALL sprites in the webGL renderer are added to a batch - * even if the batch only contains one sprite. Batching is handled automatically by the - * webGL renderer. A good tip is: the smaller the number of batchs there are, the faster - * the webGL renderer will run. - * - * @class WebGLBatch - * @contructor - * @param gl {WebGLContext} An instance of the webGL context - */ -PIXI.WebGLRenderGroup = function(gl) -{ - this.gl = gl; - this.root; - - this.backgroundColor; - this.batchs = []; - this.toRemove = []; -} - -// constructor -PIXI.WebGLRenderGroup.prototype.constructor = PIXI.WebGLRenderGroup; - -/** - * Add a display object to the webgl renderer - * - * @method setRenderable - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.setRenderable = function(displayObject) -{ - // has this changed?? - if(this.root)this.removeDisplayObjectAndChildren(this.root); - - displayObject.worldVisible = displayObject.visible; - - // soooooo // - // to check if any batchs exist already?? - - // TODO what if its already has an object? should remove it - this.root = displayObject; - this.addDisplayObjectAndChildren(displayObject); -} - -/** - * Renders the stage to its webgl view - * - * @method render - * @param projection {Object} - */ -PIXI.WebGLRenderGroup.prototype.render = function(projection) -{ - PIXI.WebGLRenderer.updateTextures(); - - var gl = this.gl; - - - gl.uniform2f(PIXI.shaderProgram.projectionVector, projection.x, projection.y); - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - - // TODO remove this by replacing visible with getter setters.. - this.checkVisibility(this.root, this.root.visible); - - // will render all the elements in the group - var renderable; - - - for (var i=0; i < this.batchs.length; i++) - { - renderable = this.batchs[i]; - if(renderable instanceof PIXI.WebGLBatch) - { - this.batchs[i].render(); - } - else if(renderable instanceof PIXI.TilingSprite) - { - if(renderable.visible)this.renderTilingSprite(renderable, projection); - } - else if(renderable instanceof PIXI.Strip) - { - if(renderable.visible)this.renderStrip(renderable, projection); - } - else if(renderable instanceof PIXI.Graphics) - { - if(renderable.visible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable, projection);//, projectionMatrix); - } - else if(renderable instanceof PIXI.FilterBlock) - { - /* - * for now only masks are supported.. - */ - if(renderable.open) - { - gl.enable(gl.STENCIL_TEST); - - gl.colorMask(false, false, false, false); - gl.stencilFunc(gl.ALWAYS,1,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE); - - PIXI.WebGLGraphics.renderGraphics(renderable.mask, projection); - - gl.colorMask(true, true, true, false); - gl.stencilFunc(gl.NOTEQUAL,0,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); - } - else - { - gl.disable(gl.STENCIL_TEST); - } - } - } - -} - -/** - * Renders the stage to its webgl view - * - * @method handleFilter - * @param filter {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.handleFilter = function(filter, projection) -{ - -} - -/** - * Renders a specific displayObject - * - * @method renderSpecific - * @param displayObject {DisplayObject} - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderSpecific = function(displayObject, projection) -{ - PIXI.WebGLRenderer.updateTextures(); - - var gl = this.gl; - this.checkVisibility(displayObject, displayObject.visible); - -// gl.uniformMatrix4fv(PIXI.shaderProgram.mvMatrixUniform, false, projectionMatrix); - gl.uniform2f(PIXI.shaderProgram.projectionVector, projection.x, projection.y); - - // to do! - // render part of the scene... - - var startIndex; - var startBatchIndex; - - var endIndex; - var endBatchIndex; - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.first; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - var startBatch = nextRenderable.batch; - - if(nextRenderable instanceof PIXI.Sprite) - { - startBatch = nextRenderable.batch; - - var head = startBatch.head; - var next = head; - - // ok now we have the batch.. need to find the start index! - if(head == nextRenderable) - { - startIndex = 0; - } - else - { - startIndex = 1; - - while(head.__next != nextRenderable) - { - startIndex++; - head = head.__next; - } - } - } - else - { - startBatch = nextRenderable; - } - - // Get the LAST renderable object - var lastRenderable = displayObject; - var endBatch; - var lastItem = displayObject; - while(lastItem.children.length > 0) - { - lastItem = lastItem.children[lastItem.children.length-1]; - if(lastItem.renderable)lastRenderable = lastItem; - } - - if(lastRenderable instanceof PIXI.Sprite) - { - endBatch = lastRenderable.batch; - - var head = endBatch.head; - - if(head == lastRenderable) - { - endIndex = 0; - } - else - { - endIndex = 1; - - while(head.__next != lastRenderable) - { - endIndex++; - head = head.__next; - } - } - } - else - { - endBatch = lastRenderable; - } - - // TODO - need to fold this up a bit! - - if(startBatch == endBatch) - { - if(startBatch instanceof PIXI.WebGLBatch) - { - startBatch.render(startIndex, endIndex+1); - } - else - { - this.renderSpecial(startBatch, projection); - } - return; - } - - // now we have first and last! - startBatchIndex = this.batchs.indexOf(startBatch); - endBatchIndex = this.batchs.indexOf(endBatch); - - // DO the first batch - if(startBatch instanceof PIXI.WebGLBatch) - { - startBatch.render(startIndex); - } - else - { - this.renderSpecial(startBatch, projection); - } - - // DO the middle batchs.. - for (var i=startBatchIndex+1; i < endBatchIndex; i++) - { - renderable = this.batchs[i]; - - if(renderable instanceof PIXI.WebGLBatch) - { - this.batchs[i].render(); - } - else - { - this.renderSpecial(renderable, projection); - } - } - - // DO the last batch.. - if(endBatch instanceof PIXI.WebGLBatch) - { - endBatch.render(0, endIndex+1); - } - else - { - this.renderSpecial(endBatch, projection); - } -} - -/** - * Renders a specific renderable - * - * @method renderSpecial - * @param renderable {DisplayObject} - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderSpecial = function(renderable, projection) -{ - if(renderable instanceof PIXI.TilingSprite) - { - if(renderable.visible)this.renderTilingSprite(renderable, projection); - } - else if(renderable instanceof PIXI.Strip) - { - if(renderable.visible)this.renderStrip(renderable, projection); - } - else if(renderable instanceof PIXI.CustomRenderable) - { - if(renderable.visible) renderable.renderWebGL(this, projection); - } - else if(renderable instanceof PIXI.Graphics) - { - if(renderable.visible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable, projection); - } - else if(renderable instanceof PIXI.FilterBlock) - { - /* - * for now only masks are supported.. - */ - - var gl = PIXI.gl; - - if(renderable.open) - { - gl.enable(gl.STENCIL_TEST); - - gl.colorMask(false, false, false, false); - gl.stencilFunc(gl.ALWAYS,1,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE); - - PIXI.WebGLGraphics.renderGraphics(renderable.mask, projection); - - // we know this is a render texture so enable alpha too.. - gl.colorMask(true, true, true, true); - gl.stencilFunc(gl.NOTEQUAL,0,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); - } - else - { - gl.disable(gl.STENCIL_TEST); - } - } -} - -/** - * Checks the visibility of a displayObject - * - * @method checkVisibility - * @param displayObject {DisplayObject} - * @param globalVisible {Boolean} - * @private - */ -PIXI.WebGLRenderGroup.prototype.checkVisibility = function(displayObject, globalVisible) -{ - // give the dp a reference to its renderGroup... - var children = displayObject.children; - //displayObject.worldVisible = globalVisible; - for (var i=0; i < children.length; i++) - { - var child = children[i]; - - // TODO optimize... should'nt need to loop through everything all the time - child.worldVisible = child.visible && globalVisible; - - // everything should have a batch! - // time to see whats new! - if(child.textureChange) - { - child.textureChange = false; - if(child.worldVisible)this.updateTexture(child); - // update texture!! - } - - if(child.children.length > 0) - { - this.checkVisibility(child, child.worldVisible); - } - }; -} - -/** - * Updates a webgl texture - * - * @method updateTexture - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.updateTexture = function(displayObject) -{ - - // TODO definitely can optimse this function.. - - this.removeObject(displayObject); - - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - var previousRenderable = displayObject.first; - while(previousRenderable != this.root) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.last; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - - this.insertObject(displayObject, previousRenderable, nextRenderable); -} - -/** - * Adds filter blocks - * - * @method addFilterBlocks - * @param start {FilterBlock} - * @param end {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.addFilterBlocks = function(start, end) -{ - start.__renderGroup = this; - end.__renderGroup = this; - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - var previousRenderable = start; - while(previousRenderable != this.root) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - this.insertAfter(start, previousRenderable); - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var previousRenderable2 = end; - while(previousRenderable2 != this.root) - { - previousRenderable2 = previousRenderable2._iPrev; - if(previousRenderable2.renderable && previousRenderable2.__renderGroup)break; - } - this.insertAfter(end, previousRenderable2); -} - -/** - * Remove filter blocks - * - * @method removeFilterBlocks - * @param start {FilterBlock} - * @param end {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeFilterBlocks = function(start, end) -{ - this.removeObject(start); - this.removeObject(end); -} - -/** - * Adds a display object and children to the webgl context - * - * @method addDisplayObjectAndChildren - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.addDisplayObjectAndChildren = function(displayObject) -{ - if(displayObject.__renderGroup)displayObject.__renderGroup.removeDisplayObjectAndChildren(displayObject); - - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - - var previousRenderable = displayObject.first; - while(previousRenderable != this.root.first) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.last; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - - // one the display object hits this. we can break the loop - - var tempObject = displayObject.first; - var testObject = displayObject.last._iNext; - do - { - tempObject.__renderGroup = this; - - if(tempObject.renderable) - { - - this.insertObject(tempObject, previousRenderable, nextRenderable); - previousRenderable = tempObject; - } - - tempObject = tempObject._iNext; - } - while(tempObject != testObject) -} - -/** - * Removes a display object and children to the webgl context - * - * @method removeDisplayObjectAndChildren - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeDisplayObjectAndChildren = function(displayObject) -{ - if(displayObject.__renderGroup != this)return; - -// var displayObject = displayObject.first; - var lastObject = displayObject.last; - do - { - displayObject.__renderGroup = null; - if(displayObject.renderable)this.removeObject(displayObject); - displayObject = displayObject._iNext; - } - while(displayObject) -} - -/** - * Inserts a displayObject into the linked list - * - * @method insertObject - * @param displayObject {DisplayObject} - * @param previousObject {DisplayObject} - * @param nextObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.insertObject = function(displayObject, previousObject, nextObject) -{ - // while looping below THE OBJECT MAY NOT HAVE BEEN ADDED - var previousSprite = previousObject; - var nextSprite = nextObject; - - /* - * so now we have the next renderable and the previous renderable - * - */ - if(displayObject instanceof PIXI.Sprite) - { - var previousBatch - var nextBatch - - if(previousSprite instanceof PIXI.Sprite) - { - previousBatch = previousSprite.batch; - if(previousBatch) - { - if(previousBatch.texture == displayObject.texture.baseTexture && previousBatch.blendMode == displayObject.blendMode) - { - previousBatch.insertAfter(displayObject, previousSprite); - return; - } - } - } - else - { - // TODO reword! - previousBatch = previousSprite; - } - - if(nextSprite) - { - if(nextSprite instanceof PIXI.Sprite) - { - nextBatch = nextSprite.batch; - - //batch may not exist if item was added to the display list but not to the webGL - if(nextBatch) - { - if(nextBatch.texture == displayObject.texture.baseTexture && nextBatch.blendMode == displayObject.blendMode) - { - nextBatch.insertBefore(displayObject, nextSprite); - return; - } - else - { - if(nextBatch == previousBatch) - { - // THERE IS A SPLIT IN THIS BATCH! // - var splitBatch = previousBatch.split(nextSprite); - // COOL! - // add it back into the array - /* - * OOPS! - * seems the new sprite is in the middle of a batch - * lets split it.. - */ - var batch = PIXI.WebGLRenderer.getBatch(); - - var index = this.batchs.indexOf( previousBatch ); - batch.init(displayObject); - this.batchs.splice(index+1, 0, batch, splitBatch); - - return; - } - } - } - } - else - { - // TODO re-word! - - nextBatch = nextSprite; - } - } - - /* - * looks like it does not belong to any batch! - * but is also not intersecting one.. - * time to create anew one! - */ - - var batch = PIXI.WebGLRenderer.getBatch(); - batch.init(displayObject); - - if(previousBatch) // if this is invalid it means - { - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, batch); - } - else - { - this.batchs.push(batch); - } - - return; - } - else if(displayObject instanceof PIXI.TilingSprite) - { - - // add to a batch!! - this.initTilingSprite(displayObject); - // this.batchs.push(displayObject); - - } - else if(displayObject instanceof PIXI.Strip) - { - // add to a batch!! - this.initStrip(displayObject); - // this.batchs.push(displayObject); - } - else if(displayObject)// instanceof PIXI.Graphics) - { - //displayObject.initWebGL(this); - - // add to a batch!! - //this.initStrip(displayObject); - //this.batchs.push(displayObject); - } - - this.insertAfter(displayObject, previousSprite); - - // insert and SPLIT! - -} - -/** - * Inserts a displayObject into the linked list - * - * @method insertAfter - * @param item {DisplayObject} - * @param displayObject {DisplayObject} The object to insert - * @private - */ -PIXI.WebGLRenderGroup.prototype.insertAfter = function(item, displayObject) -{ - if(displayObject instanceof PIXI.Sprite) - { - var previousBatch = displayObject.batch; - - if(previousBatch) - { - // so this object is in a batch! - - // is it not? need to split the batch - if(previousBatch.tail == displayObject) - { - // is it tail? insert in to batchs - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, item); - } - else - { - // TODO MODIFY ADD / REMOVE CHILD TO ACCOUNT FOR FILTERS (also get prev and next) // - - // THERE IS A SPLIT IN THIS BATCH! // - var splitBatch = previousBatch.split(displayObject.__next); - - // COOL! - // add it back into the array - /* - * OOPS! - * seems the new sprite is in the middle of a batch - * lets split it.. - */ - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, item, splitBatch); - } - } - else - { - this.batchs.push(item); - } - } - else - { - var index = this.batchs.indexOf( displayObject ); - this.batchs.splice(index+1, 0, item); - } -} - -/** - * Removes a displayObject from the linked list - * - * @method removeObject - * @param displayObject {DisplayObject} The object to remove - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeObject = function(displayObject) -{ - // loop through children.. - // display object // - - // add a child from the render group.. - // remove it and all its children! - //displayObject.cacheVisible = false;//displayObject.visible; - - /* - * removing is a lot quicker.. - * - */ - var batchToRemove; - - if(displayObject instanceof PIXI.Sprite) - { - // should always have a batch! - var batch = displayObject.batch; - if(!batch)return; // this means the display list has been altered befre rendering - - batch.remove(displayObject); - - if(batch.size==0) - { - batchToRemove = batch; - } - } - else - { - batchToRemove = displayObject; - } - - /* - * Looks like there is somthing that needs removing! - */ - if(batchToRemove) - { - var index = this.batchs.indexOf( batchToRemove ); - if(index == -1)return;// this means it was added then removed before rendered - - // ok so.. check to see if you adjacent batchs should be joined. - // TODO may optimise? - if(index == 0 || index == this.batchs.length-1) - { - // wha - eva! just get of the empty batch! - this.batchs.splice(index, 1); - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - - return; - } - - if(this.batchs[index-1] instanceof PIXI.WebGLBatch && this.batchs[index+1] instanceof PIXI.WebGLBatch) - { - if(this.batchs[index-1].texture == this.batchs[index+1].texture && this.batchs[index-1].blendMode == this.batchs[index+1].blendMode) - { - //console.log("MERGE") - this.batchs[index-1].merge(this.batchs[index+1]); - - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - PIXI.WebGLRenderer.returnBatch(this.batchs[index+1]); - this.batchs.splice(index, 2); - return; - } - } - - this.batchs.splice(index, 1); - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - } -} - -/** - * Initializes a tiling sprite - * - * @method initTilingSprite - * @param sprite {TilingSprite} The tiling sprite to initialize - * @private - */ -PIXI.WebGLRenderGroup.prototype.initTilingSprite = function(sprite) -{ - var gl = this.gl; - - // make the texture tilable.. - - sprite.verticies = new Float32Array([0, 0, - sprite.width, 0, - sprite.width, sprite.height, - 0, sprite.height]); - - sprite.uvs = new Float32Array([0, 0, - 1, 0, - 1, 1, - 0, 1]); - - sprite.colors = new Float32Array([1,1,1,1]); - - sprite.indices = new Uint16Array([0, 1, 3,2])//, 2]); - - sprite._vertexBuffer = gl.createBuffer(); - sprite._indexBuffer = gl.createBuffer(); - sprite._uvBuffer = gl.createBuffer(); - sprite._colorBuffer = gl.createBuffer(); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.verticies, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.uvs, gl.DYNAMIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.colors, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, sprite._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, sprite.indices, gl.STATIC_DRAW); - -// return ( (x > 0) && ((x & (x - 1)) == 0) ); - - if(sprite.texture.baseTexture._glTexture) - { - gl.bindTexture(gl.TEXTURE_2D, sprite.texture.baseTexture._glTexture); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); - sprite.texture.baseTexture._powerOf2 = true; - } - else - { - sprite.texture.baseTexture._powerOf2 = true; - } -} - -/** - * Renders a Strip - * - * @method renderStrip - * @param strip {Strip} The strip to render - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderStrip = function(strip, projection) -{ - var gl = this.gl; - var shaderProgram = PIXI.shaderProgram; -// mat - //var mat4Real = PIXI.mat3.toMat4(strip.worldTransform); - //PIXI.mat4.transpose(mat4Real); - //PIXI.mat4.multiply(projectionMatrix, mat4Real, mat4Real ) - - - gl.useProgram(PIXI.stripShaderProgram); - - var m = PIXI.mat3.clone(strip.worldTransform); - - PIXI.mat3.transpose(m); - - // set the matrix transform for the - gl.uniformMatrix3fv(PIXI.stripShaderProgram.translationMatrix, false, m); - gl.uniform2f(PIXI.stripShaderProgram.projectionVector, projection.x, projection.y); - gl.uniform1f(PIXI.stripShaderProgram.alpha, strip.worldAlpha); - -/* - if(strip.blendMode == PIXI.blendModes.NORMAL) - { - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - } - else - { - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR); - } - */ - - - if(!strip.dirty) - { - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferSubData(gl.ARRAY_BUFFER, 0, strip.verticies) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - } - else - { - strip.dirty = false; - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW); - - } - //console.log(gl.TRIANGLE_STRIP); - - gl.drawElements(gl.TRIANGLE_STRIP, strip.indices.length, gl.UNSIGNED_SHORT, 0); - - gl.useProgram(PIXI.shaderProgram); -} - -/** - * Renders a TilingSprite - * - * @method renderTilingSprite - * @param sprite {TilingSprite} The tiling sprite to render - * @param projectionMatrix {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderTilingSprite = function(sprite, projectionMatrix) -{ - var gl = this.gl; - var shaderProgram = PIXI.shaderProgram; - - var tilePosition = sprite.tilePosition; - var tileScale = sprite.tileScale; - - var offsetX = tilePosition.x/sprite.texture.baseTexture.width; - var offsetY = tilePosition.y/sprite.texture.baseTexture.height; - - var scaleX = (sprite.width / sprite.texture.baseTexture.width) / tileScale.x; - var scaleY = (sprite.height / sprite.texture.baseTexture.height) / tileScale.y; - - sprite.uvs[0] = 0 - offsetX; - sprite.uvs[1] = 0 - offsetY; - - sprite.uvs[2] = (1 * scaleX) -offsetX; - sprite.uvs[3] = 0 - offsetY; - - sprite.uvs[4] = (1 *scaleX) - offsetX; - sprite.uvs[5] = (1 *scaleY) - offsetY; - - sprite.uvs[6] = 0 - offsetX; - sprite.uvs[7] = (1 *scaleY) - offsetY; - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._uvBuffer); - gl.bufferSubData(gl.ARRAY_BUFFER, 0, sprite.uvs) - - this.renderStrip(sprite, projectionMatrix); -} - -/** - * Initializes a strip to be rendered - * - * @method initStrip - * @param strip {Strip} The strip to initialize - * @private - */ -PIXI.WebGLRenderGroup.prototype.initStrip = function(strip) -{ - // build the strip! - var gl = this.gl; - var shaderProgram = this.shaderProgram; - - strip._vertexBuffer = gl.createBuffer(); - strip._indexBuffer = gl.createBuffer(); - strip._uvBuffer = gl.createBuffer(); - strip._colorBuffer = gl.createBuffer(); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.DYNAMIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW); - - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW); -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * the CanvasRenderer draws the stage and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. - * Dont forget to add the view to your DOM or you will not see anything :) - * - * @class CanvasRenderer - * @constructor - * @param width=0 {Number} the width of the canvas view - * @param height=0 {Number} the height of the canvas view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - */ -PIXI.CanvasRenderer = function(width, height, view, transparent) -{ - this.transparent = transparent; - - /** - * The width of the canvas view - * - * @property width - * @type Number - * @default 800 - */ - this.width = width || 800; - - /** - * The height of the canvas view - * - * @property height - * @type Number - * @default 600 - */ - this.height = height || 600; - - /** - * The canvas element that the everything is drawn to - * - * @property view - * @type Canvas - */ - this.view = view || document.createElement( 'canvas' ); - - /** - * The canvas context that the everything is drawn to - * @property context - * @type Canvas 2d Context - */ - this.context = this.view.getContext("2d"); - - this.refresh = true; - // hack to enable some hardware acceleration! - //this.view.style["transform"] = "translatez(0)"; - - this.view.width = this.width; - this.view.height = this.height; - this.count = 0; -} - -// constructor -PIXI.CanvasRenderer.prototype.constructor = PIXI.CanvasRenderer; - -/** - * Renders the stage to its canvas view - * - * @method render - * @param stage {Stage} the Stage element to be rendered - */ -PIXI.CanvasRenderer.prototype.render = function(stage) -{ - // update children if need be - - //stage.__childrenAdded = []; - //stage.__childrenRemoved = []; - - // update textures if need be - PIXI.texturesToUpdate = []; - PIXI.texturesToDestroy = []; - - stage.updateTransform(); - - // update the background color - if(this.view.style.backgroundColor!=stage.backgroundColorString && !this.transparent)this.view.style.backgroundColor = stage.backgroundColorString; - - this.context.setTransform(1,0,0,1,0,0); - this.context.clearRect(0, 0, this.width, this.height) - this.renderDisplayObject(stage); - //as - - // run interaction! - if(stage.interactive) - { - //need to add some events! - if(!stage._interactiveEventsAdded) - { - stage._interactiveEventsAdded = true; - stage.interactionManager.setTarget(this); - } - } - - // remove frame updates.. - if(PIXI.Texture.frameUpdates.length > 0) - { - PIXI.Texture.frameUpdates = []; - } - - -} - -/** - * resizes the canvas view to the specified width and height - * - * @method resize - * @param width {Number} the new width of the canvas view - * @param height {Number} the new height of the canvas view - */ -PIXI.CanvasRenderer.prototype.resize = function(width, height) -{ - this.width = width; - this.height = height; - - this.view.width = width; - this.view.height = height; -} - -/** - * Renders a display object - * - * @method renderDisplayObject - * @param displayObject {DisplayObject} The displayObject to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject) -{ - // no loger recurrsive! - var transform; - var context = this.context; - - context.globalCompositeOperation = 'source-over'; - - // one the display object hits this. we can break the loop - var testObject = displayObject.last._iNext; - displayObject = displayObject.first; - - do - { - transform = displayObject.worldTransform; - - if(!displayObject.visible) - { - displayObject = displayObject.last._iNext; - continue; - } - - if(!displayObject.renderable) - { - displayObject = displayObject._iNext; - continue; - } - - if(displayObject instanceof PIXI.Sprite) - { - - var frame = displayObject.texture.frame; - - if(frame) - { - context.globalAlpha = displayObject.worldAlpha; - - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]); - - context.drawImage(displayObject.texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, - (displayObject.anchor.x) * -frame.width, - (displayObject.anchor.y) * -frame.height, - frame.width, - frame.height); - } - } - else if(displayObject instanceof PIXI.Strip) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - this.renderStrip(displayObject); - } - else if(displayObject instanceof PIXI.TilingSprite) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - this.renderTilingSprite(displayObject); - } - else if(displayObject instanceof PIXI.CustomRenderable) - { - displayObject.renderCanvas(this); - } - else if(displayObject instanceof PIXI.Graphics) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - PIXI.CanvasGraphics.renderGraphics(displayObject, context); - } - else if(displayObject instanceof PIXI.FilterBlock) - { - if(displayObject.open) - { - context.save(); - - var cacheAlpha = displayObject.mask.alpha; - var maskTransform = displayObject.mask.worldTransform; - - context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5]) - - displayObject.mask.worldAlpha = 0.5; - - context.worldAlpha = 0; - - PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, context); - // context.fillStyle = 0xFF0000; - // context.fillRect(0, 0, 200, 200); - context.clip(); - - displayObject.mask.worldAlpha = cacheAlpha; - //context.globalCompositeOperation = 'lighter'; - } - else - { - //context.globalCompositeOperation = 'source-over'; - context.restore(); - } - } - // count++ - displayObject = displayObject._iNext; - - - } - while(displayObject != testObject) - - -} - -/** - * Renders a flat strip - * - * @method renderStripFlat - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip) -{ - var context = this.context; - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - - context.beginPath(); - for (var i=1; i < length-2; i++) - { - - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - - }; - - context.fillStyle = "#FF0000"; - context.fill(); - context.closePath(); -} - -/** - * Renders a tiling sprite - * - * @method renderTilingSprite - * @param sprite {TilingSprite} The tilingsprite to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderTilingSprite = function(sprite) -{ - var context = this.context; - - context.globalAlpha = sprite.worldAlpha; - - if(!sprite.__tilePattern) sprite.__tilePattern = context.createPattern(sprite.texture.baseTexture.source, "repeat"); - - context.beginPath(); - - var tilePosition = sprite.tilePosition; - var tileScale = sprite.tileScale; - - // offset - context.scale(tileScale.x,tileScale.y); - context.translate(tilePosition.x, tilePosition.y); - - context.fillStyle = sprite.__tilePattern; - context.fillRect(-tilePosition.x,-tilePosition.y,sprite.width / tileScale.x, sprite.height / tileScale.y); - - context.scale(1/tileScale.x, 1/tileScale.y); - context.translate(-tilePosition.x, -tilePosition.y); - - context.closePath(); -} - -/** - * Renders a strip - * - * @method renderStrip - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStrip = function(strip) -{ - var context = this.context; - //context.globalCompositeOperation = 'lighter'; - // draw triangles!! - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - for (var i=1; i < length-2; i++) - { - - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; - var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height; - - - context.save(); - context.beginPath(); - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - context.closePath(); - - // context.fillStyle = "white"//rgb(1, 1, 1,1)); - // context.fill(); - context.clip(); - - - // Compute matrix transform - var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2; - var delta_a = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2; - var delta_b = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2; - var delta_c = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2; - var delta_d = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2; - var delta_e = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2; - var delta_f = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2; - - - - - context.transform(delta_a/delta, delta_d/delta, - delta_b/delta, delta_e/delta, - delta_c/delta, delta_f/delta); - - context.drawImage(strip.texture.baseTexture.source, 0, 0); - context.restore(); - }; - -// context.globalCompositeOperation = 'source-over'; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * A set of functions used by the canvas renderer to draw the primitive graphics data - * - * @class CanvasGraphics - */ -PIXI.CanvasGraphics = function() -{ - -} - - -/* - * Renders the graphics object - * - * @static - * @private - * @method renderGraphics - * @param graphics {Graphics} - * @param context {Context2D} - */ -PIXI.CanvasGraphics.renderGraphics = function(graphics, context) -{ - var worldAlpha = graphics.worldAlpha; - - for (var i=0; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - var points = data.points; - - context.strokeStyle = color = '#' + ('00000' + ( data.lineColor | 0).toString(16)).substr(-6); - - context.lineWidth = data.lineWidth; - - if(data.type == PIXI.Graphics.POLY) - { - //if(data.lineWidth <= 0)continue; - - context.beginPath(); - - context.moveTo(points[0], points[1]); - - for (var j=1; j < points.length/2; j++) - { - context.lineTo(points[j * 2], points[j * 2 + 1]); - } - - // if the first and last point are the same close the path - much neater :) - if(points[0] == points[points.length-2] && points[1] == points[points.length-1]) - { - context.closePath(); - } - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - else if(data.type == PIXI.Graphics.RECT) - { - - // TODO - need to be Undefined! - if(data.fillColor) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fillRect(points[0], points[1], points[2], points[3]); - - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.strokeRect(points[0], points[1], points[2], points[3]); - } - - } - else if(data.type == PIXI.Graphics.CIRC) - { - // TODO - need to be Undefined! - context.beginPath(); - context.arc(points[0], points[1], points[2],0,2*Math.PI); - context.closePath(); - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - else if(data.type == PIXI.Graphics.ELIP) - { - - // elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - - var elipseData = data.points; - - var w = elipseData[2] * 2; - var h = elipseData[3] * 2; - - var x = elipseData[0] - w/2; - var y = elipseData[1] - h/2; - - context.beginPath(); - - var kappa = .5522848, - ox = (w / 2) * kappa, // control point offset horizontal - oy = (h / 2) * kappa, // control point offset vertical - xe = x + w, // x-end - ye = y + h, // y-end - xm = x + w / 2, // x-middle - ym = y + h / 2; // y-middle - - context.moveTo(x, ym); - context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - - context.closePath(); - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - - }; -} - -/* - * Renders a graphics mask - * - * @static - * @private - * @method renderGraphicsMask - * @param graphics {Graphics} - * @param context {Context2D} - */ -PIXI.CanvasGraphics.renderGraphicsMask = function(graphics, context) -{ - var worldAlpha = graphics.worldAlpha; - - var len = graphics.graphicsData.length; - if(len > 1) - { - len = 1; - console.log("Pixi.js warning: masks in canvas can only mask using the first path in the graphics object") - } - - for (var i=0; i < 1; i++) - { - var data = graphics.graphicsData[i]; - var points = data.points; - - if(data.type == PIXI.Graphics.POLY) - { - //if(data.lineWidth <= 0)continue; - - context.beginPath(); - context.moveTo(points[0], points[1]); - - for (var j=1; j < points.length/2; j++) - { - context.lineTo(points[j * 2], points[j * 2 + 1]); - } - - // if the first and last point are the same close the path - much neater :) - if(points[0] == points[points.length-2] && points[1] == points[points.length-1]) - { - context.closePath(); - } - - } - else if(data.type == PIXI.Graphics.RECT) - { - context.beginPath(); - context.rect(points[0], points[1], points[2], points[3]); - context.closePath(); - } - else if(data.type == PIXI.Graphics.CIRC) - { - // TODO - need to be Undefined! - context.beginPath(); - context.arc(points[0], points[1], points[2],0,2*Math.PI); - context.closePath(); - } - else if(data.type == PIXI.Graphics.ELIP) - { - - // elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - var elipseData = data.points; - - var w = elipseData[2] * 2; - var h = elipseData[3] * 2; - - var x = elipseData[0] - w/2; - var y = elipseData[1] - h/2; - - context.beginPath(); - - var kappa = .5522848, - ox = (w / 2) * kappa, // control point offset horizontal - oy = (h / 2) * kappa, // control point offset vertical - xe = x + w, // x-end - ye = y + h, // y-end - xm = x + w / 2, // x-middle - ym = y + h / 2; // y-middle - - context.moveTo(x, ym); - context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - context.closePath(); - } - - - }; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * The Graphics class contains a set of methods that you can use to create primitive shapes and lines. - * It is important to know that with the webGL renderer only simple polys can be filled at this stage - * Complex polys will not be filled. Heres an example of a complex poly: http://www.goodboydigital.com/wp-content/uploads/2013/06/complexPolygon.png - * - * @class Graphics - * @extends DisplayObjectContainer - * @constructor - */ -PIXI.Graphics = function() -{ - PIXI.DisplayObjectContainer.call( this ); - - this.renderable = true; - - /** - * The alpha of the fill of this graphics object - * - * @property fillAlpha - * @type Number - */ - this.fillAlpha = 1; - - /** - * The width of any lines drawn - * - * @property lineWidth - * @type Number - */ - this.lineWidth = 0; - - /** - * The color of any lines drawn - * - * @property lineColor - * @type String - */ - this.lineColor = "black"; - - /** - * Graphics data - * - * @property graphicsData - * @type Array - * @private - */ - this.graphicsData = []; - - /** - * Current path - * - * @property currentPath - * @type Object - * @private - */ - this.currentPath = {points:[]}; -} - -// constructor -PIXI.Graphics.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Graphics.prototype.constructor = PIXI.Graphics; - -/** - * Specifies a line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method. - * - * @method lineStyle - * @param lineWidth {Number} width of the line to draw, will update the object's stored style - * @param color {Number} color of the line to draw, will update the object's stored style - * @param alpha {Number} alpha of the line to draw, will update the object's stored style - */ -PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.lineWidth = lineWidth || 0; - this.lineColor = color || 0; - this.lineAlpha = (alpha == undefined) ? 1 : alpha; - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; - - this.graphicsData.push(this.currentPath); -} - -/** - * Moves the current drawing position to (x, y). - * - * @method moveTo - * @param x {Number} the X coord to move to - * @param y {Number} the Y coord to move to - */ -PIXI.Graphics.prototype.moveTo = function(x, y) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; - - this.currentPath.points.push(x, y); - - this.graphicsData.push(this.currentPath); -} - -/** - * Draws a line using the current line style from the current drawing position to (x, y); - * the current drawing position is then set to (x, y). - * - * @method lineTo - * @param x {Number} the X coord to draw to - * @param y {Number} the Y coord to draw to - */ -PIXI.Graphics.prototype.lineTo = function(x, y) -{ - this.currentPath.points.push(x, y); - this.dirty = true; -} - -/** - * Specifies a simple one-color fill that subsequent calls to other Graphics methods - * (such as lineTo() or drawCircle()) use when drawing. - * - * @method beginFill - * @param color {uint} the color of the fill - * @param alpha {Number} the alpha - */ -PIXI.Graphics.prototype.beginFill = function(color, alpha) -{ - this.filling = true; - this.fillColor = color || 0; - this.fillAlpha = alpha || 1; -} - -/** - * Applies a fill to the lines and shapes that were added since the last call to the beginFill() method. - * - * @method endFill - */ -PIXI.Graphics.prototype.endFill = function() -{ - this.filling = false; - this.fillColor = null; - this.fillAlpha = 1; -} - -/** - * @method drawRect - * - * @param x {Number} The X coord of the top-left of the rectangle - * @param y {Number} The Y coord of the top-left of the rectangle - * @param width {Number} The width of the rectangle - * @param height {Number} The height of the rectangle - */ -PIXI.Graphics.prototype.drawRect = function( x, y, width, height ) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, width, height], type:PIXI.Graphics.RECT}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Draws a circle. - * - * @method drawCircle - * @param x {Number} The X coord of the center of the circle - * @param y {Number} The Y coord of the center of the circle - * @param radius {Number} The radius of the circle - */ -PIXI.Graphics.prototype.drawCircle = function( x, y, radius) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, radius, radius], type:PIXI.Graphics.CIRC}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Draws an elipse. - * - * @method drawElipse - * @param x {Number} - * @param y {Number} - * @param width {Number} - * @param height {Number} - */ -PIXI.Graphics.prototype.drawElipse = function( x, y, width, height) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, width, height], type:PIXI.Graphics.ELIP}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings. - * - * @method clear - */ -PIXI.Graphics.prototype.clear = function() -{ - this.lineWidth = 0; - this.filling = false; - - this.dirty = true; - this.clearDirty = true; - this.graphicsData = []; -} - -// SOME TYPES: -PIXI.Graphics.POLY = 0; -PIXI.Graphics.RECT = 1; -PIXI.Graphics.CIRC = 2; -PIXI.Graphics.ELIP = 3; - -/** - * @author Mat Groves http://matgroves.com/ - */ - -PIXI.Strip = function(texture, width, height) -{ - PIXI.DisplayObjectContainer.call( this ); - this.texture = texture; - this.blendMode = PIXI.blendModes.NORMAL; - - try - { - this.uvs = new Float32Array([0, 1, - 1, 1, - 1, 0, 0,1]); - - this.verticies = new Float32Array([0, 0, - 0,0, - 0,0, 0, - 0, 0]); - - this.colors = new Float32Array([1, 1, 1, 1]); - - this.indices = new Uint16Array([0, 1, 2, 3]); - } - catch(error) - { - this.uvs = [0, 1, - 1, 1, - 1, 0, 0,1]; - - this.verticies = [0, 0, - 0,0, - 0,0, 0, - 0, 0]; - - this.colors = [1, 1, 1, 1]; - - this.indices = [0, 1, 2, 3]; - } - - - /* - this.uvs = new Float32Array() - this.verticies = new Float32Array() - this.colors = new Float32Array() - this.indices = new Uint16Array() -*/ - this.width = width; - this.height = height; - - // load the texture! - if(texture.baseTexture.hasLoaded) - { - this.width = this.texture.frame.width; - this.height = this.texture.frame.height; - this.updateFrame = true; - } - else - { - this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); - } - - this.renderable = true; -} - -// constructor -PIXI.Strip.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Strip.prototype.constructor = PIXI.Strip; - -PIXI.Strip.prototype.setTexture = function(texture) -{ - //TODO SET THE TEXTURES - //TODO VISIBILITY - - // stop current texture - this.texture = texture; - this.width = texture.frame.width; - this.height = texture.frame.height; - this.updateFrame = true; -} - -PIXI.Strip.prototype.onTextureUpdate = function(event) -{ - this.updateFrame = true; -} -// some helper functions.. - - -/** - * @author Mat Groves http://matgroves.com/ - */ - - -PIXI.Rope = function(texture, points) -{ - PIXI.Strip.call( this, texture ); - this.points = points; - - try - { - this.verticies = new Float32Array( points.length * 4); - this.uvs = new Float32Array( points.length * 4); - this.colors = new Float32Array( points.length * 2); - this.indices = new Uint16Array( points.length * 2); - } - catch(error) - { - this.verticies = verticies - - this.uvs = uvs - this.colors = colors - this.indices = indices - } - - this.refresh(); -} - - -// constructor -PIXI.Rope.prototype = Object.create( PIXI.Strip.prototype ); -PIXI.Rope.prototype.constructor = PIXI.Rope; - -PIXI.Rope.prototype.refresh = function() -{ - var points = this.points; - if(points.length < 1)return; - - var uvs = this.uvs - var indices = this.indices; - var colors = this.colors; - - var lastPoint = points[0]; - var nextPoint; - var perp = {x:0, y:0}; - var point = points[0]; - - this.count-=0.2; - - - uvs[0] = 0 - uvs[1] = 1 - uvs[2] = 0 - uvs[3] = 1 - - colors[0] = 1; - colors[1] = 1; - - indices[0] = 0; - indices[1] = 1; - - var total = points.length; - - for (var i = 1; i < total; i++) - { - - var point = points[i]; - var index = i * 4; - // time to do some smart drawing! - var amount = i/(total-1) - - if(i%2) - { - uvs[index] = amount; - uvs[index+1] = 0; - - uvs[index+2] = amount - uvs[index+3] = 1 - - } - else - { - uvs[index] = amount - uvs[index+1] = 0 - - uvs[index+2] = amount - uvs[index+3] = 1 - } - - index = i * 2; - colors[index] = 1; - colors[index+1] = 1; - - index = i * 2; - indices[index] = index; - indices[index + 1] = index + 1; - - lastPoint = point; - } -} - -PIXI.Rope.prototype.updateTransform = function() -{ - - var points = this.points; - if(points.length < 1)return; - - var verticies = this.verticies - - var lastPoint = points[0]; - var nextPoint; - var perp = {x:0, y:0}; - var point = points[0]; - - this.count-=0.2; - - verticies[0] = point.x + perp.x - verticies[1] = point.y + perp.y //+ 200 - verticies[2] = point.x - perp.x - verticies[3] = point.y - perp.y//+200 - // time to do some smart drawing! - - var total = points.length; - - for (var i = 1; i < total; i++) - { - - var point = points[i]; - var index = i * 4; - - if(i < points.length-1) - { - nextPoint = points[i+1]; - } - else - { - nextPoint = point - } - - perp.y = -(nextPoint.x - lastPoint.x); - perp.x = nextPoint.y - lastPoint.y; - - var ratio = (1 - (i / (total-1))) * 10; - if(ratio > 1)ratio = 1; - - var perpLength = Math.sqrt(perp.x * perp.x + perp.y * perp.y); - var num = this.texture.height/2//(20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio; - perp.x /= perpLength; - perp.y /= perpLength; - - perp.x *= num; - perp.y *= num; - - verticies[index] = point.x + perp.x - verticies[index+1] = point.y + perp.y - verticies[index+2] = point.x - perp.x - verticies[index+3] = point.y - perp.y - - lastPoint = point; - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call( this ); -} - -PIXI.Rope.prototype.setTexture = function(texture) -{ - // stop current texture - this.texture = texture; - this.updateFrame = true; -} - - - - - -/** - * @author Mat Groves http://matgroves.com/ - */ - -/** - * A tiling sprite is a fast way of rendering a tiling image - * - * @class TilingSprite - * @extends DisplayObjectContainer - * @constructor - * @param texture {Texture} the texture of the tiling sprite - * @param width {Number} the width of the tiling sprite - * @param height {Number} the height of the tiling sprite - */ -PIXI.TilingSprite = function(texture, width, height) -{ - PIXI.DisplayObjectContainer.call( this ); - - /** - * The texture that the sprite is using - * - * @property texture - * @type Texture - */ - this.texture = texture; - - /** - * The width of the tiling sprite - * - * @property width - * @type Number - */ - this.width = width; - - /** - * The height of the tiling sprite - * - * @property height - * @type Number - */ - this.height = height; - - /** - * The scaling of the image that is being tiled - * - * @property tileScale - * @type Point - */ - this.tileScale = new PIXI.Point(1,1); - - /** - * The offset position of the image that is being tiled - * - * @property tilePosition - * @type Point - */ - this.tilePosition = new PIXI.Point(0,0); - - this.renderable = true; - - this.blendMode = PIXI.blendModes.NORMAL -} - -// constructor -PIXI.TilingSprite.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.TilingSprite.prototype.constructor = PIXI.TilingSprite; - -/** - * Sets the texture of the tiling sprite - * - * @method setTexture - * @param texture {Texture} The PIXI texture that is displayed by the sprite - */ -PIXI.TilingSprite.prototype.setTexture = function(texture) -{ - //TODO SET THE TEXTURES - //TODO VISIBILITY - - // stop current texture - this.texture = texture; - this.updateFrame = true; -} - -/** - * When the texture is updated, this event will fire to update the frame - * - * @method onTextureUpdate - * @param event - * @private - */ -PIXI.TilingSprite.prototype.onTextureUpdate = function(event) -{ - this.updateFrame = true; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi - * - * Awesome JS run time provided by EsotericSoftware - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -/** - * A class that enables the you to import and run your spine animations in pixi. - * Spine animation data needs to be loaded using the PIXI.AssetLoader or PIXI.SpineLoader before it can be used by this class - * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source - * - * @class Spine - * @extends DisplayObjectContainer - * @constructor - * @param url {String} The url of the spine anim file to be used - */ -PIXI.Spine = function(url) -{ - PIXI.DisplayObjectContainer.call(this); - - this.spineData = PIXI.AnimCache[url]; - - if(!this.spineData) - { - throw new Error("Spine data must be preloaded using PIXI.SpineLoader or PIXI.AssetLoader: " + url); - return; - } - - this.count = 0; - - this.sprites = []; - - this.skeleton = new spine.Skeleton(this.spineData); - this.skeleton.updateWorldTransform(); - - this.stateData = new spine.AnimationStateData(this.spineData); - this.state = new spine.AnimationState(this.stateData); - - // add the sprites.. - for (var i = 0; i < this.skeleton.drawOrder.length; i++) { - - var attachmentName = this.skeleton.drawOrder[i].data.attachmentName; - - // kind of an assumtion here. that its a png - if(!PIXI.TextureCache[attachmentName]) - { - attachmentName += ".png"; - } - - - var sprite = new PIXI.Sprite(PIXI.Texture.fromFrame(attachmentName)); - sprite.anchor.x = sprite.anchor.y = 0.5; - this.addChild(sprite); - this.sprites.push(sprite); - }; -} - -PIXI.Spine.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Spine.prototype.constructor = PIXI.Spine; - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.Spine.prototype.updateTransform = function() -{ - // TODO should make this time based really.. - this.state.update(1/60); - this.state.apply(this.skeleton); - this.skeleton.updateWorldTransform(); - - - for (var i = 0; i < this.skeleton.drawOrder.length; i++) - { - var slot = this.skeleton.drawOrder[i]; - - var x = slot.bone.worldX + slot.attachment.x * slot.bone.m00 + slot.attachment.y * slot.bone.m01 + slot.attachment.width * 0.5; - var y = slot.bone.worldY + slot.attachment.x * slot.bone.m10 + slot.attachment.y * slot.bone.m11 + slot.attachment.height * 0.5; - //console.log(x + ' : ' + y); - - - //console.log(slot.attachment.name) - if(slot.cacheName != slot.attachment.name) - { - var attachmentName = slot.attachment.name; - - if(!PIXI.TextureCache[attachmentName]) - { - attachmentName += ".png"; - } - - this.sprites[i].setTexture(PIXI.TextureCache[attachmentName]); - - slot.cacheName = slot.attachment.name; - } - - x += -((slot.attachment.width * (slot.bone.worldScaleX + slot.attachment.scaleX - 1))>>1); - y += -((slot.attachment.height * (slot.bone.worldScaleY + slot.attachment.scaleY - 1))>>1); - - - this.sprites[i].position.x = x; - this.sprites[i].position.y = y; - this.sprites[i].rotation = (-(slot.bone.worldRotation + slot.attachment.rotation)) * (Math.PI/180); - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call(this); -} - -/* - * Awesome JS run time provided by EsotericSoftware - * - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -var spine = {}; - -spine.BoneData = function (name, parent) { - this.name = name; - this.parent = parent; -}; -spine.BoneData.prototype = { - length: 0, - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1 -}; - -spine.SlotData = function (name, boneData) { - this.name = name; - this.boneData = boneData; -}; -spine.SlotData.prototype = { - r: 1, g: 1, b: 1, a: 1, - attachmentName: null -}; - -spine.Bone = function (boneData, parent) { - this.data = boneData; - this.parent = parent; - this.setToSetupPose(); -}; -spine.Bone.yDown = false; -spine.Bone.prototype = { - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1, - m00: 0, m01: 0, worldX: 0, // a b x - m10: 0, m11: 0, worldY: 0, // c d y - worldRotation: 0, - worldScaleX: 1, worldScaleY: 1, - updateWorldTransform: function (flipX, flipY) { - var parent = this.parent; - if (parent != null) { - this.worldX = this.x * parent.m00 + this.y * parent.m01 + parent.worldX; - this.worldY = this.x * parent.m10 + this.y * parent.m11 + parent.worldY; - this.worldScaleX = parent.worldScaleX * this.scaleX; - this.worldScaleY = parent.worldScaleY * this.scaleY; - this.worldRotation = parent.worldRotation + this.rotation; - } else { - this.worldX = this.x; - this.worldY = this.y; - this.worldScaleX = this.scaleX; - this.worldScaleY = this.scaleY; - this.worldRotation = this.rotation; - } - var radians = this.worldRotation * Math.PI / 180; - var cos = Math.cos(radians); - var sin = Math.sin(radians); - this.m00 = cos * this.worldScaleX; - this.m10 = sin * this.worldScaleX; - this.m01 = -sin * this.worldScaleY; - this.m11 = cos * this.worldScaleY; - if (flipX) { - this.m00 = -this.m00; - this.m01 = -this.m01; - } - if (flipY) { - this.m10 = -this.m10; - this.m11 = -this.m11; - } - if (spine.Bone.yDown) { - this.m10 = -this.m10; - this.m11 = -this.m11; - } - }, - setToSetupPose: function () { - var data = this.data; - this.x = data.x; - this.y = data.y; - this.rotation = data.rotation; - this.scaleX = data.scaleX; - this.scaleY = data.scaleY; - } -}; - -spine.Slot = function (slotData, skeleton, bone) { - this.data = slotData; - this.skeleton = skeleton; - this.bone = bone; - this.setToSetupPose(); -}; -spine.Slot.prototype = { - r: 1, g: 1, b: 1, a: 1, - _attachmentTime: 0, - attachment: null, - setAttachment: function (attachment) { - this.attachment = attachment; - this._attachmentTime = this.skeleton.time; - }, - setAttachmentTime: function (time) { - this._attachmentTime = this.skeleton.time - time; - }, - getAttachmentTime: function () { - return this.skeleton.time - this._attachmentTime; - }, - setToSetupPose: function () { - var data = this.data; - this.r = data.r; - this.g = data.g; - this.b = data.b; - this.a = data.a; - - var slotDatas = this.skeleton.data.slots; - for (var i = 0, n = slotDatas.length; i < n; i++) { - if (slotDatas[i] == data) { - this.setAttachment(!data.attachmentName ? null : this.skeleton.getAttachmentBySlotIndex(i, data.attachmentName)); - break; - } - } - } -}; - -spine.Skin = function (name) { - this.name = name; - this.attachments = {}; -}; -spine.Skin.prototype = { - addAttachment: function (slotIndex, name, attachment) { - this.attachments[slotIndex + ":" + name] = attachment; - }, - getAttachment: function (slotIndex, name) { - return this.attachments[slotIndex + ":" + name]; - }, - _attachAll: function (skeleton, oldSkin) { - for (var key in oldSkin.attachments) { - var colon = key.indexOf(":"); - var slotIndex = parseInt(key.substring(0, colon)); - var name = key.substring(colon + 1); - var slot = skeleton.slots[slotIndex]; - if (slot.attachment && slot.attachment.name == name) { - var attachment = this.getAttachment(slotIndex, name); - if (attachment) slot.setAttachment(attachment); - } - } - } -}; - -spine.Animation = function (name, timelines, duration) { - this.name = name; - this.timelines = timelines; - this.duration = duration; -}; -spine.Animation.prototype = { - apply: function (skeleton, time, loop) { - if (loop && this.duration != 0) time %= this.duration; - var timelines = this.timelines; - for (var i = 0, n = timelines.length; i < n; i++) - timelines[i].apply(skeleton, time, 1); - }, - mix: function (skeleton, time, loop, alpha) { - if (loop && this.duration != 0) time %= this.duration; - var timelines = this.timelines; - for (var i = 0, n = timelines.length; i < n; i++) - timelines[i].apply(skeleton, time, alpha); - } -}; - -spine.binarySearch = function (values, target, step) { - var low = 0; - var high = Math.floor(values.length / step) - 2; - if (high == 0) return step; - var current = high >>> 1; - while (true) { - if (values[(current + 1) * step] <= target) - low = current + 1; - else - high = current; - if (low == high) return (low + 1) * step; - current = (low + high) >>> 1; - } -}; -spine.linearSearch = function (values, target, step) { - for (var i = 0, last = values.length - step; i <= last; i += step) - if (values[i] > target) return i; - return -1; -}; - -spine.Curves = function (frameCount) { - this.curves = []; // dfx, dfy, ddfx, ddfy, dddfx, dddfy, ... - this.curves.length = (frameCount - 1) * 6; -}; -spine.Curves.prototype = { - setLinear: function (frameIndex) { - this.curves[frameIndex * 6] = 0/*LINEAR*/; - }, - setStepped: function (frameIndex) { - this.curves[frameIndex * 6] = -1/*STEPPED*/; - }, - /** Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next. - * cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of - * the difference between the keyframe's values. */ - setCurve: function (frameIndex, cx1, cy1, cx2, cy2) { - var subdiv_step = 1 / 10/*BEZIER_SEGMENTS*/; - var subdiv_step2 = subdiv_step * subdiv_step; - var subdiv_step3 = subdiv_step2 * subdiv_step; - var pre1 = 3 * subdiv_step; - var pre2 = 3 * subdiv_step2; - var pre4 = 6 * subdiv_step2; - var pre5 = 6 * subdiv_step3; - var tmp1x = -cx1 * 2 + cx2; - var tmp1y = -cy1 * 2 + cy2; - var tmp2x = (cx1 - cx2) * 3 + 1; - var tmp2y = (cy1 - cy2) * 3 + 1; - var i = frameIndex * 6; - var curves = this.curves; - curves[i] = cx1 * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3; - curves[i + 1] = cy1 * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3; - curves[i + 2] = tmp1x * pre4 + tmp2x * pre5; - curves[i + 3] = tmp1y * pre4 + tmp2y * pre5; - curves[i + 4] = tmp2x * pre5; - curves[i + 5] = tmp2y * pre5; - }, - getCurvePercent: function (frameIndex, percent) { - percent = percent < 0 ? 0 : (percent > 1 ? 1 : percent); - var curveIndex = frameIndex * 6; - var curves = this.curves; - var dfx = curves[curveIndex]; - if (!dfx/*LINEAR*/) return percent; - if (dfx == -1/*STEPPED*/) return 0; - var dfy = curves[curveIndex + 1]; - var ddfx = curves[curveIndex + 2]; - var ddfy = curves[curveIndex + 3]; - var dddfx = curves[curveIndex + 4]; - var dddfy = curves[curveIndex + 5]; - var x = dfx, y = dfy; - var i = 10/*BEZIER_SEGMENTS*/ - 2; - while (true) { - if (x >= percent) { - var lastX = x - dfx; - var lastY = y - dfy; - return lastY + (y - lastY) * (percent - lastX) / (x - lastX); - } - if (i == 0) break; - i--; - dfx += ddfx; - dfy += ddfy; - ddfx += dddfx; - ddfy += dddfy; - x += dfx; - y += dfy; - } - return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1. - } -}; - -spine.RotateTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, angle, ... - this.frames.length = frameCount * 2; -}; -spine.RotateTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, angle) { - frameIndex *= 2; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = angle; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 2]) { // Time is after last frame. - var amount = bone.data.rotation + frames[frames.length - 1] - bone.rotation; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - bone.rotation += amount * alpha; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 2); - var lastFrameValue = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex - 2/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 2 - 1, percent); - - var amount = frames[frameIndex + 1/*FRAME_VALUE*/] - lastFrameValue; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - amount = bone.data.rotation + (lastFrameValue + amount * percent) - bone.rotation; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - bone.rotation += amount * alpha; - } -}; - -spine.TranslateTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, x, y, ... - this.frames.length = frameCount * 3; -}; -spine.TranslateTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 3; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 3; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = x; - this.frames[frameIndex + 2] = y; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 3]) { // Time is after last frame. - bone.x += (bone.data.x + frames[frames.length - 2] - bone.x) * alpha; - bone.y += (bone.data.y + frames[frames.length - 1] - bone.y) * alpha; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 3); - var lastFrameX = frames[frameIndex - 2]; - var lastFrameY = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent); - bone.x += (bone.data.x + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.x) * alpha; - bone.y += (bone.data.y + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.y) * alpha; - } -}; - -spine.ScaleTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, x, y, ... - this.frames.length = frameCount * 3; -}; -spine.ScaleTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 3; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 3; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = x; - this.frames[frameIndex + 2] = y; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 3]) { // Time is after last frame. - bone.scaleX += (bone.data.scaleX - 1 + frames[frames.length - 2] - bone.scaleX) * alpha; - bone.scaleY += (bone.data.scaleY - 1 + frames[frames.length - 1] - bone.scaleY) * alpha; - - - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 3); - var lastFrameX = frames[frameIndex - 2]; - var lastFrameY = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent); - - bone.scaleX += (bone.data.scaleX - 1 + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.scaleX) * alpha; - bone.scaleY += (bone.data.scaleY - 1 + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.scaleY) * alpha; - } -}; - -spine.ColorTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, r, g, b, a, ... - this.frames.length = frameCount * 5; -}; -spine.ColorTimeline.prototype = { - slotIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 5; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = r; - this.frames[frameIndex + 2] = g; - this.frames[frameIndex + 3] = b; - this.frames[frameIndex + 4] = a; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - var slot = skeleton.slots[this.slotIndex]; - - if (time >= frames[frames.length - 5]) { // Time is after last frame. - var i = frames.length - 1; - slot.r = frames[i - 3]; - slot.g = frames[i - 2]; - slot.b = frames[i - 1]; - slot.a = frames[i]; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 5); - var lastFrameR = frames[frameIndex - 4]; - var lastFrameG = frames[frameIndex - 3]; - var lastFrameB = frames[frameIndex - 2]; - var lastFrameA = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex - 5/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 5 - 1, percent); - - var r = lastFrameR + (frames[frameIndex + 1/*FRAME_R*/] - lastFrameR) * percent; - var g = lastFrameG + (frames[frameIndex + 2/*FRAME_G*/] - lastFrameG) * percent; - var b = lastFrameB + (frames[frameIndex + 3/*FRAME_B*/] - lastFrameB) * percent; - var a = lastFrameA + (frames[frameIndex + 4/*FRAME_A*/] - lastFrameA) * percent; - if (alpha < 1) { - slot.r += (r - slot.r) * alpha; - slot.g += (g - slot.g) * alpha; - slot.b += (b - slot.b) * alpha; - slot.a += (a - slot.a) * alpha; - } else { - slot.r = r; - slot.g = g; - slot.b = b; - slot.a = a; - } - } -}; - -spine.AttachmentTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, ... - this.frames.length = frameCount; - this.attachmentNames = []; // time, ... - this.attachmentNames.length = frameCount; -}; -spine.AttachmentTimeline.prototype = { - slotIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, attachmentName) { - this.frames[frameIndex] = time; - this.attachmentNames[frameIndex] = attachmentName; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var frameIndex; - if (time >= frames[frames.length - 1]) // Time is after last frame. - frameIndex = frames.length - 1; - else - frameIndex = spine.binarySearch(frames, time, 1) - 1; - - var attachmentName = this.attachmentNames[frameIndex]; - //console.log(skeleton.slots[this.slotIndex]) - - // change the name! - // skeleton.slots[this.slotIndex].attachmentName = attachmentName; - - skeleton.slots[this.slotIndex].setAttachment(!attachmentName ? null : skeleton.getAttachmentBySlotIndex(this.slotIndex, attachmentName)); - } -}; - -spine.SkeletonData = function () { - this.bones = []; - this.slots = []; - this.skins = []; - this.animations = []; -}; -spine.SkeletonData.prototype = { - defaultSkin: null, - /** @return May be null. */ - findBone: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].name == boneName) return bones[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findBoneIndex: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].name == boneName) return i; - return -1; - }, - /** @return May be null. */ - findSlot: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) { - if (slots[i].name == slotName) return slot[i]; - } - return null; - }, - /** @return -1 if the bone was not found. */ - findSlotIndex: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].name == slotName) return i; - return -1; - }, - /** @return May be null. */ - findSkin: function (skinName) { - var skins = this.skins; - for (var i = 0, n = skins.length; i < n; i++) - if (skins[i].name == skinName) return skins[i]; - return null; - }, - /** @return May be null. */ - findAnimation: function (animationName) { - var animations = this.animations; - for (var i = 0, n = animations.length; i < n; i++) - if (animations[i].name == animationName) return animations[i]; - return null; - } -}; - -spine.Skeleton = function (skeletonData) { - this.data = skeletonData; - - this.bones = []; - for (var i = 0, n = skeletonData.bones.length; i < n; i++) { - var boneData = skeletonData.bones[i]; - var parent = !boneData.parent ? null : this.bones[skeletonData.bones.indexOf(boneData.parent)]; - this.bones.push(new spine.Bone(boneData, parent)); - } - - this.slots = []; - this.drawOrder = []; - for (var i = 0, n = skeletonData.slots.length; i < n; i++) { - var slotData = skeletonData.slots[i]; - var bone = this.bones[skeletonData.bones.indexOf(slotData.boneData)]; - var slot = new spine.Slot(slotData, this, bone); - this.slots.push(slot); - this.drawOrder.push(slot); - } -}; -spine.Skeleton.prototype = { - x: 0, y: 0, - skin: null, - r: 1, g: 1, b: 1, a: 1, - time: 0, - flipX: false, flipY: false, - /** Updates the world transform for each bone. */ - updateWorldTransform: function () { - var flipX = this.flipX; - var flipY = this.flipY; - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - bones[i].updateWorldTransform(flipX, flipY); - }, - /** Sets the bones and slots to their setup pose values. */ - setToSetupPose: function () { - this.setBonesToSetupPose(); - this.setSlotsToSetupPose(); - }, - setBonesToSetupPose: function () { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - bones[i].setToSetupPose(); - }, - setSlotsToSetupPose: function () { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - slots[i].setToSetupPose(i); - }, - /** @return May return null. */ - getRootBone: function () { - return this.bones.length == 0 ? null : this.bones[0]; - }, - /** @return May be null. */ - findBone: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].data.name == boneName) return bones[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findBoneIndex: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].data.name == boneName) return i; - return -1; - }, - /** @return May be null. */ - findSlot: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].data.name == slotName) return slots[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findSlotIndex: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].data.name == slotName) return i; - return -1; - }, - setSkinByName: function (skinName) { - var skin = this.data.findSkin(skinName); - if (!skin) throw "Skin not found: " + skinName; - this.setSkin(skin); - }, - /** Sets the skin used to look up attachments not found in the {@link SkeletonData#getDefaultSkin() default skin}. Attachments - * from the new skin are attached if the corresponding attachment from the old skin was attached. - * @param newSkin May be null. */ - setSkin: function (newSkin) { - if (this.skin && newSkin) newSkin._attachAll(this, this.skin); - this.skin = newSkin; - }, - /** @return May be null. */ - getAttachmentBySlotName: function (slotName, attachmentName) { - return this.getAttachmentBySlotIndex(this.data.findSlotIndex(slotName), attachmentName); - }, - /** @return May be null. */ - getAttachmentBySlotIndex: function (slotIndex, attachmentName) { - if (this.skin) { - var attachment = this.skin.getAttachment(slotIndex, attachmentName); - if (attachment) return attachment; - } - if (this.data.defaultSkin) return this.data.defaultSkin.getAttachment(slotIndex, attachmentName); - return null; - }, - /** @param attachmentName May be null. */ - setAttachment: function (slotName, attachmentName) { - var slots = this.slots; - for (var i = 0, n = slots.size; i < n; i++) { - var slot = slots[i]; - if (slot.data.name == slotName) { - var attachment = null; - if (attachmentName) { - - attachment = this.getAttachment(i, attachmentName); - if (attachment == null) throw "Attachment not found: " + attachmentName + ", for slot: " + slotName; - } - - slot.setAttachment(attachment); - return; - } - } - throw "Slot not found: " + slotName; - }, - update: function (delta) { - time += delta; - } -}; - -spine.AttachmentType = { - region: 0 -}; - -spine.RegionAttachment = function () { - this.offset = []; - this.offset.length = 8; - this.uvs = []; - this.uvs.length = 8; -}; -spine.RegionAttachment.prototype = { - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1, - width: 0, height: 0, - rendererObject: null, - regionOffsetX: 0, regionOffsetY: 0, - regionWidth: 0, regionHeight: 0, - regionOriginalWidth: 0, regionOriginalHeight: 0, - setUVs: function (u, v, u2, v2, rotate) { - var uvs = this.uvs; - if (rotate) { - uvs[2/*X2*/] = u; - uvs[3/*Y2*/] = v2; - uvs[4/*X3*/] = u; - uvs[5/*Y3*/] = v; - uvs[6/*X4*/] = u2; - uvs[7/*Y4*/] = v; - uvs[0/*X1*/] = u2; - uvs[1/*Y1*/] = v2; - } else { - uvs[0/*X1*/] = u; - uvs[1/*Y1*/] = v2; - uvs[2/*X2*/] = u; - uvs[3/*Y2*/] = v; - uvs[4/*X3*/] = u2; - uvs[5/*Y3*/] = v; - uvs[6/*X4*/] = u2; - uvs[7/*Y4*/] = v2; - } - }, - updateOffset: function () { - var regionScaleX = this.width / this.regionOriginalWidth * this.scaleX; - var regionScaleY = this.height / this.regionOriginalHeight * this.scaleY; - var localX = -this.width / 2 * this.scaleX + this.regionOffsetX * regionScaleX; - var localY = -this.height / 2 * this.scaleY + this.regionOffsetY * regionScaleY; - var localX2 = localX + this.regionWidth * regionScaleX; - var localY2 = localY + this.regionHeight * regionScaleY; - var radians = this.rotation * Math.PI / 180; - var cos = Math.cos(radians); - var sin = Math.sin(radians); - var localXCos = localX * cos + this.x; - var localXSin = localX * sin; - var localYCos = localY * cos + this.y; - var localYSin = localY * sin; - var localX2Cos = localX2 * cos + this.x; - var localX2Sin = localX2 * sin; - var localY2Cos = localY2 * cos + this.y; - var localY2Sin = localY2 * sin; - var offset = this.offset; - offset[0/*X1*/] = localXCos - localYSin; - offset[1/*Y1*/] = localYCos + localXSin; - offset[2/*X2*/] = localXCos - localY2Sin; - offset[3/*Y2*/] = localY2Cos + localXSin; - offset[4/*X3*/] = localX2Cos - localY2Sin; - offset[5/*Y3*/] = localY2Cos + localX2Sin; - offset[6/*X4*/] = localX2Cos - localYSin; - offset[7/*Y4*/] = localYCos + localX2Sin; - }, - computeVertices: function (x, y, bone, vertices) { - - x += bone.worldX; - y += bone.worldY; - var m00 = bone.m00; - var m01 = bone.m01; - var m10 = bone.m10; - var m11 = bone.m11; - var offset = this.offset; - vertices[0/*X1*/] = offset[0/*X1*/] * m00 + offset[1/*Y1*/] * m01 + x; - vertices[1/*Y1*/] = offset[0/*X1*/] * m10 + offset[1/*Y1*/] * m11 + y; - vertices[2/*X2*/] = offset[2/*X2*/] * m00 + offset[3/*Y2*/] * m01 + x; - vertices[3/*Y2*/] = offset[2/*X2*/] * m10 + offset[3/*Y2*/] * m11 + y; - vertices[4/*X3*/] = offset[4/*X3*/] * m00 + offset[5/*X3*/] * m01 + x; - vertices[5/*X3*/] = offset[4/*X3*/] * m10 + offset[5/*X3*/] * m11 + y; - vertices[6/*X4*/] = offset[6/*X4*/] * m00 + offset[7/*Y4*/] * m01 + x; - vertices[7/*Y4*/] = offset[6/*X4*/] * m10 + offset[7/*Y4*/] * m11 + y; - } -} - -spine.AnimationStateData = function (skeletonData) { - this.skeletonData = skeletonData; - this.animationToMixTime = {}; -}; -spine.AnimationStateData.prototype = { - setMixByName: function (fromName, toName, duration) { - var from = this.skeletonData.findAnimation(fromName); - if (!from) throw "Animation not found: " + fromName; - var to = this.skeletonData.findAnimation(toName); - if (!to) throw "Animation not found: " + toName; - this.setMix(from, to, duration); - }, - setMix: function (from, to, duration) { - this.animationToMixTime[from.name + ":" + to.name] = duration; - }, - getMix: function (from, to) { - var time = this.animationToMixTime[from.name + ":" + to.name]; - return time ? time : 0; - } -}; - -spine.AnimationState = function (stateData) { - this.data = stateData; - this.queue = []; -}; -spine.AnimationState.prototype = { - current: null, - previous: null, - currentTime: 0, - previousTime: 0, - currentLoop: false, - previousLoop: false, - mixTime: 0, - mixDuration: 0, - update: function (delta) { - this.currentTime += delta; - this.previousTime += delta; - this.mixTime += delta; - - if (this.queue.length > 0) { - var entry = this.queue[0]; - if (this.currentTime >= entry.delay) { - this._setAnimation(entry.animation, entry.loop); - this.queue.shift(); - } - } - }, - apply: function (skeleton) { - if (!this.current) return; - if (this.previous) { - this.previous.apply(skeleton, this.previousTime, this.previousLoop); - var alpha = this.mixTime / this.mixDuration; - if (alpha >= 1) { - alpha = 1; - this.previous = null; - } - this.current.mix(skeleton, this.currentTime, this.currentLoop, alpha); - } else - this.current.apply(skeleton, this.currentTime, this.currentLoop); - }, - clearAnimation: function () { - this.previous = null; - this.current = null; - this.queue.length = 0; - }, - _setAnimation: function (animation, loop) { - this.previous = null; - if (animation && this.current) { - this.mixDuration = this.data.getMix(this.current, animation); - if (this.mixDuration > 0) { - this.mixTime = 0; - this.previous = this.current; - this.previousTime = this.currentTime; - this.previousLoop = this.currentLoop; - } - } - this.current = animation; - this.currentLoop = loop; - this.currentTime = 0; - }, - /** @see #setAnimation(Animation, Boolean) */ - setAnimationByName: function (animationName, loop) { - var animation = this.data.skeletonData.findAnimation(animationName); - if (!animation) throw "Animation not found: " + animationName; - this.setAnimation(animation, loop); - }, - /** Set the current animation. Any queued animations are cleared and the current animation time is set to 0. - * @param animation May be null. */ - setAnimation: function (animation, loop) { - this.queue.length = 0; - this._setAnimation(animation, loop); - }, - /** @see #addAnimation(Animation, Boolean, Number) */ - addAnimationByName: function (animationName, loop, delay) { - var animation = this.data.skeletonData.findAnimation(animationName); - if (!animation) throw "Animation not found: " + animationName; - this.addAnimation(animation, loop, delay); - }, - /** Adds an animation to be played delay seconds after the current or last queued animation. - * @param delay May be <= 0 to use duration of previous animation minus any mix duration plus the negative delay. */ - addAnimation: function (animation, loop, delay) { - var entry = {}; - entry.animation = animation; - entry.loop = loop; - - if (!delay || delay <= 0) { - var previousAnimation = this.queue.length == 0 ? this.current : this.queue[this.queue.length - 1].animation; - if (previousAnimation != null) - delay = previousAnimation.duration - this.data.getMix(previousAnimation, animation) + (delay || 0); - else - delay = 0; - } - entry.delay = delay; - - this.queue.push(entry); - }, - /** Returns true if no animation is set or if the current time is greater than the animation duration, regardless of looping. */ - isComplete: function () { - return !this.current || this.currentTime >= this.current.duration; - } -}; - -spine.SkeletonJson = function (attachmentLoader) { - this.attachmentLoader = attachmentLoader; -}; -spine.SkeletonJson.prototype = { - scale: 1, - readSkeletonData: function (root) { - var skeletonData = new spine.SkeletonData(); - - // Bones. - var bones = root["bones"]; - for (var i = 0, n = bones.length; i < n; i++) { - var boneMap = bones[i]; - var parent = null; - if (boneMap["parent"]) { - parent = skeletonData.findBone(boneMap["parent"]); - if (!parent) throw "Parent bone not found: " + boneMap["parent"]; - } - var boneData = new spine.BoneData(boneMap["name"], parent); - boneData.length = (boneMap["length"] || 0) * this.scale; - boneData.x = (boneMap["x"] || 0) * this.scale; - boneData.y = (boneMap["y"] || 0) * this.scale; - boneData.rotation = (boneMap["rotation"] || 0); - boneData.scaleX = boneMap["scaleX"] || 1; - boneData.scaleY = boneMap["scaleY"] || 1; - skeletonData.bones.push(boneData); - } - - // Slots. - var slots = root["slots"]; - for (var i = 0, n = slots.length; i < n; i++) { - var slotMap = slots[i]; - var boneData = skeletonData.findBone(slotMap["bone"]); - if (!boneData) throw "Slot bone not found: " + slotMap["bone"]; - var slotData = new spine.SlotData(slotMap["name"], boneData); - - var color = slotMap["color"]; - if (color) { - slotData.r = spine.SkeletonJson.toColor(color, 0); - slotData.g = spine.SkeletonJson.toColor(color, 1); - slotData.b = spine.SkeletonJson.toColor(color, 2); - slotData.a = spine.SkeletonJson.toColor(color, 3); - } - - slotData.attachmentName = slotMap["attachment"]; - - skeletonData.slots.push(slotData); - } - - // Skins. - var skins = root["skins"]; - for (var skinName in skins) { - if (!skins.hasOwnProperty(skinName)) continue; - var skinMap = skins[skinName]; - var skin = new spine.Skin(skinName); - for (var slotName in skinMap) { - if (!skinMap.hasOwnProperty(slotName)) continue; - var slotIndex = skeletonData.findSlotIndex(slotName); - var slotEntry = skinMap[slotName]; - for (var attachmentName in slotEntry) { - if (!slotEntry.hasOwnProperty(attachmentName)) continue; - var attachment = this.readAttachment(skin, attachmentName, slotEntry[attachmentName]); - if (attachment != null) skin.addAttachment(slotIndex, attachmentName, attachment); - } - } - skeletonData.skins.push(skin); - if (skin.name == "default") skeletonData.defaultSkin = skin; - } - - // Animations. - var animations = root["animations"]; - for (var animationName in animations) { - if (!animations.hasOwnProperty(animationName)) continue; - this.readAnimation(animationName, animations[animationName], skeletonData); - } - - return skeletonData; - }, - readAttachment: function (skin, name, map) { - name = map["name"] || name; - - var type = spine.AttachmentType[map["type"] || "region"]; - - // @ekelokorpi - // var attachment = this.attachmentLoader.newAttachment(skin, type, name); - var attachment = new spine.RegionAttachment(); - - // @Doormat23 - // add the name of the attachment - attachment.name = name; - - if (type == spine.AttachmentType.region) { - attachment.x = (map["x"] || 0) * this.scale; - attachment.y = (map["y"] || 0) * this.scale; - attachment.scaleX = map["scaleX"] || 1; - attachment.scaleY = map["scaleY"] || 1; - attachment.rotation = map["rotation"] || 0; - attachment.width = (map["width"] || 32) * this.scale; - attachment.height = (map["height"] || 32) * this.scale; - attachment.updateOffset(); - } - - return attachment; - }, - readAnimation: function (name, map, skeletonData) { - var timelines = []; - var duration = 0; - - var bones = map["bones"]; - for (var boneName in bones) { - if (!bones.hasOwnProperty(boneName)) continue; - var boneIndex = skeletonData.findBoneIndex(boneName); - if (boneIndex == -1) throw "Bone not found: " + boneName; - var boneMap = bones[boneName]; - - for (var timelineName in boneMap) { - if (!boneMap.hasOwnProperty(timelineName)) continue; - var values = boneMap[timelineName]; - if (timelineName == "rotate") { - var timeline = new spine.RotateTimeline(values.length); - timeline.boneIndex = boneIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - timeline.setFrame(frameIndex, valueMap["time"], valueMap["angle"]); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 2 - 2]); - - } else if (timelineName == "translate" || timelineName == "scale") { - var timeline; - var timelineScale = 1; - if (timelineName == "scale") - timeline = new spine.ScaleTimeline(values.length); - else { - timeline = new spine.TranslateTimeline(values.length); - timelineScale = this.scale; - } - timeline.boneIndex = boneIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - var x = (valueMap["x"] || 0) * timelineScale; - var y = (valueMap["y"] || 0) * timelineScale; - timeline.setFrame(frameIndex, valueMap["time"], x, y); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 3 - 3]); - - } else - throw "Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")"; - } - } - var slots = map["slots"]; - for (var slotName in slots) { - if (!slots.hasOwnProperty(slotName)) continue; - var slotMap = slots[slotName]; - var slotIndex = skeletonData.findSlotIndex(slotName); - - for (var timelineName in slotMap) { - if (!slotMap.hasOwnProperty(timelineName)) continue; - var values = slotMap[timelineName]; - if (timelineName == "color") { - var timeline = new spine.ColorTimeline(values.length); - timeline.slotIndex = slotIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - var color = valueMap["color"]; - var r = spine.SkeletonJson.toColor(color, 0); - var g = spine.SkeletonJson.toColor(color, 1); - var b = spine.SkeletonJson.toColor(color, 2); - var a = spine.SkeletonJson.toColor(color, 3); - timeline.setFrame(frameIndex, valueMap["time"], r, g, b, a); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 5 - 5]); - - } else if (timelineName == "attachment") { - var timeline = new spine.AttachmentTimeline(values.length); - timeline.slotIndex = slotIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - timeline.setFrame(frameIndex++, valueMap["time"], valueMap["name"]); - } - timelines.push(timeline); - // PIXI FIX - duration = Math.max(duration, timeline.frames[Math.floor(timeline.getFrameCount()) - 1]); - } else - throw "Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")"; - } - } - skeletonData.animations.push(new spine.Animation(name, timelines, duration)); - } -}; -spine.SkeletonJson.readCurve = function (timeline, frameIndex, valueMap) { - var curve = valueMap["curve"]; - if (!curve) return; - if (curve == "stepped") - timeline.curves.setStepped(frameIndex); - else if (curve instanceof Array) - timeline.curves.setCurve(frameIndex, curve[0], curve[1], curve[2], curve[3]); -}; -spine.SkeletonJson.toColor = function (hexString, colorIndex) { - if (hexString.length != 8) throw "Color hexidecimal length must be 8, recieved: " + hexString; - return parseInt(hexString.substring(colorIndex * 2, 2), 16) / 255; -}; - -spine.Atlas = function (atlasText, textureLoader) { - this.textureLoader = textureLoader; - this.pages = []; - this.regions = []; - - var reader = new spine.AtlasReader(atlasText); - var tuple = []; - tuple.length = 4; - var page = null; - while (true) { - var line = reader.readLine(); - if (line == null) break; - line = reader.trim(line); - if (line.length == 0) - page = null; - else if (!page) { - page = new spine.AtlasPage(); - page.name = line; - - page.format = spine.Atlas.Format[reader.readValue()]; - - reader.readTuple(tuple); - page.minFilter = spine.Atlas.TextureFilter[tuple[0]]; - page.magFilter = spine.Atlas.TextureFilter[tuple[1]]; - - var direction = reader.readValue(); - page.uWrap = spine.Atlas.TextureWrap.clampToEdge; - page.vWrap = spine.Atlas.TextureWrap.clampToEdge; - if (direction == "x") - page.uWrap = spine.Atlas.TextureWrap.repeat; - else if (direction == "y") - page.vWrap = spine.Atlas.TextureWrap.repeat; - else if (direction == "xy") - page.uWrap = page.vWrap = spine.Atlas.TextureWrap.repeat; - - textureLoader.load(page, line); - - this.pages.push(page); - - } else { - var region = new spine.AtlasRegion(); - region.name = line; - region.page = page; - - region.rotate = reader.readValue() == "true"; - - reader.readTuple(tuple); - var x = parseInt(tuple[0]); - var y = parseInt(tuple[1]); - - reader.readTuple(tuple); - var width = parseInt(tuple[0]); - var height = parseInt(tuple[1]); - - region.u = x / page.width; - region.v = y / page.height; - if (region.rotate) { - region.u2 = (x + height) / page.width; - region.v2 = (y + width) / page.height; - } else { - region.u2 = (x + width) / page.width; - region.v2 = (y + height) / page.height; - } - region.x = x; - region.y = y; - region.width = Math.abs(width); - region.height = Math.abs(height); - - if (reader.readTuple(tuple) == 4) { // split is optional - region.splits = [parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])]; - - if (reader.readTuple(tuple) == 4) { // pad is optional, but only present with splits - region.pads = [parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])]; - - reader.readTuple(tuple); - } - } - - region.originalWidth = parseInt(tuple[0]); - region.originalHeight = parseInt(tuple[1]); - - reader.readTuple(tuple); - region.offsetX = parseInt(tuple[0]); - region.offsetY = parseInt(tuple[1]); - - region.index = parseInt(reader.readValue()); - - this.regions.push(region); - } - } -}; -spine.Atlas.prototype = { - findRegion: function (name) { - var regions = this.regions; - for (var i = 0, n = regions.length; i < n; i++) - if (regions[i].name == name) return regions[i]; - return null; - }, - dispose: function () { - var pages = this.pages; - for (var i = 0, n = pages.length; i < n; i++) - this.textureLoader.unload(pages[i].rendererObject); - }, - updateUVs: function (page) { - var regions = this.regions; - for (var i = 0, n = regions.length; i < n; i++) { - var region = regions[i]; - if (region.page != page) continue; - region.u = region.x / page.width; - region.v = region.y / page.height; - if (region.rotate) { - region.u2 = (region.x + region.height) / page.width; - region.v2 = (region.y + region.width) / page.height; - } else { - region.u2 = (region.x + region.width) / page.width; - region.v2 = (region.y + region.height) / page.height; - } - } - } -}; - -spine.Atlas.Format = { - alpha: 0, - intensity: 1, - luminanceAlpha: 2, - rgb565: 3, - rgba4444: 4, - rgb888: 5, - rgba8888: 6 -}; - -spine.Atlas.TextureFilter = { - nearest: 0, - linear: 1, - mipMap: 2, - mipMapNearestNearest: 3, - mipMapLinearNearest: 4, - mipMapNearestLinear: 5, - mipMapLinearLinear: 6 -}; - -spine.Atlas.TextureWrap = { - mirroredRepeat: 0, - clampToEdge: 1, - repeat: 2 -}; - -spine.AtlasPage = function () {}; -spine.AtlasPage.prototype = { - name: null, - format: null, - minFilter: null, - magFilter: null, - uWrap: null, - vWrap: null, - rendererObject: null, - width: 0, - height: 0 -}; - -spine.AtlasRegion = function () {}; -spine.AtlasRegion.prototype = { - page: null, - name: null, - x: 0, y: 0, - width: 0, height: 0, - u: 0, v: 0, u2: 0, v2: 0, - offsetX: 0, offsetY: 0, - originalWidth: 0, originalHeight: 0, - index: 0, - rotate: false, - splits: null, - pads: null, -}; - -spine.AtlasReader = function (text) { - this.lines = text.split(/\r\n|\r|\n/); -}; -spine.AtlasReader.prototype = { - index: 0, - trim: function (value) { - return value.replace(/^\s+|\s+$/g, ""); - }, - readLine: function () { - if (this.index >= this.lines.length) return null; - return this.lines[this.index++]; - }, - readValue: function () { - var line = this.readLine(); - var colon = line.indexOf(":"); - if (colon == -1) throw "Invalid line: " + line; - return this.trim(line.substring(colon + 1)); - }, - /** Returns the number of tuple values read (2 or 4). */ - readTuple: function (tuple) { - var line = this.readLine(); - var colon = line.indexOf(":"); - if (colon == -1) throw "Invalid line: " + line; - var i = 0, lastMatch= colon + 1; - for (; i < 3; i++) { - var comma = line.indexOf(",", lastMatch); - if (comma == -1) { - if (i == 0) throw "Invalid line: " + line; - break; - } - tuple[i] = this.trim(line.substr(lastMatch, comma - lastMatch)); - lastMatch = comma + 1; - } - tuple[i] = this.trim(line.substring(lastMatch)); - return i + 1; - } -} - -spine.AtlasAttachmentLoader = function (atlas) { - this.atlas = atlas; -} -spine.AtlasAttachmentLoader.prototype = { - newAttachment: function (skin, type, name) { - switch (type) { - case spine.AttachmentType.region: - var region = this.atlas.findRegion(name); - if (!region) throw "Region not found in atlas: " + name + " (" + type + ")"; - var attachment = new spine.RegionAttachment(name); - attachment.rendererObject = region; - attachment.setUVs(region.u, region.v, region.u2, region.v2, region.rotate); - attachment.regionOffsetX = region.offsetX; - attachment.regionOffsetY = region.offsetY; - attachment.regionWidth = region.width; - attachment.regionHeight = region.height; - attachment.regionOriginalWidth = region.originalWidth; - attachment.regionOriginalHeight = region.originalHeight; - return attachment; - } - throw "Unknown attachment type: " + type; - } -} - -PIXI.AnimCache = {}; -spine.Bone.yDown = true; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * This object is one that will allow you to specify custom rendering functions based on render type - * - * @class CustomRenderable - * @extends DisplayObject - * @constructor - */ -PIXI.CustomRenderable = function() -{ - PIXI.DisplayObject.call( this ); - -} - -// constructor -PIXI.CustomRenderable.prototype = Object.create( PIXI.DisplayObject.prototype ); -PIXI.CustomRenderable.prototype.constructor = PIXI.CustomRenderable; - -/** - * If this object is being rendered by a CanvasRenderer it will call this callback - * - * @method renderCanvas - * @param renderer {CanvasRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.renderCanvas = function(renderer) -{ - // override! -} - -/** - * If this object is being rendered by a WebGLRenderer it will call this callback to initialize - * - * @method initWebGL - * @param renderer {WebGLRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.initWebGL = function(renderer) -{ - // override! -} - -/** - * If this object is being rendered by a WebGLRenderer it will call this callback - * - * @method renderWebGL - * @param renderer {WebGLRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.renderWebGL = function(renderGroup, projectionMatrix) -{ - // not sure if both needed? but ya have for now! - // override! -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI.BaseTextureCache = {}; -PIXI.texturesToUpdate = []; -PIXI.texturesToDestroy = []; - -/** - * A texture stores the information that represents an image. All textures have a base texture - * - * @class BaseTexture - * @uses EventTarget - * @constructor - * @param source {String} the source object (image or canvas) - */ -PIXI.BaseTexture = function(source) -{ - PIXI.EventTarget.call( this ); - - /** - * [read-only] The width of the base texture set when the image has loaded - * - * @property width - * @type Number - * @readOnly - */ - this.width = 100; - - /** - * [read-only] The height of the base texture set when the image has loaded - * - * @property height - * @type Number - * @readOnly - */ - this.height = 100; - - /** - * [read-only] Describes if the base texture has loaded or not - * - * @property hasLoaded - * @type Boolean - * @readOnly - */ - this.hasLoaded = false; - - /** - * The source that is loaded to create the texture - * - * @property source - * @type Image - */ - this.source = source; - - if(!source)return; - - if(this.source instanceof Image || this.source instanceof HTMLImageElement) - { - if(this.source.complete) - { - this.hasLoaded = true; - this.width = this.source.width; - this.height = this.source.height; - - PIXI.texturesToUpdate.push(this); - } - else - { - - var scope = this; - this.source.onload = function(){ - - scope.hasLoaded = true; - scope.width = scope.source.width; - scope.height = scope.source.height; - - // add it to somewhere... - PIXI.texturesToUpdate.push(scope); - scope.dispatchEvent( { type: 'loaded', content: scope } ); - } - // this.image.src = imageUrl; - } - } - else - { - this.hasLoaded = true; - this.width = this.source.width; - this.height = this.source.height; - - PIXI.texturesToUpdate.push(this); - } - - this._powerOf2 = false; -} - -PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; - -/** - * Destroys this base texture - * - * @method destroy - */ -PIXI.BaseTexture.prototype.destroy = function() -{ - if(this.source instanceof Image) - { - this.source.src = null; - } - this.source = null; - PIXI.texturesToDestroy.push(this); -} - -/** - * Helper function that returns a base texture based on an image url - * If the image is not in the base texture cache it will be created and loaded - * - * @static - * @method fromImage - * @param imageUrl {String} The image url of the texture - * @return BaseTexture - */ -PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin) -{ - var baseTexture = PIXI.BaseTextureCache[imageUrl]; - if(!baseTexture) - { - // new Image() breaks tex loading in some versions of Chrome. - // See https://code.google.com/p/chromium/issues/detail?id=238071 - var image = new Image();//document.createElement('img'); - if (crossorigin) - { - image.crossOrigin = ''; - } - image.src = imageUrl; - baseTexture = new PIXI.BaseTexture(image); - PIXI.BaseTextureCache[imageUrl] = baseTexture; - } - - return baseTexture; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI.TextureCache = {}; -PIXI.FrameCache = {}; - -/** - * A texture stores the information that represents an image or part of an image. It cannot be added - * to the display list directly. To do this use PIXI.Sprite. If no frame is provided then the whole image is used - * - * @class Texture - * @uses EventTarget - * @constructor - * @param baseTexture {BaseTexture} The base texture source to create the texture from - * @param frmae {Rectangle} The rectangle frame of the texture to show - */ -PIXI.Texture = function(baseTexture, frame) -{ - PIXI.EventTarget.call( this ); - - if(!frame) - { - this.noFrame = true; - frame = new PIXI.Rectangle(0,0,1,1); - } - - if(baseTexture instanceof PIXI.Texture) - baseTexture = baseTexture.baseTexture; - - /** - * The base texture of this texture - * - * @property baseTexture - * @type BaseTexture - */ - this.baseTexture = baseTexture; - - /** - * The frame specifies the region of the base texture that this texture uses - * - * @property frame - * @type Rectangle - */ - this.frame = frame; - - /** - * The trim point - * - * @property trim - * @type Point - */ - this.trim = new PIXI.Point(); - - this.scope = this; - - if(baseTexture.hasLoaded) - { - if(this.noFrame)frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); - //console.log(frame) - - this.setFrame(frame); - } - else - { - var scope = this; - baseTexture.addEventListener( 'loaded', function(){ scope.onBaseTextureLoaded()} ); - } -} - -PIXI.Texture.prototype.constructor = PIXI.Texture; - -/** - * Called when the base texture is loaded - * - * @method onBaseTextureLoaded - * @param event - * @private - */ -PIXI.Texture.prototype.onBaseTextureLoaded = function(event) -{ - var baseTexture = this.baseTexture; - baseTexture.removeEventListener( 'loaded', this.onLoaded ); - - if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); - this.noFrame = false; - this.width = this.frame.width; - this.height = this.frame.height; - - this.scope.dispatchEvent( { type: 'update', content: this } ); -} - -/** - * Destroys this texture - * - * @method destroy - * @param destroyBase {Boolean} Whether to destroy the base texture as well - */ -PIXI.Texture.prototype.destroy = function(destroyBase) -{ - if(destroyBase)this.baseTexture.destroy(); -} - -/** - * Specifies the rectangle region of the baseTexture - * - * @method setFrame - * @param frame {Rectangle} The frame of the texture to set it to - */ -PIXI.Texture.prototype.setFrame = function(frame) -{ - this.frame = frame; - this.width = frame.width; - this.height = frame.height; - - if(frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error("Texture Error: frame does not fit inside the base Texture dimensions " + this); - } - - this.updateFrame = true; - - PIXI.Texture.frameUpdates.push(this); - //this.dispatchEvent( { type: 'update', content: this } ); -} - -/** - * Helper function that returns a texture based on an image url - * If the image is not in the texture cache it will be created and loaded - * - * @static - * @method fromImage - * @param imageUrl {String} The image url of the texture - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - * @return Texture - */ -PIXI.Texture.fromImage = function(imageUrl, crossorigin) -{ - var texture = PIXI.TextureCache[imageUrl]; - - if(!texture) - { - texture = new PIXI.Texture(PIXI.BaseTexture.fromImage(imageUrl, crossorigin)); - PIXI.TextureCache[imageUrl] = texture; - } - - return texture; -} - -/** - * Helper function that returns a texture based on a frame id - * If the frame id is not in the texture cache an error will be thrown - * - * @static - * @method fromFrame - * @param frameId {String} The frame id of the texture - * @return Texture - */ -PIXI.Texture.fromFrame = function(frameId) -{ - var texture = PIXI.TextureCache[frameId]; - if(!texture)throw new Error("The frameId '"+ frameId +"' does not exist in the texture cache " + this); - return texture; -} - -/** - * Helper function that returns a texture based on a canvas element - * If the canvas is not in the texture cache it will be created and loaded - * - * @static - * @method fromCanvas - * @param canvas {Canvas} The canvas element source of the texture - * @return Texture - */ -PIXI.Texture.fromCanvas = function(canvas) -{ - var baseTexture = new PIXI.BaseTexture(canvas); - return new PIXI.Texture(baseTexture); -} - - -/** - * Adds a texture to the textureCache. - * - * @static - * @method addTextureToCache - * @param texture {Texture} - * @param id {String} the id that the texture will be stored against. - */ -PIXI.Texture.addTextureToCache = function(texture, id) -{ - PIXI.TextureCache[id] = texture; -} - -/** - * Remove a texture from the textureCache. - * - * @static - * @method removeTextureFromCache - * @param id {String} the id of the texture to be removed - * @return {Texture} the texture that was removed - */ -PIXI.Texture.removeTextureFromCache = function(id) -{ - var texture = PIXI.TextureCache[id] - PIXI.TextureCache[id] = null; - return texture; -} - -// this is more for webGL.. it contains updated frames.. -PIXI.Texture.frameUpdates = []; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - A RenderTexture is a special texture that allows any pixi displayObject to be rendered to it. - - __Hint__: All DisplayObjects (exmpl. Sprites) that renders on RenderTexture should be preloaded. - Otherwise black rectangles will be drawn instead. - - RenderTexture takes snapshot of DisplayObject passed to render method. If DisplayObject is passed to render method, position and rotation of it will be ignored. For example: - - var renderTexture = new PIXI.RenderTexture(800, 600); - var sprite = PIXI.Sprite.fromImage("spinObj_01.png"); - sprite.position.x = 800/2; - sprite.position.y = 600/2; - sprite.anchor.x = 0.5; - sprite.anchor.y = 0.5; - renderTexture.render(sprite); - - Sprite in this case will be rendered to 0,0 position. To render this sprite at center DisplayObjectContainer should be used: - - var doc = new PIXI.DisplayObjectContainer(); - doc.addChild(sprite); - renderTexture.render(doc); // Renders to center of renderTexture - - @class RenderTexture - @extends Texture - @constructor - @param width {Number} The width of the render texture - @param height {Number} The height of the render texture - */ -PIXI.RenderTexture = function(width, height) -{ - PIXI.EventTarget.call( this ); - - this.width = width || 100; - this.height = height || 100; - - this.indetityMatrix = PIXI.mat3.create(); - - this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); - - if(PIXI.gl) - { - this.initWebGL(); - } - else - { - this.initCanvas(); - } -} - -PIXI.RenderTexture.prototype = Object.create( PIXI.Texture.prototype ); -PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture; - -/** - * Initializes the webgl data for this texture - * - * @method initWebGL - * @private - */ -PIXI.RenderTexture.prototype.initWebGL = function() -{ - var gl = PIXI.gl; - this.glFramebuffer = gl.createFramebuffer(); - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - - this.glFramebuffer.width = this.width; - this.glFramebuffer.height = this.height; - - this.baseTexture = new PIXI.BaseTexture(); - - this.baseTexture.width = this.width; - this.baseTexture.height = this.height; - - this.baseTexture._glTexture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); - - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - - this.baseTexture.isRender = true; - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0); - - // create a projection matrix.. - this.projection = new PIXI.Point(this.width/2 , this.height/2); -/* - this.projectionMatrix = PIXI.mat4.create(); - - this.projectionMatrix[5] = 2/this.height// * 0.5; - this.projectionMatrix[13] = -1; - - this.projectionMatrix[0] = 2/this.width; - this.projectionMatrix[12] = -1; -*/ - // set the correct render function.. - this.render = this.renderWebGL; - - -} - - -PIXI.RenderTexture.prototype.resize = function(width, height) -{ - - this.width = width; - this.height = height; - - //this.frame.width = this.width - //this.frame.height = this.height; - - - if(PIXI.gl) - { - this.projection.x = this.width/2 - this.projection.y = this.height/2; - - var gl = PIXI.gl; - gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - } - else - { - - this.frame.width = this.width - this.frame.height = this.height; - this.renderer.resize(this.width, this.height); - } -} - -/** - * Initializes the canvas data for this texture - * - * @method initCanvas - * @private - */ -PIXI.RenderTexture.prototype.initCanvas = function() -{ - this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, 0); - - this.baseTexture = new PIXI.BaseTexture(this.renderer.view); - this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); - - this.render = this.renderCanvas; -} - -/** - * This function will draw the display object to the texture. - * - * @method renderWebGL - * @param displayObject {DisplayObject} The display object to render this texture on - * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn - * @private - */ -PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear) -{ - var gl = PIXI.gl; - - // enable the alpha color mask.. - gl.colorMask(true, true, true, true); - - gl.viewport(0, 0, this.width, this.height); - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - - if(clear) - { - gl.clearColor(0,0,0, 0); - gl.clear(gl.COLOR_BUFFER_BIT); - } - - // THIS WILL MESS WITH HIT TESTING! - var children = displayObject.children; - - //TODO -? create a new one??? dont think so! - displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix; - // modify to flip... - displayObject.worldTransform[4] = -1; - displayObject.worldTransform[5] = this.projection.y * 2; - - - if(position) - { - displayObject.worldTransform[2] = position.x; - displayObject.worldTransform[5] -= position.y; - } - - - - for(var i=0,j=children.length; i} assetURLs an array of image/sprite sheet urls that you would like loaded - * supported. Supported image formats include "jpeg", "jpg", "png", "gif". Supported - * sprite sheet data formats only include "JSON" at this time. Supported bitmap font - * data formats include "xml" and "fnt". - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.AssetLoader = function(assetURLs, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The array of asset URLs that are going to be loaded - * - * @property assetURLs - * @type Array - */ - this.assetURLs = assetURLs; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * Maps file extension to loader types - * - * @property loadersByType - * @type Object - */ - this.loadersByType = { - "jpg": PIXI.ImageLoader, - "jpeg": PIXI.ImageLoader, - "png": PIXI.ImageLoader, - "gif": PIXI.ImageLoader, - "json": PIXI.JsonLoader, - "anim": PIXI.SpineLoader, - "xml": PIXI.BitmapFontLoader, - "fnt": PIXI.BitmapFontLoader - }; - - -}; - -/** - * Fired when an item has loaded - * @event onProgress - */ - -/** - * Fired when all the assets have loaded - * @event onComplete - */ - -// constructor -PIXI.AssetLoader.prototype.constructor = PIXI.AssetLoader; - -/** - * Starts loading the assets sequentially - * - * @method load - */ -PIXI.AssetLoader.prototype.load = function() -{ - var scope = this; - - this.loadCount = this.assetURLs.length; - - for (var i=0; i < this.assetURLs.length; i++) - { - var fileName = this.assetURLs[i]; - var fileType = fileName.split(".").pop().toLowerCase(); - - var loaderClass = this.loadersByType[fileType]; - if(!loaderClass) - throw new Error(fileType + " is an unsupported file type"); - - var loader = new loaderClass(fileName, this.crossorigin); - - loader.addEventListener("loaded", function() - { - scope.onAssetLoaded(); - }); - loader.load(); - } -}; - -/** - * Invoked after each file is loaded - * - * @method onAssetLoaded - * @private - */ -PIXI.AssetLoader.prototype.onAssetLoaded = function() -{ - this.loadCount--; - this.dispatchEvent({type: "onProgress", content: this}); - if(this.onProgress) this.onProgress(); - - if(this.loadCount == 0) - { - this.dispatchEvent({type: "onComplete", content: this}); - if(this.onComplete) this.onComplete(); - } -}; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The json file loader is used to load in JSON data and parsing it - * When loaded this class will dispatch a "loaded" event - * If load failed this class will dispatch a "error" event - * - * @class JsonLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.JsonLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * [read-only] Whether the data has loaded yet - * - * @property loaded - * @type Boolean - * @readOnly - */ - this.loaded = false; - -}; - -// constructor -PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader; - -/** - * Loads the JSON data - * - * @method load - */ -PIXI.JsonLoader.prototype.load = function () { - this.ajaxRequest = new AjaxRequest(); - var scope = this; - this.ajaxRequest.onreadystatechange = function () { - scope.onJSONLoaded(); - }; - - this.ajaxRequest.open("GET", this.url, true); - if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json"); - this.ajaxRequest.send(null); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.JsonLoader.prototype.onJSONLoaded = function () { - if (this.ajaxRequest.readyState == 4) { - if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) { - this.json = JSON.parse(this.ajaxRequest.responseText); - - if(this.json.frames) - { - // sprite sheet - var scope = this; - var textureUrl = this.baseUrl + this.json.meta.image; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - var frameData = this.json.frames; - - this.texture = image.texture.baseTexture; - image.addEventListener("loaded", function (event) { - scope.onLoaded(); - }); - - for (var i in frameData) { - var rect = frameData[i].frame; - if (rect) { - PIXI.TextureCache[i] = new PIXI.Texture(this.texture, { - x: rect.x, - y: rect.y, - width: rect.w, - height: rect.h - }); - if (frameData[i].trimmed) { - //var realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w) - // calculate the offset! - } - } - } - - image.load(); - - } - else if(this.json.bones) - { - // spine animation - var spineJsonParser = new spine.SkeletonJson(); - var skeletonData = spineJsonParser.readSkeletonData(this.json); - PIXI.AnimCache[this.url] = skeletonData; - this.onLoaded(); - } - else - { - this.onLoaded(); - } - } - else - { - this.onError(); - } - } -}; - -/** - * Invoke when json file loaded - * - * @method onLoaded - * @private - */ -PIXI.JsonLoader.prototype.onLoaded = function () { - this.loaded = true; - this.dispatchEvent({ - type: "loaded", - content: this - }); -}; - -/** - * Invoke when error occured - * - * @method onError - * @private - */ -PIXI.JsonLoader.prototype.onError = function () { - this.dispatchEvent({ - type: "error", - content: this - }); -}; -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The sprite sheet loader is used to load in JSON sprite sheet data - * To generate the data you can use http://www.codeandweb.com/texturepacker and publish the "JSON" format - * There is a free version so thats nice, although the paid version is great value for money. - * It is highly recommended to use Sprite sheets (also know as texture atlas") as it means sprite"s can be batched and drawn together for highly increased rendering speed. - * Once the data has been loaded the frames are stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId() - * This loader will also load the image file that the Spritesheet points to as well as the data. - * When loaded this class will dispatch a "loaded" event - * - * @class SpriteSheetLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the sprite sheet JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ - -PIXI.SpriteSheetLoader = function (url, crossorigin) { - /* - * i use texture packer to load the assets.. - * http://www.codeandweb.com/texturepacker - * make sure to set the format as "JSON" - */ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * The texture being loaded - * - * @property texture - * @type Texture - */ - this.texture = null; - - /** - * The frames of the sprite sheet - * - * @property frames - * @type Object - */ - this.frames = {}; -}; - -// constructor -PIXI.SpriteSheetLoader.prototype.constructor = PIXI.SpriteSheetLoader; - -/** - * This will begin loading the JSON file - * - * @method load - */ -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; - scope.onJSONLoaded(); - }); - jsonLoader.load(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () { - var scope = this; - var textureUrl = this.baseUrl + this.json.meta.image; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - var frameData = this.json.frames; - - this.texture = image.texture.baseTexture; - image.addEventListener("loaded", function (event) { - scope.onLoaded(); - }); - - for (var i in frameData) { - var rect = frameData[i].frame; - if (rect) { - PIXI.TextureCache[i] = new PIXI.Texture(this.texture, { - x: rect.x, - y: rect.y, - width: rect.w, - height: rect.h - }); - if (frameData[i].trimmed) { - //var realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w) - // calculate the offset! - } - } - } - - image.load(); -}; -/** - * Invoke when all files are loaded (json and texture) - * - * @method onLoaded - * @private - */ -PIXI.SpriteSheetLoader.prototype.onLoaded = function () { - this.dispatchEvent({ - type: "loaded", - content: this - }); -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The image loader class is responsible for loading images file formats ("jpeg", "jpg", "png" and "gif") - * Once the image has been loaded it is stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId() - * When loaded this class will dispatch a 'loaded' event - * - * @class ImageLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the image - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.ImageLoader = function(url, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The texture being loaded - * - * @property texture - * @type Texture - */ - this.texture = PIXI.Texture.fromImage(url, crossorigin); -}; - -// constructor -PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader; - -/** - * Loads image or takes it from cache - * - * @method load - */ -PIXI.ImageLoader.prototype.load = function() -{ - if(!this.texture.baseTexture.hasLoaded) - { - var scope = this; - this.texture.baseTexture.addEventListener("loaded", function() - { - scope.onLoaded(); - }); - } - else - { - this.onLoaded(); - } -}; - -/** - * Invoked when image file is loaded or it is already cached and ready to use - * - * @method onLoaded - * @private - */ -PIXI.ImageLoader.prototype.onLoaded = function() -{ - this.dispatchEvent({type: "loaded", content: this}); -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The xml loader is used to load in XML bitmap font data ("xml" or "fnt") - * To generate the data you can use http://www.angelcode.com/products/bmfont/ - * This loader will also load the image file as the data. - * When loaded this class will dispatch a "loaded" event - * - * @class BitmapFontLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the sprite sheet JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.BitmapFontLoader = function(url, crossorigin) -{ - /* - * i use texture packer to load the assets.. - * http://www.codeandweb.com/texturepacker - * make sure to set the format as "JSON" - */ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * [read-only] The texture of the bitmap font - * - * @property baseUrl - * @type String - */ - this.texture = null; -}; - -// constructor -PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; - -/** - * Loads the XML font data - * - * @method load - */ -PIXI.BitmapFontLoader.prototype.load = function() -{ - this.ajaxRequest = new XMLHttpRequest(); - var scope = this; - this.ajaxRequest.onreadystatechange = function() - { - scope.onXMLLoaded(); - }; - - this.ajaxRequest.open("GET", this.url, true); - if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/xml"); - this.ajaxRequest.send(null) -}; - -/** - * Invoked when XML file is loaded, parses the data - * - * @method onXMLLoaded - * @private - */ -PIXI.BitmapFontLoader.prototype.onXMLLoaded = function() -{ - if (this.ajaxRequest.readyState == 4) - { - if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) - { - var textureUrl = this.baseUrl + this.ajaxRequest.responseXML.getElementsByTagName("page")[0].attributes.getNamedItem("file").nodeValue; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - this.texture = image.texture.baseTexture; - - var data = {}; - var info = this.ajaxRequest.responseXML.getElementsByTagName("info")[0]; - var common = this.ajaxRequest.responseXML.getElementsByTagName("common")[0]; - data.font = info.attributes.getNamedItem("face").nodeValue; - data.size = parseInt(info.attributes.getNamedItem("size").nodeValue, 10); - data.lineHeight = parseInt(common.attributes.getNamedItem("lineHeight").nodeValue, 10); - data.chars = {}; - - //parse letters - var letters = this.ajaxRequest.responseXML.getElementsByTagName("char"); - - for (var i = 0; i < letters.length; i++) - { - var charCode = parseInt(letters[i].attributes.getNamedItem("id").nodeValue, 10); - - var textureRect = { - x: parseInt(letters[i].attributes.getNamedItem("x").nodeValue, 10), - y: parseInt(letters[i].attributes.getNamedItem("y").nodeValue, 10), - width: parseInt(letters[i].attributes.getNamedItem("width").nodeValue, 10), - height: parseInt(letters[i].attributes.getNamedItem("height").nodeValue, 10) - }; - PIXI.TextureCache[charCode] = new PIXI.Texture(this.texture, textureRect); - - data.chars[charCode] = { - xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), - yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), - xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), - kerning: {}, - texture:new PIXI.Texture(this.texture, textureRect) - - }; - } - - //parse kernings - var kernings = this.ajaxRequest.responseXML.getElementsByTagName("kerning"); - for (i = 0; i < kernings.length; i++) - { - var first = parseInt(kernings[i].attributes.getNamedItem("first").nodeValue, 10); - var second = parseInt(kernings[i].attributes.getNamedItem("second").nodeValue, 10); - var amount = parseInt(kernings[i].attributes.getNamedItem("amount").nodeValue, 10); - - data.chars[second].kerning[first] = amount; - - } - - PIXI.BitmapText.fonts[data.font] = data; - - var scope = this; - image.addEventListener("loaded", function() { - scope.onLoaded(); - }); - image.load(); - } - } -}; - -/** - * Invoked when all files are loaded (xml/fnt and texture) - * - * @method onLoaded - * @private - */ -PIXI.BitmapFontLoader.prototype.onLoaded = function() -{ - this.dispatchEvent({type: "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 - * - * Awesome JS run time provided by EsotericSoftware - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -/** - * The Spine loader is used to load in JSON spine data - * To generate the data you need to use http://esotericsoftware.com/ and export the "JSON" format - * Due to a clash of names You will need to change the extension of the spine file from *.json to *.anim for it to load - * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source - * You will need to generate a sprite sheet to accompany the spine data - * When loaded this class will dispatch a "loaded" event - * - * @class Spine - * @uses EventTarget - * @constructor - * @param url {String} The url of the JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.SpineLoader = function(url, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] Whether the data has loaded yet - * - * @property loaded - * @type Boolean - * @readOnly - */ - this.loaded = false; -} - -PIXI.SpineLoader.prototype.constructor = PIXI.SpineLoader; - -/** - * Loads the JSON data - * - * @method load - */ -PIXI.SpineLoader.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; - scope.onJSONLoaded(); - }); - jsonLoader.load(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.SpineLoader.prototype.onJSONLoaded = function (event) { - var spineJsonParser = new spine.SkeletonJson(); - var skeletonData = spineJsonParser.readSkeletonData(this.json); - - PIXI.AnimCache[this.url] = skeletonData; - - this.onLoaded(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onLoaded - * @private - */ -PIXI.SpineLoader.prototype.onLoaded = function () { - this.loaded = true; - this.dispatchEvent({type: "loaded", content: this}); -}; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - if (typeof exports !== 'undefined') { - if (typeof module !== 'undefined' && module.exports) { - exports = module.exports = PIXI; - } - exports.PIXI = PIXI; - } else { - root.PIXI = PIXI; - } - - -}).call(this); \ No newline at end of file diff --git a/examples/example 5 - Morph/index.html b/examples/example 5 - Morph/index.html index 0c8c5c3..dd246f7 100755 --- a/examples/example 5 - Morph/index.html +++ b/examples/example 5 - Morph/index.html @@ -4,9 +4,9 @@ Pixi Morph by Photon Storm - + - + @@ -45,7 +45,7 @@ renderer = PIXI.autoDetectRenderer(w, h); stage = new PIXI.Stage; - + document.body.appendChild(renderer.view); makeObject(0); @@ -298,7 +298,7 @@ { w = $(window).width() - 16; h = $(window).height() - 16; - + renderer.resize(w, h); } diff --git a/examples/example 5 - Morph/pixi.js b/examples/example 5 - Morph/pixi.js deleted file mode 100644 index a6e7055..0000000 --- a/examples/example 5 - Morph/pixi.js +++ /dev/null @@ -1,10438 +0,0 @@ -/** - * @license - * Pixi.JS - v1.3.0 - * Copyright (c) 2012, Mat Groves - * http://goodboydigital.com/ - * - * Compiled: 2013-07-24 - * - * Pixi.JS is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license.php - */ -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -(function(){ - - var root = this; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * @module PIXI - */ -var PIXI = PIXI || {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis. - * - * @class Point - * @constructor - * @param x {Number} position of the point - * @param y {Number} position of the point - */ -PIXI.Point = function(x, y) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; -} - -/** - * Creates a clone of this point - * - * @method clone - * @return {Point} a copy of the point - */ -PIXI.Point.prototype.clone = function() -{ - return new PIXI.Point(this.x, this.y); -} - -// constructor -PIXI.Point.prototype.constructor = PIXI.Point; - - -/** - * @author Mat Groves http://matgroves.com/ - */ - -/** - * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. - * - * @class Rectangle - * @constructor - * @param x {Number} The X coord of the upper-left corner of the rectangle - * @param y {Number} The Y coord of the upper-left corner of the rectangle - * @param width {Number} The overall wisth of this rectangle - * @param height {Number} The overall height of this rectangle - */ -PIXI.Rectangle = function(x, y, width, height) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property width - * @type Number - * @default 0 - */ - this.width = width || 0; - - /** - * @property height - * @type Number - * @default 0 - */ - this.height = height || 0; -} - -/** - * Creates a clone of this Rectangle - * - * @method clone - * @return {Rectangle} a copy of the rectangle - */ -PIXI.Rectangle.prototype.clone = function() -{ - return new PIXI.Rectangle(this.x, this.y, this.width, this.height); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this Rectangle - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this Rectangle - */ -PIXI.Rectangle.prototype.contains = function(x, y) -{ - if(this.width <= 0 || this.height <= 0) - return false; - - var x1 = this.x; - if(x > x1 && x < x1 + this.width) - { - var y1 = this.y; - - if(y > y1 && y < y1 + this.height) - { - return true; - } - } - - return false; -} - -// constructor -PIXI.Rectangle.prototype.constructor = PIXI.Rectangle; - - -/** - * @author Adrien Brault - */ - -/** - * @class Polygon - * @constructor - * @param points* {Array|Array|Point...|Number...} This can be an array of Points that form the polygon, - * a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arugments passed can be - * all the points of the polygon e.g. `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the - * arguments passed can be flat x,y values e.g. `new PIXI.Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are - * Numbers. - */ -PIXI.Polygon = function(points) -{ - //if points isn't an array, use arguments as the array - if(!(points instanceof Array)) - points = Array.prototype.slice.call(arguments); - - //if this is a flat array of numbers, convert it to points - if(typeof points[0] === 'number') { - var p = []; - for(var i = 0, il = points.length; i < il; i+=2) { - p.push( - new PIXI.Point(points[i], points[i + 1]) - ); - } - - points = p; - } - - this.points = points; -} - -/** - * Creates a clone of this polygon - * - * @method clone - * @return {Polygon} a copy of the polygon - */ -PIXI.Polygon.prototype.clone = function() -{ - var points = []; - for (var i=0; i y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi); - - if(intersect) inside = !inside; - } - - return inside; -} - -PIXI.Polygon.prototype.constructor = PIXI.Polygon; - - -/** - * @author Chad Engler - */ - -/** - * The Circle object can be used to specify a hit area for displayobjects - * - * @class Circle - * @constructor - * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this circle - * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this circle - * @param radius {Number} The radius of the circle - */ -PIXI.Circle = function(x, y, radius) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property radius - * @type Number - * @default 0 - */ - this.radius = radius || 0; -} - -/** - * Creates a clone of this Circle instance - * - * @method clone - * @return {Circle} a copy of the polygon - */ -PIXI.Circle.prototype.clone = function() -{ - return new PIXI.Circle(this.x, this.y, this.radius); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this circle - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this polygon - */ -PIXI.Circle.prototype.contains = function(x, y) -{ - if(this.radius <= 0) - return false; - - var dx = (this.x - x), - dy = (this.y - y), - r2 = this.radius * this.radius; - - dx *= dx; - dy *= dy; - - return (dx + dy <= r2); -} - -PIXI.Circle.prototype.constructor = PIXI.Circle; - - -/** - * @author Chad Engler - */ - -/** - * The Ellipse object can be used to specify a hit area for displayobjects - * - * @class Ellipse - * @constructor - * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this ellipse - * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this ellipse - * @param width {Number} The overall height of this ellipse - * @param height {Number} The overall width of this ellipse - */ -PIXI.Ellipse = function(x, y, width, height) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property width - * @type Number - * @default 0 - */ - this.width = width || 0; - - /** - * @property height - * @type Number - * @default 0 - */ - this.height = height || 0; -} - -/** - * Creates a clone of this Ellipse instance - * - * @method clone - * @return {Ellipse} a copy of the ellipse - */ -PIXI.Ellipse.prototype.clone = function() -{ - return new PIXI.Ellipse(this.x, this.y, this.width, this.height); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this ellipse - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this ellipse - */ -PIXI.Ellipse.prototype.contains = function(x, y) -{ - if(this.width <= 0 || this.height <= 0) - return false; - - //normalize the coords to an ellipse with center 0,0 - //and a radius of 0.5 - var normx = ((x - this.x) / this.width) - 0.5, - normy = ((y - this.y) / this.height) - 0.5; - - normx *= normx; - normy *= normy; - - return (normx + normy < 0.25); -} - -PIXI.Ellipse.getBounds = function() -{ - return new PIXI.Rectangle(this.x, this.y, this.width, this.height); -} - -PIXI.Ellipse.prototype.constructor = PIXI.Ellipse; - - - - -/* - * A lighter version of the rad gl-matrix created by Brandon Jones, Colin MacKenzie IV - * you both rock! - */ - -function determineMatrixArrayType() { - PIXI.Matrix = (typeof Float32Array !== 'undefined') ? Float32Array : Array; - return PIXI.Matrix; -} - -determineMatrixArrayType(); - -PIXI.mat3 = {}; - -PIXI.mat3.create = function() -{ - var matrix = new PIXI.Matrix(9); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 1; - matrix[5] = 0; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 1; - - return matrix; -} - - -PIXI.mat3.identity = function(matrix) -{ - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 1; - matrix[5] = 0; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 1; - - return matrix; -} - - -PIXI.mat4 = {}; - -PIXI.mat4.create = function() -{ - var matrix = new PIXI.Matrix(16); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 0; - matrix[5] = 1; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 0; - matrix[9] = 0; - matrix[10] = 1; - matrix[11] = 0; - matrix[12] = 0; - matrix[13] = 0; - matrix[14] = 0; - matrix[15] = 1; - - return matrix; -} - -PIXI.mat3.multiply = function (mat, mat2, dest) -{ - if (!dest) { dest = mat; } - - // Cache the matrix values (makes for huge speed increases!) - var a00 = mat[0], a01 = mat[1], a02 = mat[2], - a10 = mat[3], a11 = mat[4], a12 = mat[5], - a20 = mat[6], a21 = mat[7], a22 = mat[8], - - b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], - b10 = mat2[3], b11 = mat2[4], b12 = mat2[5], - b20 = mat2[6], b21 = mat2[7], b22 = mat2[8]; - - dest[0] = b00 * a00 + b01 * a10 + b02 * a20; - dest[1] = b00 * a01 + b01 * a11 + b02 * a21; - dest[2] = b00 * a02 + b01 * a12 + b02 * a22; - - dest[3] = b10 * a00 + b11 * a10 + b12 * a20; - dest[4] = b10 * a01 + b11 * a11 + b12 * a21; - dest[5] = b10 * a02 + b11 * a12 + b12 * a22; - - dest[6] = b20 * a00 + b21 * a10 + b22 * a20; - dest[7] = b20 * a01 + b21 * a11 + b22 * a21; - dest[8] = b20 * a02 + b21 * a12 + b22 * a22; - - return dest; -} - -PIXI.mat3.clone = function(mat) -{ - var matrix = new PIXI.Matrix(9); - - matrix[0] = mat[0]; - matrix[1] = mat[1]; - matrix[2] = mat[2]; - matrix[3] = mat[3]; - matrix[4] = mat[4]; - matrix[5] = mat[5]; - matrix[6] = mat[6]; - matrix[7] = mat[7]; - matrix[8] = mat[8]; - - return matrix; -} - -PIXI.mat3.transpose = function (mat, dest) -{ - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (!dest || mat === dest) { - var a01 = mat[1], a02 = mat[2], - a12 = mat[5]; - - mat[1] = mat[3]; - mat[2] = mat[6]; - mat[3] = a01; - mat[5] = mat[7]; - mat[6] = a02; - mat[7] = a12; - return mat; - } - - dest[0] = mat[0]; - dest[1] = mat[3]; - dest[2] = mat[6]; - dest[3] = mat[1]; - dest[4] = mat[4]; - dest[5] = mat[7]; - dest[6] = mat[2]; - dest[7] = mat[5]; - dest[8] = mat[8]; - return dest; -} - -PIXI.mat3.toMat4 = function (mat, dest) -{ - if (!dest) { dest = PIXI.mat4.create(); } - - dest[15] = 1; - dest[14] = 0; - dest[13] = 0; - dest[12] = 0; - - dest[11] = 0; - dest[10] = mat[8]; - dest[9] = mat[7]; - dest[8] = mat[6]; - - dest[7] = 0; - dest[6] = mat[5]; - dest[5] = mat[4]; - dest[4] = mat[3]; - - dest[3] = 0; - dest[2] = mat[2]; - dest[1] = mat[1]; - dest[0] = mat[0]; - - return dest; -} - - -///// - - -PIXI.mat4.create = function() -{ - var matrix = new PIXI.Matrix(16); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 0; - matrix[5] = 1; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 0; - matrix[9] = 0; - matrix[10] = 1; - matrix[11] = 0; - matrix[12] = 0; - matrix[13] = 0; - matrix[14] = 0; - matrix[15] = 1; - - return matrix; -} - -PIXI.mat4.transpose = function (mat, dest) -{ - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (!dest || mat === dest) - { - var a01 = mat[1], a02 = mat[2], a03 = mat[3], - a12 = mat[6], a13 = mat[7], - a23 = mat[11]; - - mat[1] = mat[4]; - mat[2] = mat[8]; - mat[3] = mat[12]; - mat[4] = a01; - mat[6] = mat[9]; - mat[7] = mat[13]; - mat[8] = a02; - mat[9] = a12; - mat[11] = mat[14]; - mat[12] = a03; - mat[13] = a13; - mat[14] = a23; - return mat; - } - - dest[0] = mat[0]; - dest[1] = mat[4]; - dest[2] = mat[8]; - dest[3] = mat[12]; - dest[4] = mat[1]; - dest[5] = mat[5]; - dest[6] = mat[9]; - dest[7] = mat[13]; - dest[8] = mat[2]; - dest[9] = mat[6]; - dest[10] = mat[10]; - dest[11] = mat[14]; - dest[12] = mat[3]; - dest[13] = mat[7]; - dest[14] = mat[11]; - dest[15] = mat[15]; - return dest; -} - -PIXI.mat4.multiply = function (mat, mat2, dest) -{ - if (!dest) { dest = mat; } - - // Cache the matrix values (makes for huge speed increases!) - var a00 = mat[ 0], a01 = mat[ 1], a02 = mat[ 2], a03 = mat[3]; - var a10 = mat[ 4], a11 = mat[ 5], a12 = mat[ 6], a13 = mat[7]; - var a20 = mat[ 8], a21 = mat[ 9], a22 = mat[10], a23 = mat[11]; - var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15]; - - // Cache only the current line of the second matrix - var b0 = mat2[0], b1 = mat2[1], b2 = mat2[2], b3 = mat2[3]; - dest[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[4]; - b1 = mat2[5]; - b2 = mat2[6]; - b3 = mat2[7]; - dest[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[8]; - b1 = mat2[9]; - b2 = mat2[10]; - b3 = mat2[11]; - dest[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[12]; - b1 = mat2[13]; - b2 = mat2[14]; - b3 = mat2[15]; - dest[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - return dest; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The base class for all objects that are rendered on the screen. - * - * @class DisplayObject - * @constructor - */ -PIXI.DisplayObject = function() -{ - this.last = this; - this.first = this; - - /** - * The coordinate of the object relative to the local coordinates of the parent. - * - * @property position - * @type Point - */ - this.position = new PIXI.Point(); - - /** - * The scale factor of the object. - * - * @property scale - * @type Point - */ - this.scale = new PIXI.Point(1,1);//{x:1, y:1}; - - /** - * The pivot point of the displayObject that it rotates around - * - * @property pivot - * @type Point - */ - this.pivot = new PIXI.Point(0,0); - - /** - * The rotation of the object in radians. - * - * @property rotation - * @type Number - */ - this.rotation = 0; - - /** - * The opacity of the object. - * - * @property alpha - * @type Number - */ - this.alpha = 1; - - /** - * The visibility of the object. - * - * @property visible - * @type Boolean - */ - this.visible = true; - - /** - * This is the defined area that will pick up mouse / touch events. It is null by default. - * Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children) - * - * @property hitArea - * @type Rectangle|Circle|Ellipse|Polygon - */ - this.hitArea = null; - - /** - * This is used to indicate if the displayObject should display a mouse hand cursor on rollover - * - * @property buttonMode - * @type Boolean - */ - this.buttonMode = false; - - /** - * Can this object be rendered - * - * @property renderable - * @type Boolean - */ - this.renderable = false; - - /** - * [read-only] The visibility of the object based on world (parent) factors. - * - * @property worldVisible - * @type Boolean - * @readOnly - */ - this.worldVisible = false; - - /** - * [read-only] The display object container that contains this display object. - * - * @property parent - * @type DisplayObjectContainer - * @readOnly - */ - this.parent = null; - - /** - * [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage. - * - * @property stage - * @type Stage - * @readOnly - */ - this.stage = null; - - /** - * [read-only] The index of this object in the parent's `children` array - * - * @property childIndex - * @type Number - * @readOnly - */ - this.childIndex = 0; - - /** - * [read-only] The multiplied alpha of the displayobject - * - * @property worldAlpha - * @type Number - * @readOnly - */ - this.worldAlpha = 1; - - /** - * [read-only] Whether or not the object is interactive, do not toggle directly! use the `interactive` property - * - * @property _interactive - * @type Boolean - * @readOnly - * @private - */ - this._interactive = false; - - /** - * [read-only] Current transform of the object based on world (parent) factors - * - * @property worldTransform - * @type Mat3 - * @readOnly - * @private - */ - this.worldTransform = PIXI.mat3.create()//mat3.identity(); - - /** - * [read-only] Current transform of the object locally - * - * @property localTransform - * @type Mat3 - * @readOnly - * @private - */ - this.localTransform = PIXI.mat3.create()//mat3.identity(); - - /** - * [NYI] Unkown - * - * @property color - * @type Array<> - * @private - */ - this.color = []; - - /** - * [NYI] Holds whether or not this object is dynamic, for rendering optimization - * - * @property dynamic - * @type Boolean - * @private - */ - this.dynamic = true; - - // chach that puppy! - this._sr = 0; - this._cr = 1; - - /* - * MOUSE Callbacks - */ - - /** - * A callback that is used when the users clicks on the displayObject with their mouse - * @method click - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user clicks the mouse down over the sprite - * @method mousedown - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the mouse that was over the displayObject - * for this callback to be fired the mouse must have been pressed down over the displayObject - * @method mouseup - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject - * for this callback to be fired, The touch must have started over the displayObject - * @method mouseupoutside - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the users mouse rolls over the displayObject - * @method mouseover - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the users mouse leaves the displayObject - * @method mouseout - * @param interactionData {InteractionData} - */ - - - /* - * TOUCH Callbacks - */ - - /** - * A callback that is used when the users taps on the sprite with their finger - * basically a touch version of click - * @method tap - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user touch's over the displayObject - * @method touchstart - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases a touch over the displayObject - * @method touchend - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the touch that was over the displayObject - * for this callback to be fired, The touch must have started over the sprite - * @method touchendoutside - * @param interactionData {InteractionData} - */ -} - -// constructor -PIXI.DisplayObject.prototype.constructor = PIXI.DisplayObject; - -//TODO make visible a getter setter -/* -Object.defineProperty(PIXI.DisplayObject.prototype, 'visible', { - get: function() { - return this._visible; - }, - set: function(value) { - this._visible = value; - } -});*/ - -/** - * [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default - * Instead of using this function you can now simply set the interactive property to true or false - * - * @method setInteractive - * @param interactive {Boolean} - * @deprecated Simply set the `interactive` property directly - */ -PIXI.DisplayObject.prototype.setInteractive = function(interactive) -{ - this.interactive = interactive; -} - -/** - * Indicates if the sprite will have touch and mouse interactivity. It is false by default - * - * @property interactive - * @type Boolean - * @default false - */ -Object.defineProperty(PIXI.DisplayObject.prototype, 'interactive', { - get: function() { - return this._interactive; - }, - set: function(value) { - this._interactive = value; - - // TODO more to be done here.. - // need to sort out a re-crawl! - if(this.stage)this.stage.dirty = true; - } -}); - -/** - * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. - * In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. - * To remove a mask, set this property to null. - * - * @property mask - * @type Graphics - */ -Object.defineProperty(PIXI.DisplayObject.prototype, 'mask', { - get: function() { - return this._mask; - }, - set: function(value) { - - this._mask = value; - - if(value) - { - this.addFilter(value) - } - else - { - this.removeFilter(); - } - } -}); - -/* - * Adds a filter to this displayObject - * - * @method addFilter - * @param mask {Graphics} the graphics object to use as a filter - * @private - */ -PIXI.DisplayObject.prototype.addFilter = function(mask) -{ - if(this.filter)return; - this.filter = true; - - - // insert a filter block.. - var start = new PIXI.FilterBlock(); - var end = new PIXI.FilterBlock(); - - - start.mask = mask; - end.mask = mask; - - start.first = start.last = this; - end.first = end.last = this; - - start.open = true; - - /* - * - * insert start - * - */ - - var childFirst = start - var childLast = start - var nextObject; - var previousObject; - - previousObject = this.first._iPrev; - - if(previousObject) - { - nextObject = previousObject._iNext; - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - } - else - { - nextObject = this; - } - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - - // now insert the end filter block.. - - /* - * - * insert end filter - * - */ - var childFirst = end - var childLast = end - var nextObject = null; - var previousObject = null; - - previousObject = this.last; - nextObject = previousObject._iNext; - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - var updateLast = this; - - var prevLast = this.last; - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = end; - } - updateLast = updateLast.parent; - } - - this.first = start; - - // if webGL... - if(this.__renderGroup) - { - this.__renderGroup.addFilterBlocks(start, end); - } - - mask.renderable = false; - -} - -/* - * Removes the filter to this displayObject - * - * @method removeFilter - * @private - */ -PIXI.DisplayObject.prototype.removeFilter = function() -{ - if(!this.filter)return; - this.filter = false; - - // modify the list.. - var startBlock = this.first; - - var nextObject = startBlock._iNext; - var previousObject = startBlock._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - if(previousObject)previousObject._iNext = nextObject; - - this.first = startBlock._iNext; - - - // remove the end filter - var lastBlock = this.last; - - var nextObject = lastBlock._iNext; - var previousObject = lastBlock._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - previousObject._iNext = nextObject; - - // this is always true too! -// if(this.last == lastBlock) - //{ - var tempLast = lastBlock._iPrev; - // need to make sure the parents last is updated too - var updateLast = this; - while(updateLast.last == lastBlock) - { - updateLast.last = tempLast; - updateLast = updateLast.parent; - if(!updateLast)break; - } - - var mask = startBlock.mask - mask.renderable = true; - - // if webGL... - if(this.__renderGroup) - { - this.__renderGroup.removeFilterBlocks(startBlock, lastBlock); - } - //} -} - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.DisplayObject.prototype.updateTransform = function() -{ - // TODO OPTIMIZE THIS!! with dirty - if(this.rotation != this.rotationCache) - { - this.rotationCache = this.rotation; - this._sr = Math.sin(this.rotation); - this._cr = Math.cos(this.rotation); - } - - var localTransform = this.localTransform; - var parentTransform = this.parent.worldTransform; - var worldTransform = this.worldTransform; - //console.log(localTransform) - localTransform[0] = this._cr * this.scale.x; - localTransform[1] = -this._sr * this.scale.y - localTransform[3] = this._sr * this.scale.x; - localTransform[4] = this._cr * this.scale.y; - - // TODO --> do we even need a local matrix??? - - var px = this.pivot.x; - var py = this.pivot.y; - - // Cache the matrix values (makes for huge speed increases!) - var a00 = localTransform[0], a01 = localTransform[1], a02 = this.position.x - localTransform[0] * px - py * localTransform[1], - a10 = localTransform[3], a11 = localTransform[4], a12 = this.position.y - localTransform[4] * py - px * localTransform[3], - - b00 = parentTransform[0], b01 = parentTransform[1], b02 = parentTransform[2], - b10 = parentTransform[3], b11 = parentTransform[4], b12 = parentTransform[5]; - - localTransform[2] = a02 - localTransform[5] = a12 - - worldTransform[0] = b00 * a00 + b01 * a10; - worldTransform[1] = b00 * a01 + b01 * a11; - worldTransform[2] = b00 * a02 + b01 * a12 + b02; - - worldTransform[3] = b10 * a00 + b11 * a10; - worldTransform[4] = b10 * a01 + b11 * a11; - worldTransform[5] = b10 * a02 + b11 * a12 + b12; - - // because we are using affine transformation, we can optimise the matrix concatenation process.. wooo! - // mat3.multiply(this.localTransform, this.parent.worldTransform, this.worldTransform); - this.worldAlpha = this.alpha * this.parent.worldAlpha; - -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * A DisplayObjectContainer represents a collection of display objects. - * It is the base class of all display objects that act as a container for other objects. - * - * @class DisplayObjectContainer - * @extends DisplayObject - * @constructor - */ -PIXI.DisplayObjectContainer = function() -{ - PIXI.DisplayObject.call( this ); - - /** - * [read-only] The of children of this container. - * - * @property children - * @type Array - * @readOnly - */ - this.children = []; -} - -// constructor -PIXI.DisplayObjectContainer.prototype = Object.create( PIXI.DisplayObject.prototype ); -PIXI.DisplayObjectContainer.prototype.constructor = PIXI.DisplayObjectContainer; - -//TODO make visible a getter setter -/* -Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'visible', { - get: function() { - return this._visible; - }, - set: function(value) { - this._visible = value; - - } -});*/ - -/** - * Adds a child to the container. - * - * @method addChild - * @param child {DisplayObject} The DisplayObject to add to the container - */ -PIXI.DisplayObjectContainer.prototype.addChild = function(child) -{ - if(child.parent != undefined) - { - - //// COULD BE THIS??? - child.parent.removeChild(child); - // return; - } - - child.parent = this; - child.childIndex = this.children.length; - - this.children.push(child); - - // updae the stage refference.. - - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = this.stage; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // LINKED LIST // - - // modify the list.. - var childFirst = child.first - var childLast = child.last; - var nextObject; - var previousObject; - - // this could be wrong if there is a filter?? - if(this.filter) - { - previousObject = this.last._iPrev; - } - else - { - previousObject = this.last; - } - - nextObject = previousObject._iNext; - - // always true in this case - //this.last = child.last; - // need to make sure the parents last is updated too - var updateLast = this; - var prevLast = previousObject; - - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = child.last; - } - updateLast = updateLast.parent; - } - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - // need to remove any render groups.. - if(this.__renderGroup) - { - // being used by a renderTexture.. if it exists then it must be from a render texture; - if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child); - // add them to the new render group.. - this.__renderGroup.addDisplayObjectAndChildren(child); - } - -} - -/** - * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown - * - * @method addChildAt - * @param child {DisplayObject} The child to add - * @param index {Number} The index to place the child in - */ -PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index) -{ - if(index >= 0 && index <= this.children.length) - { - if(child.parent != undefined) - { - child.parent.removeChild(child); - } - child.parent = this; - - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = this.stage; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // modify the list.. - var childFirst = child.first - var childLast = child.last; - var nextObject; - var previousObject; - - if(index == this.children.length) - { - previousObject = this.last; - var updateLast = this;//.parent; - var prevLast = this.last; - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = child.last; - } - updateLast = updateLast.parent; - } - } - else if(index == 0) - { - previousObject = this; - } - else - { - previousObject = this.children[index-1].last; - } - - nextObject = previousObject._iNext; - - // always true in this case - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - this.children.splice(index, 0, child); - // need to remove any render groups.. - if(this.__renderGroup) - { - // being used by a renderTexture.. if it exists then it must be from a render texture; - if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child); - // add them to the new render group.. - this.__renderGroup.addDisplayObjectAndChildren(child); - } - - } - else - { - throw new Error(child + " The index "+ index +" supplied is out of bounds " + this.children.length); - } -} - -/** - * [NYI] Swaps the depth of 2 displayObjects - * - * @method swapChildren - * @param child {DisplayObject} - * @param child2 {DisplayObject} - * @private - */ -PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2) -{ - /* - * this funtion needs to be recoded.. - * can be done a lot faster.. - */ - return; - - // need to fix this function :/ - /* - // TODO I already know this?? - var index = this.children.indexOf( child ); - var index2 = this.children.indexOf( child2 ); - - if ( index !== -1 && index2 !== -1 ) - { - // cool - - /* - if(this.stage) - { - // this is to satisfy the webGL batching.. - // TODO sure there is a nicer way to achieve this! - this.stage.__removeChild(child); - this.stage.__removeChild(child2); - - this.stage.__addChild(child); - this.stage.__addChild(child2); - } - - // swap the positions.. - this.children[index] = child2; - this.children[index2] = child; - - } - else - { - throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this); - }*/ -} - -/** - * Returns the Child at the specified index - * - * @method getChildAt - * @param index {Number} The index to get the child from - */ -PIXI.DisplayObjectContainer.prototype.getChildAt = function(index) -{ - if(index >= 0 && index < this.children.length) - { - return this.children[index]; - } - else - { - throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this); - } -} - -/** - * Removes a child from the container. - * - * @method removeChild - * @param child {DisplayObject} The DisplayObject to remove - */ -PIXI.DisplayObjectContainer.prototype.removeChild = function(child) -{ - var index = this.children.indexOf( child ); - if ( index !== -1 ) - { - // unlink // - // modify the list.. - var childFirst = child.first - var childLast = child.last; - - var nextObject = childLast._iNext; - var previousObject = childFirst._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - previousObject._iNext = nextObject; - - if(this.last == childLast) - { - var tempLast = childFirst._iPrev; - // need to make sure the parents last is updated too - var updateLast = this; - while(updateLast.last == childLast.last) - { - updateLast.last = tempLast; - updateLast = updateLast.parent; - if(!updateLast)break; - } - } - - childLast._iNext = null; - childFirst._iPrev = null; - - // update the stage reference.. - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = null; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // webGL trim - if(child.__renderGroup) - { - child.__renderGroup.removeDisplayObjectAndChildren(child); - } - - child.parent = undefined; - this.children.splice( index, 1 ); - } - else - { - throw new Error(child + " The supplied DisplayObject must be a child of the caller " + this); - } -} - -/* - * Updates the container's children's transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.DisplayObjectContainer.prototype.updateTransform = function() -{ - if(!this.visible)return; - - PIXI.DisplayObject.prototype.updateTransform.call( this ); - - for(var i=0,j=this.children.length; i} an array of {Texture} objects that make up the animation - */ -PIXI.MovieClip = function(textures) -{ - PIXI.Sprite.call(this, textures[0]); - - /** - * The array of textures that make up the animation - * - * @property textures - * @type Array - */ - this.textures = textures; - - /** - * The speed that the MovieClip will play at. Higher is faster, lower is slower - * - * @property animationSpeed - * @type Number - * @default 1 - */ - this.animationSpeed = 1; - - /** - * Whether or not the movie clip repeats after playing. - * - * @property loop - * @type Boolean - * @default true - */ - this.loop = true; - - /** - * Function to call when a MovieClip finishes playing - * - * @property onComplete - * @type Function - */ - this.onComplete = null; - - /** - * [read-only] The index MovieClips current frame (this may not have to be a whole number) - * - * @property currentFrame - * @type Number - * @default 0 - * @readOnly - */ - this.currentFrame = 0; - - /** - * [read-only] Indicates if the MovieClip is currently playing - * - * @property playing - * @type Boolean - * @readOnly - */ - this.playing = false; -} - -// constructor -PIXI.MovieClip.prototype = Object.create( PIXI.Sprite.prototype ); -PIXI.MovieClip.prototype.constructor = PIXI.MovieClip; - -/** - * Stops the MovieClip - * - * @method stop - */ -PIXI.MovieClip.prototype.stop = function() -{ - this.playing = false; -} - -/** - * Plays the MovieClip - * - * @method play - */ -PIXI.MovieClip.prototype.play = function() -{ - this.playing = true; -} - -/** - * Stops the MovieClip and goes to a specific frame - * - * @method gotoAndStop - * @param frameNumber {Number} frame index to stop at - */ -PIXI.MovieClip.prototype.gotoAndStop = function(frameNumber) -{ - this.playing = false; - this.currentFrame = frameNumber; - var round = (this.currentFrame + 0.5) | 0; - this.setTexture(this.textures[round % this.textures.length]); -} - -/** - * Goes to a specific frame and begins playing the MovieClip - * - * @method gotoAndPlay - * @param frameNumber {Number} frame index to start at - */ -PIXI.MovieClip.prototype.gotoAndPlay = function(frameNumber) -{ - this.currentFrame = frameNumber; - this.playing = true; -} - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.MovieClip.prototype.updateTransform = function() -{ - PIXI.Sprite.prototype.updateTransform.call(this); - - if(!this.playing)return; - - this.currentFrame += this.animationSpeed; - var round = (this.currentFrame + 0.5) | 0; - if(this.loop || round < this.textures.length) - { - this.setTexture(this.textures[round % this.textures.length]); - } - else if(round >= this.textures.length) - { - this.gotoAndStop(this.textures.length - 1); - if(this.onComplete) - { - this.onComplete(); - } - } -} -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - - -PIXI.FilterBlock = function(mask) -{ - this.graphics = mask - this.visible = true; - this.renderable = true; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Text Object will create a line(s) of text to split a line you can use "\n" - * - * @class Text - * @extends Sprite - * @constructor - * @param text {String} The copy that you would like the text to display - * @param [style] {Object} The style parameters - * @param [style.font] {String} default "bold 20pt Arial" The style and size of the font - * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00" - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - * @param [style.stroke] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00" - * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke) - * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used - * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap - */ -PIXI.Text = function(text, style) -{ - this.canvas = document.createElement("canvas"); - this.context = this.canvas.getContext("2d"); - PIXI.Sprite.call(this, PIXI.Texture.fromCanvas(this.canvas)); - - this.setText(text); - this.setStyle(style); - - this.updateText(); - this.dirty = false; -}; - -// constructor -PIXI.Text.prototype = Object.create(PIXI.Sprite.prototype); -PIXI.Text.prototype.constructor = PIXI.Text; - -/** - * Set the style of the text - * - * @method setStyle - * @param [style] {Object} The style parameters - * @param [style.font="bold 20pt Arial"] {String} The style and size of the font - * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00" - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - * @param [style.stroke="black"] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00" - * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke) - * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used - * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap - */ -PIXI.Text.prototype.setStyle = function(style) -{ - style = style || {}; - style.font = style.font || "bold 20pt Arial"; - style.fill = style.fill || "black"; - style.align = style.align || "left"; - style.stroke = style.stroke || "black"; //provide a default, see: https://github.com/GoodBoyDigital/pixi.js/issues/136 - style.strokeThickness = style.strokeThickness || 0; - style.wordWrap = style.wordWrap || false; - style.wordWrapWidth = style.wordWrapWidth || 100; - this.style = style; - this.dirty = true; -}; - -/** - * Set the copy for the text object. To split a line you can use "\n" - * - * @methos setText - * @param {String} text The copy that you would like the text to display - */ -PIXI.Sprite.prototype.setText = function(text) -{ - this.text = text.toString() || " "; - this.dirty = true; -}; - -/** - * Renders text - * - * @method updateText - * @private - */ -PIXI.Text.prototype.updateText = function() -{ - this.context.font = this.style.font; - - var outputText = this.text; - - // word wrap - // preserve original text - if(this.style.wordWrap)outputText = this.wordWrap(this.text); - - //split text into lines - var lines = outputText.split(/(?:\r\n|\r|\n)/); - - //calculate text width - var lineWidths = []; - var maxLineWidth = 0; - for (var i = 0; i < lines.length; i++) - { - var lineWidth = this.context.measureText(lines[i]).width; - lineWidths[i] = lineWidth; - maxLineWidth = Math.max(maxLineWidth, lineWidth); - } - this.canvas.width = maxLineWidth + this.style.strokeThickness; - - //calculate text height - var lineHeight = this.determineFontHeight("font: " + this.style.font + ";") + this.style.strokeThickness; - this.canvas.height = lineHeight * lines.length; - - //set canvas text styles - this.context.fillStyle = this.style.fill; - this.context.font = this.style.font; - - this.context.strokeStyle = this.style.stroke; - this.context.lineWidth = this.style.strokeThickness; - - this.context.textBaseline = "top"; - - //draw lines line by line - for (i = 0; i < lines.length; i++) - { - var linePosition = new PIXI.Point(this.style.strokeThickness / 2, this.style.strokeThickness / 2 + i * lineHeight); - - if(this.style.align == "right") - { - linePosition.x += maxLineWidth - lineWidths[i]; - } - else if(this.style.align == "center") - { - linePosition.x += (maxLineWidth - lineWidths[i]) / 2; - } - - if(this.style.stroke && this.style.strokeThickness) - { - this.context.strokeText(lines[i], linePosition.x, linePosition.y); - } - - if(this.style.fill) - { - this.context.fillText(lines[i], linePosition.x, linePosition.y); - } - } - - this.updateTexture(); -}; - -/** - * Updates texture size based on canvas size - * - * @method updateTexture - * @private - */ -PIXI.Text.prototype.updateTexture = function() -{ - this.texture.baseTexture.width = this.canvas.width; - this.texture.baseTexture.height = this.canvas.height; - this.texture.frame.width = this.canvas.width; - this.texture.frame.height = this.canvas.height; - - this._width = this.canvas.width; - this._height = this.canvas.height; - - PIXI.texturesToUpdate.push(this.texture.baseTexture); -}; - -/** - * Updates the transfor of this object - * - * @method updateTransform - * @private - */ -PIXI.Text.prototype.updateTransform = function() -{ - if(this.dirty) - { - this.updateText(); - this.dirty = false; - } - - PIXI.Sprite.prototype.updateTransform.call(this); -}; - -/* - * http://stackoverflow.com/users/34441/ellisbben - * great solution to the problem! - * - * @method determineFontHeight - * @param fontStyle {Object} - * @private - */ -PIXI.Text.prototype.determineFontHeight = function(fontStyle) -{ - // build a little reference dictionary so if the font style has been used return a - // cached version... - var result = PIXI.Text.heightCache[fontStyle]; - - if(!result) - { - var body = document.getElementsByTagName("body")[0]; - var dummy = document.createElement("div"); - var dummyText = document.createTextNode("M"); - dummy.appendChild(dummyText); - dummy.setAttribute("style", fontStyle + ';position:absolute;top:0;left:0'); - body.appendChild(dummy); - - result = dummy.offsetHeight; - PIXI.Text.heightCache[fontStyle] = result; - - body.removeChild(dummy); - } - - return result; -}; - -/** - * A Text Object will apply wordwrap - * - * @method wordWrap - * @param text {String} - * @private - */ -PIXI.Text.prototype.wordWrap = function(text) -{ - // search good wrap position - var searchWrapPos = function(ctx, text, start, end, wrapWidth) - { - var p = Math.floor((end-start) / 2) + start; - if(p == start) { - return 1; - } - - if(ctx.measureText(text.substring(0,p)).width <= wrapWidth) - { - if(ctx.measureText(text.substring(0,p+1)).width > wrapWidth) - { - return p; - } - else - { - return arguments.callee(ctx, text, p, end, wrapWidth); - } - } - else - { - return arguments.callee(ctx, text, start, p, wrapWidth); - } - }; - - var lineWrap = function(ctx, text, wrapWidth) - { - if(ctx.measureText(text).width <= wrapWidth || text.length < 1) - { - return text; - } - var pos = searchWrapPos(ctx, text, 0, text.length, wrapWidth); - return text.substring(0, pos) + "\n" + arguments.callee(ctx, text.substring(pos), wrapWidth); - }; - - var result = ""; - var lines = text.split("\n"); - for (var i = 0; i < lines.length; i++) - { - result += lineWrap(this.context, lines[i], this.style.wordWrapWidth) + "\n"; - } - - return result; -}; - -/** - * Destroys this text object - * - * @method destroy - * @param destroyTexture {Boolean} - */ -PIXI.Text.prototype.destroy = function(destroyTexture) -{ - if(destroyTexture) - { - this.texture.destroy(); - } - -}; - -PIXI.Text.heightCache = {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Text Object will create a line(s) of text using bitmap font. To split a line you can use "\n", "\r" or "\r\n" - * You can generate the fnt files using - * http://www.angelcode.com/products/bmfont/ for windows or - * http://www.bmglyph.com/ for mac. - * - * @class BitmapText - * @extends DisplayObjectContainer - * @constructor - * @param text {String} The copy that you would like the text to display - * @param style {Object} The style parameters - * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously) - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - */ -PIXI.BitmapText = function(text, style) -{ - PIXI.DisplayObjectContainer.call(this); - - this.setText(text); - this.setStyle(style); - this.updateText(); - this.dirty = false - -}; - -// constructor -PIXI.BitmapText.prototype = Object.create(PIXI.DisplayObjectContainer.prototype); -PIXI.BitmapText.prototype.constructor = PIXI.BitmapText; - -/** - * Set the copy for the text object - * - * @method setText - * @param text {String} The copy that you would like the text to display - */ -PIXI.BitmapText.prototype.setText = function(text) -{ - this.text = text || " "; - this.dirty = true; -}; - -/** - * Set the style of the text - * - * @method setStyle - * @param style {Object} The style parameters - * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously) - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - */ -PIXI.BitmapText.prototype.setStyle = function(style) -{ - style = style || {}; - style.align = style.align || "left"; - this.style = style; - - var font = style.font.split(" "); - this.fontName = font[font.length - 1]; - this.fontSize = font.length >= 2 ? parseInt(font[font.length - 2], 10) : PIXI.BitmapText.fonts[this.fontName].size; - - this.dirty = true; -}; - -/** - * Renders text - * - * @method updateText - * @private - */ -PIXI.BitmapText.prototype.updateText = function() -{ - var data = PIXI.BitmapText.fonts[this.fontName]; - var pos = new PIXI.Point(); - var prevCharCode = null; - var chars = []; - var maxLineWidth = 0; - var lineWidths = []; - var line = 0; - var scale = this.fontSize / data.size; - for(var i = 0; i < this.text.length; i++) - { - var charCode = this.text.charCodeAt(i); - if(/(?:\r\n|\r|\n)/.test(this.text.charAt(i))) - { - lineWidths.push(pos.x); - maxLineWidth = Math.max(maxLineWidth, pos.x); - line++; - - pos.x = 0; - pos.y += data.lineHeight; - prevCharCode = null; - continue; - } - - var charData = data.chars[charCode]; - if(!charData) continue; - - if(prevCharCode && charData[prevCharCode]) - { - pos.x += charData.kerning[prevCharCode]; - } - chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); - pos.x += charData.xAdvance; - - prevCharCode = charCode; - } - - lineWidths.push(pos.x); - maxLineWidth = Math.max(maxLineWidth, pos.x); - - var lineAlignOffsets = []; - for(i = 0; i <= line; i++) - { - var alignOffset = 0; - if(this.style.align == "right") - { - alignOffset = maxLineWidth - lineWidths[i]; - } - else if(this.style.align == "center") - { - alignOffset = (maxLineWidth - lineWidths[i]) / 2; - } - lineAlignOffsets.push(alignOffset); - } - - for(i = 0; i < chars.length; i++) - { - var c = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode); - c.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; - c.position.y = chars[i].position.y * scale; - c.scale.x = c.scale.y = scale; - this.addChild(c); - } - - this.width = pos.x * scale; - this.height = (pos.y + data.lineHeight) * scale; -}; - -/** - * Updates the transfor of this object - * - * @method updateTransform - * @private - */ -PIXI.BitmapText.prototype.updateTransform = function() -{ - if(this.dirty) - { - while(this.children.length > 0) - { - this.removeChild(this.getChildAt(0)); - } - this.updateText(); - - this.dirty = false; - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call(this); -}; - -PIXI.BitmapText.fonts = {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - - -/** - * The interaction manager deals with mouse and touch events. Any DisplayObject can be interactive - * This manager also supports multitouch. - * - * @class InteractionManager - * @constructor - * @param stage {Stage} The stage to handle interactions - */ -PIXI.InteractionManager = function(stage) -{ - /** - * a refference to the stage - * - * @property stage - * @type Stage - */ - this.stage = stage; - - /** - * the mouse data - * - * @property mouse - * @type InteractionData - */ - this.mouse = new PIXI.InteractionData(); - - /** - * an object that stores current touches (InteractionData) by id reference - * - * @property touchs - * @type Object - */ - this.touchs = {}; - - // helpers - this.tempPoint = new PIXI.Point(); - //this.tempMatrix = mat3.create(); - - this.mouseoverEnabled = true; - - //tiny little interactiveData pool! - this.pool = []; - - this.interactiveItems = []; - - this.last = 0; -} - -// constructor -PIXI.InteractionManager.prototype.constructor = PIXI.InteractionManager; - -/** - * Collects an interactive sprite recursively to have their interactions managed - * - * @method collectInteractiveSprite - * @param displayObject {DisplayObject} the displayObject to collect - * @param iParent {DisplayObject} - * @private - */ -PIXI.InteractionManager.prototype.collectInteractiveSprite = function(displayObject, iParent) -{ - var children = displayObject.children; - var length = children.length; - - /// make an interaction tree... {item.__interactiveParent} - for (var i = length-1; i >= 0; i--) - { - var child = children[i]; - - if(child.visible) { - // push all interactive bits - if(child.interactive) - { - iParent.interactiveChildren = true; - //child.__iParent = iParent; - this.interactiveItems.push(child); - - if(child.children.length > 0) - { - this.collectInteractiveSprite(child, child); - } - } - else - { - child.__iParent = null; - - if(child.children.length > 0) - { - this.collectInteractiveSprite(child, iParent); - } - } - } - } -} - -/** - * Sets the target for event delegation - * - * @method setTarget - * @param target {WebGLRenderer|CanvasRenderer} the renderer to bind events to - * @private - */ -PIXI.InteractionManager.prototype.setTarget = function(target) -{ - if (window.navigator.msPointerEnabled) - { - // time to remove some of that zoom in ja.. - target.view.style["-ms-content-zooming"] = "none"; - target.view.style["-ms-touch-action"] = "none" - - // DO some window specific touch! - } - - this.target = target; - target.view.addEventListener('mousemove', this.onMouseMove.bind(this), true); - target.view.addEventListener('mousedown', this.onMouseDown.bind(this), true); - document.body.addEventListener('mouseup', this.onMouseUp.bind(this), true); - target.view.addEventListener('mouseout', this.onMouseUp.bind(this), true); - - // aint no multi touch just yet! - target.view.addEventListener("touchstart", this.onTouchStart.bind(this), true); - target.view.addEventListener("touchend", this.onTouchEnd.bind(this), true); - target.view.addEventListener("touchmove", this.onTouchMove.bind(this), true); -} - -/** - * updates the state of interactive objects - * - * @method update - * @private - */ -PIXI.InteractionManager.prototype.update = function() -{ - if(!this.target)return; - - // frequency of 30fps?? - var now = Date.now(); - var diff = now - this.last; - diff = (diff * 30) / 1000; - if(diff < 1)return; - this.last = now; - // - - // ok.. so mouse events?? - // yes for now :) - // OPTIMSE - how often to check?? - if(this.dirty) - { - this.dirty = false; - - var len = this.interactiveItems.length; - - for (var i=0; i < len; i++) { - this.interactiveItems[i].interactiveChildren = false; - } - - this.interactiveItems = []; - - if(this.stage.interactive)this.interactiveItems.push(this.stage); - // go through and collect all the objects that are interactive.. - this.collectInteractiveSprite(this.stage, this.stage); - } - - // loop through interactive objects! - var length = this.interactiveItems.length; - - this.target.view.style.cursor = "default"; - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - if(!item.visible)continue; - - // OPTIMISATION - only calculate every time if the mousemove function exists.. - // OK so.. does the object have any other interactive functions? - // hit-test the clip! - - - if(item.mouseover || item.mouseout || item.buttonMode) - { - // ok so there are some functions so lets hit test it.. - item.__hit = this.hitTest(item, this.mouse); - this.mouse.target = item; - // ok so deal with interactions.. - // loks like there was a hit! - if(item.__hit) - { - if(item.buttonMode)this.target.view.style.cursor = "pointer"; - - if(!item.__isOver) - { - - if(item.mouseover)item.mouseover(this.mouse); - item.__isOver = true; - } - } - else - { - if(item.__isOver) - { - // roll out! - if(item.mouseout)item.mouseout(this.mouse); - item.__isOver = false; - } - } - } - - // ---> - } -} - -/** - * Is called when the mouse moves accross the renderer element - * - * @method onMouseMove - * @param event {Event} The DOM event of the mouse moving - * @private - */ -PIXI.InteractionManager.prototype.onMouseMove = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - // TODO optimize by not check EVERY TIME! maybe half as often? // - var rect = this.target.view.getBoundingClientRect(); - - this.mouse.global.x = (event.clientX - rect.left) * (this.target.width / rect.width); - this.mouse.global.y = (event.clientY - rect.top) * ( this.target.height / rect.height); - - var length = this.interactiveItems.length; - var global = this.mouse.global; - - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mousemove) - { - //call the function! - item.mousemove(this.mouse); - } - } -} - -/** - * Is called when the mouse button is pressed down on the renderer element - * - * @method onMouseDown - * @param event {Event} The DOM event of a mouse button being pressed down - * @private - */ -PIXI.InteractionManager.prototype.onMouseDown = function(event) -{ - event.preventDefault(); - this.mouse.originalEvent = event || window.event; //IE uses window.event - - // loop through inteaction tree... - // hit test each item! -> - // get interactive items under point?? - //stage.__i - var length = this.interactiveItems.length; - var global = this.mouse.global; - - var index = 0; - var parent = this.stage; - - // while - // hit test - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mousedown || item.click) - { - item.__mouseIsDown = true; - item.__hit = this.hitTest(item, this.mouse); - - if(item.__hit) - { - //call the function! - if(item.mousedown)item.mousedown(this.mouse); - item.__isDown = true; - - // just the one! - if(!item.interactiveChildren)break; - } - } - } -} - -/** - * Is called when the mouse button is released on the renderer element - * - * @method onMouseUp - * @param event {Event} The DOM event of a mouse button being released - * @private - */ -PIXI.InteractionManager.prototype.onMouseUp = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - - var global = this.mouse.global; - - - var length = this.interactiveItems.length; - var up = false; - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mouseup || item.mouseupoutside || item.click) - { - item.__hit = this.hitTest(item, this.mouse); - - if(item.__hit && !up) - { - //call the function! - if(item.mouseup) - { - item.mouseup(this.mouse); - } - if(item.__isDown) - { - if(item.click)item.click(this.mouse); - } - - if(!item.interactiveChildren)up = true; - } - else - { - if(item.__isDown) - { - if(item.mouseupoutside)item.mouseupoutside(this.mouse); - } - } - - item.__isDown = false; - } - } -} - -/** - * Tests if the current mouse coords hit a sprite - * - * @method hitTest - * @param item {DisplayObject} The displayObject to test for a hit - * @param interactionData {InteractionData} The interactiondata object to update in the case of a hit - * @private - */ -PIXI.InteractionManager.prototype.hitTest = function(item, interactionData) -{ - var global = interactionData.global; - - if(!item.visible)return false; - - var isSprite = (item instanceof PIXI.Sprite), - worldTransform = item.worldTransform, - a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2], - a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5], - id = 1 / (a00 * a11 + a01 * -a10), - x = a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id, - y = a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id; - - interactionData.target = item; - - //a sprite or display object with a hit area defined - if(item.hitArea && item.hitArea.contains) { - if(item.hitArea.contains(x, y)) { - //if(isSprite) - interactionData.target = item; - - return true; - } - - return false; - } - // a sprite with no hitarea defined - else if(isSprite) - { - var width = item.texture.frame.width, - height = item.texture.frame.height, - x1 = -width * item.anchor.x, - y1; - - if(x > x1 && x < x1 + width) - { - y1 = -height * item.anchor.y; - - if(y > y1 && y < y1 + height) - { - // set the target property if a hit is true! - interactionData.target = item - return true; - } - } - } - - var length = item.children.length; - - for (var i = 0; i < length; i++) - { - var tempItem = item.children[i]; - var hit = this.hitTest(tempItem, interactionData); - if(hit) - { - // hmm.. TODO SET CORRECT TARGET? - interactionData.target = item - return true; - } - } - - return false; -} - -/** - * Is called when a touch is moved accross the renderer element - * - * @method onTouchMove - * @param event {Event} The DOM event of a touch moving accross the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchMove = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - var rect = this.target.view.getBoundingClientRect(); - var changedTouches = event.changedTouches; - - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - var touchData = this.touchs[touchEvent.identifier]; - - // update the touch position - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - } - - var length = this.interactiveItems.length; - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - if(item.touchmove)item.touchmove(touchData); - } -} - -/** - * Is called when a touch is started on the renderer element - * - * @method onTouchStart - * @param event {Event} The DOM event of a touch starting on the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchStart = function(event) -{ - event.preventDefault(); - this.mouse.originalEvent = event || window.event; //IE uses window.event - - var rect = this.target.view.getBoundingClientRect(); - - var changedTouches = event.changedTouches; - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - - var touchData = this.pool.pop(); - if(!touchData)touchData = new PIXI.InteractionData(); - - this.touchs[touchEvent.identifier] = touchData; - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - - var length = this.interactiveItems.length; - - for (var j = 0; j < length; j++) - { - var item = this.interactiveItems[j]; - - if(item.touchstart || item.tap) - { - item.__hit = this.hitTest(item, touchData); - - if(item.__hit) - { - //call the function! - if(item.touchstart)item.touchstart(touchData); - item.__isDown = true; - item.__touchData = touchData; - - if(!item.interactiveChildren)break; - } - } - } - } -} - -/** - * Is called when a touch is ended on the renderer element - * - * @method onTouchEnd - * @param event {Event} The DOM event of a touch ending on the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchEnd = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - var rect = this.target.view.getBoundingClientRect(); - var changedTouches = event.changedTouches; - - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - var touchData = this.touchs[touchEvent.identifier]; - var up = false; - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - - var length = this.interactiveItems.length; - for (var j = 0; j < length; j++) - { - var item = this.interactiveItems[j]; - var itemTouchData = item.__touchData; // <-- Here! - item.__hit = this.hitTest(item, touchData); - - if(itemTouchData == touchData) - { - // so this one WAS down... - - // hitTest?? - - if(item.touchend || item.tap) - { - if(item.__hit && !up) - { - if(item.touchend)item.touchend(touchData); - if(item.__isDown) - { - if(item.tap)item.tap(touchData); - } - - if(!item.interactiveChildren)up = true; - } - else - { - if(item.__isDown) - { - if(item.touchendoutside)item.touchendoutside(touchData); - } - } - - item.__isDown = false; - } - - item.__touchData = null; - - } - else - { - - } - } - // remove the touch.. - this.pool.push(touchData); - this.touchs[touchEvent.identifier] = null; - } -} - -/** - * Holds all information related to an Interaction event - * - * @class InteractionData - * @constructor - */ -PIXI.InteractionData = function() -{ - /** - * This point stores the global coords of where the touch/mouse event happened - * - * @property global - * @type Point - */ - this.global = new PIXI.Point(); - - // this is here for legacy... but will remove - this.local = new PIXI.Point(); - - /** - * The target Sprite that was interacted with - * - * @property target - * @type Sprite - */ - this.target; - - /** - * When passed to an event handler, this will be the original DOM Event that was captured - * - * @property originalEvent - * @type Event - */ - this.originalEvent; -} - -/** - * This will return the local coords of the specified displayObject for this InteractionData - * - * @method getLocalPosition - * @param displayObject {DisplayObject} The DisplayObject that you would like the local coords off - * @return {Point} A point containing the coords of the InteractionData position relative to the DisplayObject - */ -PIXI.InteractionData.prototype.getLocalPosition = function(displayObject) -{ - var worldTransform = displayObject.worldTransform; - var global = this.global; - - // do a cheeky transform to get the mouse coords; - var a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2], - a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5], - id = 1 / (a00 * a11 + a01 * -a10); - // set the mouse coords... - return new PIXI.Point(a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id, - a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id) -} - -// constructor -PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Stage represents the root of the display tree. Everything connected to the stage is rendered - * - * @class Stage - * @extends DisplayObjectContainer - * @constructor - * @param backgroundColor {Number} the background color of the stage, easiest way to pass this in is in hex format - * like: 0xFFFFFF for white - * @param interactive {Boolean} enable / disable interaction (default is false) - */ -PIXI.Stage = function(backgroundColor, interactive) -{ - PIXI.DisplayObjectContainer.call( this ); - - /** - * [read-only] Current transform of the object based on world (parent) factors - * - * @property worldTransform - * @type Mat3 - * @readOnly - * @private - */ - this.worldTransform = PIXI.mat3.create(); - - /** - * Whether or not the stage is interactive - * - * @property interactive - * @type Boolean - */ - this.interactive = interactive; - - /** - * The interaction manage for this stage, manages all interactive activity on the stage - * - * @property interactive - * @type InteractionManager - */ - this.interactionManager = new PIXI.InteractionManager(this); - - /** - * Whether the stage is dirty and needs to have interactions updated - * - * @property dirty - * @type Boolean - * @private - */ - this.dirty = true; - - this.__childrenAdded = []; - this.__childrenRemoved = []; - - //the stage is it's own stage - this.stage = this; - - //optimize hit detection a bit - this.stage.hitArea = new PIXI.Rectangle(0,0,100000, 100000); - - this.setBackgroundColor(backgroundColor); - this.worldVisible = true; -} - -// constructor -PIXI.Stage.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Stage.prototype.constructor = PIXI.Stage; - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.Stage.prototype.updateTransform = function() -{ - this.worldAlpha = 1; - - for(var i=0,j=this.children.length; i> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; -} - -/** - * A polyfill for Function.prototype.bind - * - * @method bind - */ -if (typeof Function.prototype.bind != 'function') { - Function.prototype.bind = (function () { - var slice = Array.prototype.slice; - return function (thisArg) { - var target = this, boundArgs = slice.call(arguments, 1); - - if (typeof target != 'function') throw new TypeError(); - - function bound() { - var args = boundArgs.concat(slice.call(arguments)); - target.apply(this instanceof bound ? this : thisArg, args); - } - - bound.prototype = (function F(proto) { - proto && (F.prototype = proto); - if (!(this instanceof F)) return new F; - })(target.prototype); - - return bound; - }; - })(); -} - -/** - * A wrapper for ajax requests to be handled cross browser - * - * @class AjaxRequest - * @constructor - */ -var AjaxRequest = PIXI.AjaxRequest = function() -{ - var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE - - if (window.ActiveXObject) - { //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken) - for (var i=0; i>>>>>>>>") - console.log("_") - var safe = 0; - var tmp = item.first; - console.log(tmp); - - while(tmp._iNext) - { - safe++; -// console.log(tmp.childIndex + tmp); - tmp = tmp._iNext; - console.log(tmp);//.childIndex); - // console.log(tmp); - - if(safe > 100) - { - console.log("BREAK") - break - } - } -} - - - - - - -/** - * https://github.com/mrdoob/eventtarget.js/ - * THankS mr DOob! - */ - -/** - * Adds event emitter functionality to a class - * - * @class EventTarget - * @example - * function MyEmitter() { - * PIXI.EventTarget.call(this); //mixes in event target stuff - * } - * - * var em = new MyEmitter(); - * em.emit({ type: 'eventName', data: 'some data' }); - */ -PIXI.EventTarget = function () { - - var listeners = {}; - - this.addEventListener = this.on = function ( type, listener ) { - - - if ( listeners[ type ] === undefined ) { - - listeners[ type ] = []; - - } - - if ( listeners[ type ].indexOf( listener ) === - 1 ) { - - listeners[ type ].push( listener ); - } - - }; - - this.dispatchEvent = this.emit = function ( event ) { - - for ( var listener in listeners[ event.type ] ) { - - listeners[ event.type ][ listener ]( event ); - - } - - }; - - this.removeEventListener = this.off = function ( type, listener ) { - - var index = listeners[ type ].indexOf( listener ); - - if ( index !== - 1 ) { - - listeners[ type ].splice( index, 1 ); - - } - - }; - -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * This helper function will automatically detect which renderer you should be using. - * WebGL is the preferred renderer as it is a lot fastest. If webGL is not supported by - * the browser then this function will return a canvas renderer - * - * @method autoDetectRenderer - * @static - * @param width {Number} the width of the renderers view - * @param height {Number} the height of the renderers view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - */ -PIXI.autoDetectRenderer = function(width, height, view, transparent) -{ - if(!width)width = 800; - if(!height)height = 600; - - // BORROWED from Mr Doob (mrdoob.com) - var webgl = ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )(); - - //console.log(webgl); - if( webgl ) - { - return new PIXI.WebGLRenderer(width, height, view, transparent); - } - - return new PIXI.CanvasRenderer(width, height, view, transparent); -}; - - - -/* - PolyK library - url: http://polyk.ivank.net - Released under MIT licence. - - Copyright (c) 2012 Ivan Kuckir - - 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. - - This is an amazing lib! - - slightly modified by mat groves (matgroves.com); -*/ - -PIXI.PolyK = {}; - -/** - * Triangulates shapes for webGL graphic fills - * - * @method Triangulate - * @namespace PolyK - * @constructor - */ -PIXI.PolyK.Triangulate = function(p) -{ - var sign = true; - - var n = p.length>>1; - if(n<3) return []; - var tgs = []; - var avl = []; - for(var i=0; i 3) - { - var i0 = avl[(i+0)%al]; - var i1 = avl[(i+1)%al]; - var i2 = avl[(i+2)%al]; - - var ax = p[2*i0], ay = p[2*i0+1]; - var bx = p[2*i1], by = p[2*i1+1]; - var cx = p[2*i2], cy = p[2*i2+1]; - - var earFound = false; - if(PIXI.PolyK._convex(ax, ay, bx, by, cx, cy, sign)) - { - earFound = true; - for(var j=0; j 3*al) - { - // need to flip flip reverse it! - // reset! - if(sign) - { - var tgs = []; - avl = []; - for(var i=0; i= 0) && (v >= 0) && (u + v < 1); -} - -/** - * Checks if a shape is convex - * - * @class _convex - * @namespace PolyK - * @private - */ -PIXI.PolyK._convex = function(ax, ay, bx, by, cx, cy, sign) -{ - return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) == sign; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/* - * the default suoer fast shader! - */ - -PIXI.shaderFragmentSrc = [ - "precision mediump float;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "uniform sampler2D uSampler;", - "void main(void) {", - "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));", - "gl_FragColor = gl_FragColor * vColor;", - "}" -]; - -PIXI.shaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec2 aTextureCoord;", - "attribute float aColor;", - //"uniform mat4 uMVMatrix;", - - "uniform vec2 projectionVector;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "void main(void) {", - // "gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0, 1.0);", - "gl_Position = vec4( aVertexPosition.x / projectionVector.x -1.0, aVertexPosition.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vTextureCoord = aTextureCoord;", - "vColor = aColor;", - "}" -]; - -/* - * the triangle strip shader.. - */ - -PIXI.stripShaderFragmentSrc = [ - "precision mediump float;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "uniform float alpha;", - "uniform sampler2D uSampler;", - "void main(void) {", - "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));", - "gl_FragColor = gl_FragColor * alpha;", - "}" -]; - - -PIXI.stripShaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec2 aTextureCoord;", - "attribute float aColor;", - "uniform mat3 translationMatrix;", - "uniform vec2 projectionVector;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "void main(void) {", - "vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);", - "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vTextureCoord = aTextureCoord;", - "vColor = aColor;", - "}" -]; - - -/* - * primitive shader.. - */ - -PIXI.primitiveShaderFragmentSrc = [ - "precision mediump float;", - "varying vec4 vColor;", - "void main(void) {", - "gl_FragColor = vColor;", - "}" -]; - -PIXI.primitiveShaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec4 aColor;", - "uniform mat3 translationMatrix;", - "uniform vec2 projectionVector;", - "uniform float alpha;", - "varying vec4 vColor;", - "void main(void) {", - "vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);", - "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vColor = aColor * alpha;", - "}" -]; - -PIXI.initPrimitiveShader = function() -{ - var gl = PIXI.gl; - - var shaderProgram = PIXI.compileProgram(PIXI.primitiveShaderVertexSrc, PIXI.primitiveShaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, "translationMatrix"); - - shaderProgram.alpha = gl.getUniformLocation(shaderProgram, "alpha"); - - PIXI.primitiveProgram = shaderProgram; -} - -PIXI.initDefaultShader = function() -{ - var gl = this.gl; - var shaderProgram = PIXI.compileProgram(PIXI.shaderVertexSrc, PIXI.shaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord"); - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - // shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix"); - shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler"); - - PIXI.shaderProgram = shaderProgram; -} - -PIXI.initDefaultStripShader = function() -{ - var gl = this.gl; - var shaderProgram = PIXI.compileProgram(PIXI.stripShaderVertexSrc, PIXI.stripShaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord"); - shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, "translationMatrix"); - shaderProgram.alpha = gl.getUniformLocation(shaderProgram, "alpha"); - - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - - shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler"); - - PIXI.stripShaderProgram = shaderProgram; -} - -PIXI.CompileVertexShader = function(gl, shaderSrc) -{ - return PIXI._CompileShader(gl, shaderSrc, gl.VERTEX_SHADER); -} - -PIXI.CompileFragmentShader = function(gl, shaderSrc) -{ - return PIXI._CompileShader(gl, shaderSrc, gl.FRAGMENT_SHADER); -} - -PIXI._CompileShader = function(gl, shaderSrc, shaderType) -{ - var src = shaderSrc.join("\n"); - var shader = gl.createShader(shaderType); - gl.shaderSource(shader, src); - gl.compileShader(shader); - - if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { - alert(gl.getShaderInfoLog(shader)); - return null; - } - - return shader; -} - - -PIXI.compileProgram = function(vertexSrc, fragmentSrc) -{ - var gl = PIXI.gl; - var fragmentShader = PIXI.CompileFragmentShader(gl, fragmentSrc); - var vertexShader = PIXI.CompileVertexShader(gl, vertexSrc); - - var shaderProgram = gl.createProgram(); - - gl.attachShader(shaderProgram, vertexShader); - gl.attachShader(shaderProgram, fragmentShader); - gl.linkProgram(shaderProgram); - - if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) { - alert("Could not initialise shaders"); - } - - return shaderProgram; -} - - -PIXI.activateDefaultShader = function() -{ - var gl = PIXI.gl; - var shaderProgram = PIXI.shaderProgram; - - gl.useProgram(shaderProgram); - - - gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute); - gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute); - gl.enableVertexAttribArray(shaderProgram.colorAttribute); -} - - - -PIXI.activatePrimitiveShader = function() -{ - var gl = PIXI.gl; - - gl.disableVertexAttribArray(PIXI.shaderProgram.textureCoordAttribute); - gl.disableVertexAttribArray(PIXI.shaderProgram.colorAttribute); - - gl.useProgram(PIXI.primitiveProgram); - - gl.enableVertexAttribArray(PIXI.primitiveProgram.vertexPositionAttribute); - gl.enableVertexAttribArray(PIXI.primitiveProgram.colorAttribute); -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A set of functions used by the webGL renderer to draw the primitive graphics data - * - * @class CanvasGraphics - */ -PIXI.WebGLGraphics = function() -{ - -} - -/** - * Renders the graphics object - * - * @static - * @private - * @method renderGraphics - * @param graphics {Graphics} - * @param projection {Object} - */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) -{ - var gl = PIXI.gl; - - if(!graphics._webGL)graphics._webGL = {points:[], indices:[], lastIndex:0, - buffer:gl.createBuffer(), - indexBuffer:gl.createBuffer()}; - - if(graphics.dirty) - { - graphics.dirty = false; - - if(graphics.clearDirty) - { - graphics.clearDirty = false; - - graphics._webGL.lastIndex = 0; - graphics._webGL.points = []; - graphics._webGL.indices = []; - - } - - PIXI.WebGLGraphics.updateGraphics(graphics); - } - - - PIXI.activatePrimitiveShader(); - - // This could be speeded up fo sure! - var m = PIXI.mat3.clone(graphics.worldTransform); - - PIXI.mat3.transpose(m); - - // set the matrix transform for the - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - - gl.uniformMatrix3fv(PIXI.primitiveProgram.translationMatrix, false, m); - - gl.uniform2f(PIXI.primitiveProgram.projectionVector, projection.x, projection.y); - - gl.uniform1f(PIXI.primitiveProgram.alpha, graphics.worldAlpha); - - gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer); - - // WHY DOES THIS LINE NEED TO BE THERE??? - gl.vertexAttribPointer(PIXI.shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - // its not even used.. but need to be set or it breaks? - // only on pc though.. - - gl.vertexAttribPointer(PIXI.primitiveProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 4 * 6, 0); - gl.vertexAttribPointer(PIXI.primitiveProgram.colorAttribute, 4, gl.FLOAT, false,4 * 6, 2 * 4); - - // set the index buffer! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer); - - gl.drawElements(gl.TRIANGLE_STRIP, graphics._webGL.indices.length, gl.UNSIGNED_SHORT, 0 ); - - // return to default shader... - PIXI.activateDefaultShader(); -} - -/** - * Updates the graphics object - * - * @static - * @private - * @method updateGraphics - * @param graphics {Graphics} - */ -PIXI.WebGLGraphics.updateGraphics = function(graphics) -{ - for (var i=graphics._webGL.lastIndex; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - - if(data.type == PIXI.Graphics.POLY) - { - if(data.fill) - { - if(data.points.length>3) - PIXI.WebGLGraphics.buildPoly(data, graphics._webGL); - } - - if(data.lineWidth > 0) - { - PIXI.WebGLGraphics.buildLine(data, graphics._webGL); - } - } - else if(data.type == PIXI.Graphics.RECT) - { - PIXI.WebGLGraphics.buildRectangle(data, graphics._webGL); - } - else if(data.type == PIXI.Graphics.CIRC || data.type == PIXI.Graphics.ELIP) - { - PIXI.WebGLGraphics.buildCircle(data, graphics._webGL); - } - }; - - graphics._webGL.lastIndex = graphics.graphicsData.length; - - var gl = PIXI.gl; - - graphics._webGL.glPoints = new Float32Array(graphics._webGL.points); - - gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer); - gl.bufferData(gl.ARRAY_BUFFER, graphics._webGL.glPoints, gl.STATIC_DRAW); - - graphics._webGL.glIndicies = new Uint16Array(graphics._webGL.indices); - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.glIndicies, gl.STATIC_DRAW); -} - -/** - * Builds a rectangle to draw - * - * @static - * @private - * @method buildRectangle - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData) -{ - // --- // - // need to convert points to a nice regular data - // - var rectData = graphicsData.points; - var x = rectData[0]; - var y = rectData[1]; - var width = rectData[2]; - var height = rectData[3]; - - - if(graphicsData.fill) - { - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vertPos = verts.length/6; - - // start - verts.push(x, y); - verts.push(r, g, b, alpha); - - verts.push(x + width, y); - verts.push(r, g, b, alpha); - - verts.push(x , y + height); - verts.push(r, g, b, alpha); - - verts.push(x + width, y + height); - verts.push(r, g, b, alpha); - - // insert 2 dead triangles.. - indices.push(vertPos, vertPos, vertPos+1, vertPos+2, vertPos+3, vertPos+3) - } - - if(graphicsData.lineWidth) - { - graphicsData.points = [x, y, - x + width, y, - x + width, y + height, - x, y + height, - x, y]; - - PIXI.WebGLGraphics.buildLine(graphicsData, webGLData); - } - -} - -/** - * Builds a circle to draw - * - * @static - * @private - * @method buildCircle - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildCircle = function(graphicsData, webGLData) -{ - // --- // - // need to convert points to a nice regular data - // - var rectData = graphicsData.points; - var x = rectData[0]; - var y = rectData[1]; - var width = rectData[2]; - var height = rectData[3]; - - var totalSegs = 40; - var seg = (Math.PI * 2) / totalSegs ; - - if(graphicsData.fill) - { - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vecPos = verts.length/6; - - indices.push(vecPos); - - for (var i=0; i < totalSegs + 1 ; i++) - { - verts.push(x,y, r, g, b, alpha); - - verts.push(x + Math.sin(seg * i) * width, - y + Math.cos(seg * i) * height, - r, g, b, alpha); - - indices.push(vecPos++, vecPos++); - }; - - indices.push(vecPos-1); - } - - if(graphicsData.lineWidth) - { - graphicsData.points = []; - - for (var i=0; i < totalSegs + 1; i++) - { - graphicsData.points.push(x + Math.sin(seg * i) * width, - y + Math.cos(seg * i) * height) - }; - - PIXI.WebGLGraphics.buildLine(graphicsData, webGLData); - } - -} - -/** - * Builds a line to draw - * - * @static - * @private - * @method buildLine - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData) -{ - // TODO OPTIMISE! - - var wrap = true; - var points = graphicsData.points; - if(points.length == 0)return; - - // get first and last point.. figure out the middle! - var firstPoint = new PIXI.Point( points[0], points[1] ); - var lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] ); - - // if the first point is the last point - goona have issues :) - if(firstPoint.x == lastPoint.x && firstPoint.y == lastPoint.y) - { - points.pop(); - points.pop(); - - lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] ); - - var midPointX = lastPoint.x + (firstPoint.x - lastPoint.x) *0.5; - var midPointY = lastPoint.y + (firstPoint.y - lastPoint.y) *0.5; - - points.unshift(midPointX, midPointY); - points.push(midPointX, midPointY) - } - - var verts = webGLData.points; - var indices = webGLData.indices; - var length = points.length / 2; - var indexCount = points.length; - var indexStart = verts.length/6; - - // DRAW the Line - var width = graphicsData.lineWidth / 2; - - // sort color - var color = HEXtoRGB(graphicsData.lineColor); - var alpha = graphicsData.lineAlpha; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var p1x, p1y, p2x, p2y, p3x, p3y; - var perpx, perpy, perp2x, perp2y, perp3x, perp3y; - var ipx, ipy; - var a1, b1, c1, a2, b2, c2; - var denom, pdist, dist; - - p1x = points[0]; - p1y = points[1]; - - p2x = points[2]; - p2y = points[3]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - // start - verts.push(p1x - perpx , p1y - perpy, - r, g, b, alpha); - - verts.push(p1x + perpx , p1y + perpy, - r, g, b, alpha); - - for (var i = 1; i < length-1; i++) - { - p1x = points[(i-1)*2]; - p1y = points[(i-1)*2 + 1]; - - p2x = points[(i)*2] - p2y = points[(i)*2 + 1] - - p3x = points[(i+1)*2]; - p3y = points[(i+1)*2 + 1]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - perp2x = -(p2y - p3y); - perp2y = p2x - p3x; - - dist = Math.sqrt(perp2x*perp2x + perp2y*perp2y); - perp2x /= dist; - perp2y /= dist; - perp2x *= width; - perp2y *= width; - - a1 = (-perpy + p1y) - (-perpy + p2y); - b1 = (-perpx + p2x) - (-perpx + p1x); - c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y); - a2 = (-perp2y + p3y) - (-perp2y + p2y); - b2 = (-perp2x + p2x) - (-perp2x + p3x); - c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y); - - denom = a1*b2 - a2*b1; - - if (denom == 0) { - denom+=1; - } - - px = (b1*c2 - b2*c1)/denom; - py = (a2*c1 - a1*c2)/denom; - - pdist = (px -p2x) * (px -p2x) + (py -p2y) + (py -p2y); - - if(pdist > 140 * 140) - { - perp3x = perpx - perp2x; - perp3y = perpy - perp2y; - - dist = Math.sqrt(perp3x*perp3x + perp3y*perp3y); - perp3x /= dist; - perp3y /= dist; - perp3x *= width; - perp3y *= width; - - verts.push(p2x - perp3x, p2y -perp3y); - verts.push(r, g, b, alpha); - - verts.push(p2x + perp3x, p2y +perp3y); - verts.push(r, g, b, alpha); - - verts.push(p2x - perp3x, p2y -perp3y); - verts.push(r, g, b, alpha); - - indexCount++; - } - else - { - verts.push(px , py); - verts.push(r, g, b, alpha); - - verts.push(p2x - (px-p2x), p2y - (py - p2y));//, 4); - verts.push(r, g, b, alpha); - } - } - - p1x = points[(length-2)*2] - p1y = points[(length-2)*2 + 1] - - p2x = points[(length-1)*2] - p2y = points[(length-1)*2 + 1] - - perpx = -(p1y - p2y) - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - verts.push(p2x - perpx , p2y - perpy) - verts.push(r, g, b, alpha); - - verts.push(p2x + perpx , p2y + perpy) - verts.push(r, g, b, alpha); - - indices.push(indexStart); - - for (var i=0; i < indexCount; i++) - { - indices.push(indexStart++); - }; - - indices.push(indexStart-1); -} - -/** - * Builds a polygon to draw - * - * @static - * @private - * @method buildPoly - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildPoly = function(graphicsData, webGLData) -{ - var points = graphicsData.points; - if(points.length < 6)return; - - // get first and last point.. figure out the middle! - var verts = webGLData.points; - var indices = webGLData.indices; - - var length = points.length / 2; - - // sort color - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var triangles = PIXI.PolyK.Triangulate(points); - - var vertPos = verts.length / 6; - - for (var i=0; i < triangles.length; i+=3) - { - indices.push(triangles[i] + vertPos); - indices.push(triangles[i] + vertPos); - indices.push(triangles[i+1] + vertPos); - indices.push(triangles[i+2] +vertPos); - indices.push(triangles[i+2] + vertPos); - }; - - for (var i = 0; i < length; i++) - { - verts.push(points[i * 2], points[i * 2 + 1], - r, g, b, alpha); - }; -} - -function HEXtoRGB(hex) { - return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; -} - - - - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI._defaultFrame = new PIXI.Rectangle(0,0,1,1); - -// an instance of the gl context.. -// only one at the moment :/ -PIXI.gl; - -/** - * the WebGLRenderer is draws the stage and all its content onto a webGL enabled canvas. This renderer - * should be used for browsers support webGL. This Render works by automatically managing webGLBatchs. - * So no need for Sprite Batch's or Sprite Cloud's - * Dont forget to add the view to your DOM or you will not see anything :) - * - * @class WebGLRenderer - * @constructor - * @param width=0 {Number} the width of the canvas view - * @param height=0 {Number} the height of the canvas view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - * - */ -PIXI.WebGLRenderer = function(width, height, view, transparent) -{ - // do a catch.. only 1 webGL renderer.. - - this.transparent = !!transparent; - - this.width = width || 800; - this.height = height || 600; - - this.view = view || document.createElement( 'canvas' ); - this.view.width = this.width; - this.view.height = this.height; - - // deal with losing context.. - var scope = this; - this.view.addEventListener('webglcontextlost', function(event) { scope.handleContextLost(event); }, false) - this.view.addEventListener('webglcontextrestored', function(event) { scope.handleContextRestored(event); }, false) - - this.batchs = []; - - try - { - PIXI.gl = this.gl = this.view.getContext("experimental-webgl", { - alpha: this.transparent, - antialias:true, // SPEED UP?? - premultipliedAlpha:false, - stencil:true - }); - } - catch (e) - { - throw new Error(" This browser does not support webGL. Try using the canvas renderer" + this); - } - - PIXI.initPrimitiveShader(); - PIXI.initDefaultShader(); - PIXI.initDefaultStripShader(); - - PIXI.activateDefaultShader(); - - var gl = this.gl; - PIXI.WebGLRenderer.gl = gl; - - this.batch = new PIXI.WebGLBatch(gl); - gl.disable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); - - gl.enable(gl.BLEND); - gl.colorMask(true, true, true, this.transparent); - - PIXI.projection = new PIXI.Point(400, 300); - - this.resize(this.width, this.height); - this.contextLost = false; - - this.stageRenderGroup = new PIXI.WebGLRenderGroup(this.gl); -} - -// constructor -PIXI.WebGLRenderer.prototype.constructor = PIXI.WebGLRenderer; - -/** - * Gets a new WebGLBatch from the pool - * - * @static - * @method getBatch - * @return {WebGLBatch} - * @private - */ -PIXI.WebGLRenderer.getBatch = function() -{ - if(PIXI._batchs.length == 0) - { - return new PIXI.WebGLBatch(PIXI.WebGLRenderer.gl); - } - else - { - return PIXI._batchs.pop(); - } -} - -/** - * Puts a batch back into the pool - * - * @static - * @method returnBatch - * @param batch {WebGLBatch} The batch to return - * @private - */ -PIXI.WebGLRenderer.returnBatch = function(batch) -{ - batch.clean(); - PIXI._batchs.push(batch); -} - -/** - * Renders the stage to its webGL view - * - * @method render - * @param stage {Stage} the Stage element to be rendered - */ -PIXI.WebGLRenderer.prototype.render = function(stage) -{ - if(this.contextLost)return; - - - // if rendering a new stage clear the batchs.. - if(this.__stage !== stage) - { - // TODO make this work - // dont think this is needed any more? - //if(this.__stage)this.checkVisibility(this.__stage, false) - - this.__stage = stage; - this.stageRenderGroup.setRenderable(stage); - } - - // TODO not needed now... - // update children if need be - // best to remove first! - /*for (var i=0; i < stage.__childrenRemoved.length; i++) - { - var group = stage.__childrenRemoved[i].__renderGroup - if(group)group.removeDisplayObject(stage.__childrenRemoved[i]); - }*/ - - // update any textures - PIXI.WebGLRenderer.updateTextures(); - - // recursivly loop through all items! - //this.checkVisibility(stage, true); - - // update the scene graph - stage.updateTransform(); - - var gl = this.gl; - - // -- Does this need to be set every frame? -- // - gl.colorMask(true, true, true, this.transparent); - gl.viewport(0, 0, this.width, this.height); - - // set the correct matrix.. - // gl.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform, false, this.projectionMatrix); - - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - - gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); - gl.clear(gl.COLOR_BUFFER_BIT); - - // HACK TO TEST - //PIXI.projectionMatrix = this.projectionMatrix; - - this.stageRenderGroup.backgroundColor = stage.backgroundColorSplit; - this.stageRenderGroup.render(PIXI.projection); - - // interaction - // run interaction! - if(stage.interactive) - { - //need to add some events! - if(!stage._interactiveEventsAdded) - { - stage._interactiveEventsAdded = true; - stage.interactionManager.setTarget(this); - } - } - - // after rendering lets confirm all frames that have been uodated.. - if(PIXI.Texture.frameUpdates.length > 0) - { - for (var i=0; i < PIXI.Texture.frameUpdates.length; i++) - { - PIXI.Texture.frameUpdates[i].updateFrame = false; - }; - - PIXI.Texture.frameUpdates = []; - } -} - -/** - * Updates the textures loaded into this webgl renderer - * - * @static - * @method updateTextures - * @private - */ -PIXI.WebGLRenderer.updateTextures = function() -{ - for (var i=0; i < PIXI.texturesToUpdate.length; i++) this.updateTexture(PIXI.texturesToUpdate[i]); - for (var i=0; i < PIXI.texturesToDestroy.length; i++) this.destroyTexture(PIXI.texturesToDestroy[i]); - PIXI.texturesToUpdate = []; - PIXI.texturesToDestroy = []; -} - -/** - * Updates a loaded webgl texture - * - * @static - * @method updateTexture - * @param texture {Texture} The texture to update - * @private - */ -PIXI.WebGLRenderer.updateTexture = function(texture) -{ - var gl = PIXI.gl; - - if(!texture._glTexture) - { - texture._glTexture = gl.createTexture(); - } - - if(texture.hasLoaded) - { - gl.bindTexture(gl.TEXTURE_2D, texture._glTexture); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true); - - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - - // reguler... - - if(!texture._powerOf2) - { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - } - else - { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); - } - - gl.bindTexture(gl.TEXTURE_2D, null); - } -} - -/** - * Destroys a loaded webgl texture - * - * @method destroyTexture - * @param texture {Texture} The texture to update - * @private - */ -PIXI.WebGLRenderer.prototype.destroyTexture = function(texture) -{ - var gl = this.gl; - - if(texture._glTexture) - { - texture._glTexture = gl.createTexture(); - gl.deleteTexture(gl.TEXTURE_2D, texture._glTexture); - } -} - -/** - * resizes the webGL view to the specified width and height - * - * @method resize - * @param width {Number} the new width of the webGL view - * @param height {Number} the new height of the webGL view - */ -PIXI.WebGLRenderer.prototype.resize = function(width, height) -{ - this.width = width; - this.height = height; - - this.view.width = width; - this.view.height = height; - - this.gl.viewport(0, 0, this.width, this.height); - - //var projectionMatrix = this.projectionMatrix; - - PIXI.projection.x = this.width/2; - PIXI.projection.y = this.height/2; - -// projectionMatrix[0] = 2/this.width; -// projectionMatrix[5] = -2/this.height; -// projectionMatrix[12] = -1; -// projectionMatrix[13] = 1; -} - -/** - * Handles a lost webgl context - * - * @method handleContextLost - * @param event {Event} - * @private - */ -PIXI.WebGLRenderer.prototype.handleContextLost = function(event) -{ - event.preventDefault(); - this.contextLost = true; -} - -/** - * Handles a restored webgl context - * - * @method handleContextRestored - * @param event {Event} - * @private - */ -PIXI.WebGLRenderer.prototype.handleContextRestored = function(event) -{ - this.gl = this.view.getContext("experimental-webgl", { - alpha: true - }); - - this.initShaders(); - - for(var key in PIXI.TextureCache) - { - var texture = PIXI.TextureCache[key].baseTexture; - texture._glTexture = null; - PIXI.WebGLRenderer.updateTexture(texture); - }; - - for (var i=0; i < this.batchs.length; i++) - { - this.batchs[i].restoreLostContext(this.gl)// - this.batchs[i].dirty = true; - }; - - PIXI._restoreBatchs(this.gl); - - this.contextLost = false; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI._batchs = []; - -/** - * @private - */ -PIXI._getBatch = function(gl) -{ - if(PIXI._batchs.length == 0) - { - return new PIXI.WebGLBatch(gl); - } - else - { - return PIXI._batchs.pop(); - } -} - -/** - * @private - */ -PIXI._returnBatch = function(batch) -{ - batch.clean(); - PIXI._batchs.push(batch); -} - -/** - * @private - */ -PIXI._restoreBatchs = function(gl) -{ - for (var i=0; i < PIXI._batchs.length; i++) - { - PIXI._batchs[i].restoreLostContext(gl); - }; -} - -/** - * A WebGLBatch Enables a group of sprites to be drawn using the same settings. - * if a group of sprites all have the same baseTexture and blendMode then they can be grouped into a batch. - * All the sprites in a batch can then be drawn in one go by the GPU which is hugely efficient. ALL sprites - * in the webGL renderer are added to a batch even if the batch only contains one sprite. Batching is handled - * automatically by the webGL renderer. A good tip is: the smaller the number of batchs there are, the faster - * the webGL renderer will run. - * - * @class WebGLBatch - * @constructor - * @param gl {WebGLContext} an instance of the webGL context - */ -PIXI.WebGLBatch = function(gl) -{ - this.gl = gl; - - this.size = 0; - - this.vertexBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - this.uvBuffer = gl.createBuffer(); - this.colorBuffer = gl.createBuffer(); - this.blendMode = PIXI.blendModes.NORMAL; - this.dynamicSize = 1; -} - -// constructor -PIXI.WebGLBatch.prototype.constructor = PIXI.WebGLBatch; - -/** - * Cleans the batch so that is can be returned to an object pool and reused - * - * @method clean - */ -PIXI.WebGLBatch.prototype.clean = function() -{ - this.verticies = []; - this.uvs = []; - this.indices = []; - this.colors = []; - //this.sprites = []; - this.dynamicSize = 1; - this.texture = null; - this.last = null; - this.size = 0; - this.head; - this.tail; -} - -/** - * Recreates the buffers in the event of a context loss - * - * @method restoreLostContext - * @param gl {WebGLContext} - */ -PIXI.WebGLBatch.prototype.restoreLostContext = function(gl) -{ - this.gl = gl; - this.vertexBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - this.uvBuffer = gl.createBuffer(); - this.colorBuffer = gl.createBuffer(); -} - -/** - * inits the batch's texture and blend mode based if the supplied sprite - * - * @method init - * @param sprite {Sprite} the first sprite to be added to the batch. Only sprites with - * the same base texture and blend mode will be allowed to be added to this batch - */ -PIXI.WebGLBatch.prototype.init = function(sprite) -{ - sprite.batch = this; - this.dirty = true; - this.blendMode = sprite.blendMode; - this.texture = sprite.texture.baseTexture; -// this.sprites.push(sprite); - this.head = sprite; - this.tail = sprite; - this.size = 1; - - this.growBatch(); -} - -/** - * inserts a sprite before the specified sprite - * - * @method insertBefore - * @param sprite {Sprite} the sprite to be added - * @param nextSprite {nextSprite} the first sprite will be inserted before this sprite - */ -PIXI.WebGLBatch.prototype.insertBefore = function(sprite, nextSprite) -{ - this.size++; - - sprite.batch = this; - this.dirty = true; - var tempPrev = nextSprite.__prev; - nextSprite.__prev = sprite; - sprite.__next = nextSprite; - - if(tempPrev) - { - sprite.__prev = tempPrev; - tempPrev.__next = sprite; - } - else - { - this.head = sprite; - //this.head.__prev = null - } -} - -/** - * inserts a sprite after the specified sprite - * - * @method insertAfter - * @param sprite {Sprite} the sprite to be added - * @param previousSprite {Sprite} the first sprite will be inserted after this sprite - */ -PIXI.WebGLBatch.prototype.insertAfter = function(sprite, previousSprite) -{ - this.size++; - - sprite.batch = this; - this.dirty = true; - - var tempNext = previousSprite.__next; - previousSprite.__next = sprite; - sprite.__prev = previousSprite; - - if(tempNext) - { - sprite.__next = tempNext; - tempNext.__prev = sprite; - } - else - { - this.tail = sprite - } -} - -/** - * removes a sprite from the batch - * - * @method remove - * @param sprite {Sprite} the sprite to be removed - */ -PIXI.WebGLBatch.prototype.remove = function(sprite) -{ - this.size--; - - if(this.size == 0) - { - sprite.batch = null; - sprite.__prev = null; - sprite.__next = null; - return; - } - - if(sprite.__prev) - { - sprite.__prev.__next = sprite.__next; - } - else - { - this.head = sprite.__next; - this.head.__prev = null; - } - - if(sprite.__next) - { - sprite.__next.__prev = sprite.__prev; - } - else - { - this.tail = sprite.__prev; - this.tail.__next = null - } - - sprite.batch = null; - sprite.__next = null; - sprite.__prev = null; - this.dirty = true; -} - -/** - * Splits the batch into two with the specified sprite being the start of the new batch. - * - * @method split - * @param sprite {Sprite} the sprite that indicates where the batch should be split - * @return {WebGLBatch} the new batch - */ -PIXI.WebGLBatch.prototype.split = function(sprite) -{ - this.dirty = true; - - var batch = new PIXI.WebGLBatch(this.gl);//PIXI._getBatch(this.gl); - batch.init(sprite); - batch.texture = this.texture; - batch.tail = this.tail; - - this.tail = sprite.__prev; - this.tail.__next = null; - - sprite.__prev = null; - // return a splite batch! - //sprite.__prev.__next = null; - //sprite.__prev = null; - - // TODO this size is wrong! - // need to recalculate :/ problem with a linked list! - // unless it gets calculated in the "clean"? - - // need to loop through items as there is no way to know the length on a linked list :/ - var tempSize = 0; - while(sprite) - { - tempSize++; - sprite.batch = batch; - sprite = sprite.__next; - } - - batch.size = tempSize; - this.size -= tempSize; - - return batch; -} - -/** - * Merges two batchs together - * - * @method merge - * @param batch {WebGLBatch} the batch that will be merged - */ -PIXI.WebGLBatch.prototype.merge = function(batch) -{ - this.dirty = true; - - this.tail.__next = batch.head; - batch.head.__prev = this.tail; - - this.size += batch.size; - - this.tail = batch.tail; - - var sprite = batch.head; - while(sprite) - { - sprite.batch = this; - sprite = sprite.__next; - } -} - -/** - * Grows the size of the batch. As the elements in the batch cannot have a dynamic size this - * function is used to increase the size of the batch. It also creates a little extra room so - * that the batch does not need to be resized every time a sprite is added - * - * @method growBatch - */ -PIXI.WebGLBatch.prototype.growBatch = function() -{ - var gl = this.gl; - if( this.size == 1) - { - this.dynamicSize = 1; - } - else - { - this.dynamicSize = this.size * 1.5 - } - // grow verts - this.verticies = new Float32Array(this.dynamicSize * 8); - - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER,this.verticies , gl.DYNAMIC_DRAW); - - this.uvs = new Float32Array( this.dynamicSize * 8 ) - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, this.uvs , gl.DYNAMIC_DRAW); - - this.dirtyUVS = true; - - this.colors = new Float32Array( this.dynamicSize * 4 ) - gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, this.colors , gl.DYNAMIC_DRAW); - - this.dirtyColors = true; - - this.indices = new Uint16Array(this.dynamicSize * 6); - var length = this.indices.length/6; - - for (var i=0; i < length; i++) - { - var index2 = i * 6; - var index3 = i * 4; - this.indices[index2 + 0] = index3 + 0; - this.indices[index2 + 1] = index3 + 1; - this.indices[index2 + 2] = index3 + 2; - this.indices[index2 + 3] = index3 + 0; - this.indices[index2 + 4] = index3 + 2; - this.indices[index2 + 5] = index3 + 3; - }; - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW); -} - -/** - * Refresh's all the data in the batch and sync's it with the webGL buffers - * - * @method refresh - */ -PIXI.WebGLBatch.prototype.refresh = function() -{ - var gl = this.gl; - - if (this.dynamicSize < this.size) - { - this.growBatch(); - } - - var indexRun = 0; - var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index; - var a, b, c, d, tx, ty; - - var displayObject = this.head; - - while(displayObject) - { - index = indexRun * 8; - - var texture = displayObject.texture; - - var frame = texture.frame; - var tw = texture.baseTexture.width; - var th = texture.baseTexture.height; - - this.uvs[index + 0] = frame.x / tw; - this.uvs[index +1] = frame.y / th; - - this.uvs[index +2] = (frame.x + frame.width) / tw; - this.uvs[index +3] = frame.y / th; - - this.uvs[index +4] = (frame.x + frame.width) / tw; - this.uvs[index +5] = (frame.y + frame.height) / th; - - this.uvs[index +6] = frame.x / tw; - this.uvs[index +7] = (frame.y + frame.height) / th; - - displayObject.updateFrame = false; - - colorIndex = indexRun * 4; - this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha; - - displayObject = displayObject.__next; - - indexRun ++; - } - - this.dirtyUVS = true; - this.dirtyColors = true; -} - -/** - * Updates all the relevant geometry and uploads the data to the GPU - * - * @method update - */ -PIXI.WebGLBatch.prototype.update = function() -{ - var gl = this.gl; - var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, index2, index3 - - var a, b, c, d, tx, ty; - - var indexRun = 0; - - var displayObject = this.head; - - while(displayObject) - { - if(displayObject.worldVisible) - { - width = displayObject.texture.frame.width; - height = displayObject.texture.frame.height; - - // TODO trim?? - aX = displayObject.anchor.x;// - displayObject.texture.trim.x - aY = displayObject.anchor.y; //- displayObject.texture.trim.y - w0 = width * (1-aX); - w1 = width * -aX; - - h0 = height * (1-aY); - h1 = height * -aY; - - index = indexRun * 8; - - worldTransform = displayObject.worldTransform; - - a = worldTransform[0]; - b = worldTransform[3]; - c = worldTransform[1]; - d = worldTransform[4]; - tx = worldTransform[2]; - ty = worldTransform[5]; - - this.verticies[index + 0 ] = a * w1 + c * h1 + tx; - this.verticies[index + 1 ] = d * h1 + b * w1 + ty; - - this.verticies[index + 2 ] = a * w0 + c * h1 + tx; - this.verticies[index + 3 ] = d * h1 + b * w0 + ty; - - this.verticies[index + 4 ] = a * w0 + c * h0 + tx; - this.verticies[index + 5 ] = d * h0 + b * w0 + ty; - - this.verticies[index + 6] = a * w1 + c * h0 + tx; - this.verticies[index + 7] = d * h0 + b * w1 + ty; - - if(displayObject.updateFrame || displayObject.texture.updateFrame) - { - this.dirtyUVS = true; - - var texture = displayObject.texture; - - var frame = texture.frame; - var tw = texture.baseTexture.width; - var th = texture.baseTexture.height; - - this.uvs[index + 0] = frame.x / tw; - this.uvs[index +1] = frame.y / th; - - this.uvs[index +2] = (frame.x + frame.width) / tw; - this.uvs[index +3] = frame.y / th; - - this.uvs[index +4] = (frame.x + frame.width) / tw; - this.uvs[index +5] = (frame.y + frame.height) / th; - - this.uvs[index +6] = frame.x / tw; - this.uvs[index +7] = (frame.y + frame.height) / th; - - displayObject.updateFrame = false; - } - - // TODO this probably could do with some optimisation.... - if(displayObject.cacheAlpha != displayObject.worldAlpha) - { - displayObject.cacheAlpha = displayObject.worldAlpha; - - var colorIndex = indexRun * 4; - this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha; - this.dirtyColors = true; - } - } - else - { - index = indexRun * 8; - - this.verticies[index + 0 ] = 0; - this.verticies[index + 1 ] = 0; - - this.verticies[index + 2 ] = 0; - this.verticies[index + 3 ] = 0; - - this.verticies[index + 4 ] = 0; - this.verticies[index + 5 ] = 0; - - this.verticies[index + 6] = 0; - this.verticies[index + 7] = 0; - } - - indexRun++; - displayObject = displayObject.__next; - } -} - -/** - * Draws the batch to the frame buffer - * - * @method render - */ -PIXI.WebGLBatch.prototype.render = function(start, end) -{ - start = start || 0; - //end = end || this.size; - if(end == undefined)end = this.size; - - if(this.dirty) - { - this.refresh(); - this.dirty = false; - } - - if (this.size == 0)return; - - this.update(); - var gl = this.gl; - - //TODO optimize this! - - var shaderProgram = PIXI.shaderProgram; - gl.useProgram(shaderProgram); - - // update the verts.. - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - // ok.. - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.verticies) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - - if(this.dirtyUVS) - { - this.dirtyUVS = false; - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvs); - } - - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, this.texture._glTexture); - - // update color! - gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer); - - if(this.dirtyColors) - { - this.dirtyColors = false; - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.colors); - } - - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - - //var startIndex = 0//1; - var len = end - start; - // console.log(this.size) - // DRAW THAT this! - gl.drawElements(gl.TRIANGLES, len * 6, gl.UNSIGNED_SHORT, start * 2 * 6 ); -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A WebGLBatch Enables a group of sprites to be drawn using the same settings. - * if a group of sprites all have the same baseTexture and blendMode then they can be - * grouped into a batch. All the sprites in a batch can then be drawn in one go by the - * GPU which is hugely efficient. ALL sprites in the webGL renderer are added to a batch - * even if the batch only contains one sprite. Batching is handled automatically by the - * webGL renderer. A good tip is: the smaller the number of batchs there are, the faster - * the webGL renderer will run. - * - * @class WebGLBatch - * @contructor - * @param gl {WebGLContext} An instance of the webGL context - */ -PIXI.WebGLRenderGroup = function(gl) -{ - this.gl = gl; - this.root; - - this.backgroundColor; - this.batchs = []; - this.toRemove = []; -} - -// constructor -PIXI.WebGLRenderGroup.prototype.constructor = PIXI.WebGLRenderGroup; - -/** - * Add a display object to the webgl renderer - * - * @method setRenderable - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.setRenderable = function(displayObject) -{ - // has this changed?? - if(this.root)this.removeDisplayObjectAndChildren(this.root); - - displayObject.worldVisible = displayObject.visible; - - // soooooo // - // to check if any batchs exist already?? - - // TODO what if its already has an object? should remove it - this.root = displayObject; - this.addDisplayObjectAndChildren(displayObject); -} - -/** - * Renders the stage to its webgl view - * - * @method render - * @param projection {Object} - */ -PIXI.WebGLRenderGroup.prototype.render = function(projection) -{ - PIXI.WebGLRenderer.updateTextures(); - - var gl = this.gl; - - - gl.uniform2f(PIXI.shaderProgram.projectionVector, projection.x, projection.y); - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - - // TODO remove this by replacing visible with getter setters.. - this.checkVisibility(this.root, this.root.visible); - - // will render all the elements in the group - var renderable; - - - for (var i=0; i < this.batchs.length; i++) - { - renderable = this.batchs[i]; - if(renderable instanceof PIXI.WebGLBatch) - { - this.batchs[i].render(); - } - else if(renderable instanceof PIXI.TilingSprite) - { - if(renderable.visible)this.renderTilingSprite(renderable, projection); - } - else if(renderable instanceof PIXI.Strip) - { - if(renderable.visible)this.renderStrip(renderable, projection); - } - else if(renderable instanceof PIXI.Graphics) - { - if(renderable.visible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable, projection);//, projectionMatrix); - } - else if(renderable instanceof PIXI.FilterBlock) - { - /* - * for now only masks are supported.. - */ - if(renderable.open) - { - gl.enable(gl.STENCIL_TEST); - - gl.colorMask(false, false, false, false); - gl.stencilFunc(gl.ALWAYS,1,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE); - - PIXI.WebGLGraphics.renderGraphics(renderable.mask, projection); - - gl.colorMask(true, true, true, false); - gl.stencilFunc(gl.NOTEQUAL,0,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); - } - else - { - gl.disable(gl.STENCIL_TEST); - } - } - } - -} - -/** - * Renders the stage to its webgl view - * - * @method handleFilter - * @param filter {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.handleFilter = function(filter, projection) -{ - -} - -/** - * Renders a specific displayObject - * - * @method renderSpecific - * @param displayObject {DisplayObject} - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderSpecific = function(displayObject, projection) -{ - PIXI.WebGLRenderer.updateTextures(); - - var gl = this.gl; - this.checkVisibility(displayObject, displayObject.visible); - -// gl.uniformMatrix4fv(PIXI.shaderProgram.mvMatrixUniform, false, projectionMatrix); - gl.uniform2f(PIXI.shaderProgram.projectionVector, projection.x, projection.y); - - // to do! - // render part of the scene... - - var startIndex; - var startBatchIndex; - - var endIndex; - var endBatchIndex; - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.first; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - var startBatch = nextRenderable.batch; - - if(nextRenderable instanceof PIXI.Sprite) - { - startBatch = nextRenderable.batch; - - var head = startBatch.head; - var next = head; - - // ok now we have the batch.. need to find the start index! - if(head == nextRenderable) - { - startIndex = 0; - } - else - { - startIndex = 1; - - while(head.__next != nextRenderable) - { - startIndex++; - head = head.__next; - } - } - } - else - { - startBatch = nextRenderable; - } - - // Get the LAST renderable object - var lastRenderable = displayObject; - var endBatch; - var lastItem = displayObject; - while(lastItem.children.length > 0) - { - lastItem = lastItem.children[lastItem.children.length-1]; - if(lastItem.renderable)lastRenderable = lastItem; - } - - if(lastRenderable instanceof PIXI.Sprite) - { - endBatch = lastRenderable.batch; - - var head = endBatch.head; - - if(head == lastRenderable) - { - endIndex = 0; - } - else - { - endIndex = 1; - - while(head.__next != lastRenderable) - { - endIndex++; - head = head.__next; - } - } - } - else - { - endBatch = lastRenderable; - } - - // TODO - need to fold this up a bit! - - if(startBatch == endBatch) - { - if(startBatch instanceof PIXI.WebGLBatch) - { - startBatch.render(startIndex, endIndex+1); - } - else - { - this.renderSpecial(startBatch, projection); - } - return; - } - - // now we have first and last! - startBatchIndex = this.batchs.indexOf(startBatch); - endBatchIndex = this.batchs.indexOf(endBatch); - - // DO the first batch - if(startBatch instanceof PIXI.WebGLBatch) - { - startBatch.render(startIndex); - } - else - { - this.renderSpecial(startBatch, projection); - } - - // DO the middle batchs.. - for (var i=startBatchIndex+1; i < endBatchIndex; i++) - { - renderable = this.batchs[i]; - - if(renderable instanceof PIXI.WebGLBatch) - { - this.batchs[i].render(); - } - else - { - this.renderSpecial(renderable, projection); - } - } - - // DO the last batch.. - if(endBatch instanceof PIXI.WebGLBatch) - { - endBatch.render(0, endIndex+1); - } - else - { - this.renderSpecial(endBatch, projection); - } -} - -/** - * Renders a specific renderable - * - * @method renderSpecial - * @param renderable {DisplayObject} - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderSpecial = function(renderable, projection) -{ - if(renderable instanceof PIXI.TilingSprite) - { - if(renderable.visible)this.renderTilingSprite(renderable, projection); - } - else if(renderable instanceof PIXI.Strip) - { - if(renderable.visible)this.renderStrip(renderable, projection); - } - else if(renderable instanceof PIXI.CustomRenderable) - { - if(renderable.visible) renderable.renderWebGL(this, projection); - } - else if(renderable instanceof PIXI.Graphics) - { - if(renderable.visible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable, projection); - } - else if(renderable instanceof PIXI.FilterBlock) - { - /* - * for now only masks are supported.. - */ - - var gl = PIXI.gl; - - if(renderable.open) - { - gl.enable(gl.STENCIL_TEST); - - gl.colorMask(false, false, false, false); - gl.stencilFunc(gl.ALWAYS,1,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE); - - PIXI.WebGLGraphics.renderGraphics(renderable.mask, projection); - - // we know this is a render texture so enable alpha too.. - gl.colorMask(true, true, true, true); - gl.stencilFunc(gl.NOTEQUAL,0,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); - } - else - { - gl.disable(gl.STENCIL_TEST); - } - } -} - -/** - * Checks the visibility of a displayObject - * - * @method checkVisibility - * @param displayObject {DisplayObject} - * @param globalVisible {Boolean} - * @private - */ -PIXI.WebGLRenderGroup.prototype.checkVisibility = function(displayObject, globalVisible) -{ - // give the dp a reference to its renderGroup... - var children = displayObject.children; - //displayObject.worldVisible = globalVisible; - for (var i=0; i < children.length; i++) - { - var child = children[i]; - - // TODO optimize... should'nt need to loop through everything all the time - child.worldVisible = child.visible && globalVisible; - - // everything should have a batch! - // time to see whats new! - if(child.textureChange) - { - child.textureChange = false; - if(child.worldVisible)this.updateTexture(child); - // update texture!! - } - - if(child.children.length > 0) - { - this.checkVisibility(child, child.worldVisible); - } - }; -} - -/** - * Updates a webgl texture - * - * @method updateTexture - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.updateTexture = function(displayObject) -{ - - // TODO definitely can optimse this function.. - - this.removeObject(displayObject); - - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - var previousRenderable = displayObject.first; - while(previousRenderable != this.root) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.last; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - - this.insertObject(displayObject, previousRenderable, nextRenderable); -} - -/** - * Adds filter blocks - * - * @method addFilterBlocks - * @param start {FilterBlock} - * @param end {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.addFilterBlocks = function(start, end) -{ - start.__renderGroup = this; - end.__renderGroup = this; - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - var previousRenderable = start; - while(previousRenderable != this.root) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - this.insertAfter(start, previousRenderable); - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var previousRenderable2 = end; - while(previousRenderable2 != this.root) - { - previousRenderable2 = previousRenderable2._iPrev; - if(previousRenderable2.renderable && previousRenderable2.__renderGroup)break; - } - this.insertAfter(end, previousRenderable2); -} - -/** - * Remove filter blocks - * - * @method removeFilterBlocks - * @param start {FilterBlock} - * @param end {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeFilterBlocks = function(start, end) -{ - this.removeObject(start); - this.removeObject(end); -} - -/** - * Adds a display object and children to the webgl context - * - * @method addDisplayObjectAndChildren - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.addDisplayObjectAndChildren = function(displayObject) -{ - if(displayObject.__renderGroup)displayObject.__renderGroup.removeDisplayObjectAndChildren(displayObject); - - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - - var previousRenderable = displayObject.first; - while(previousRenderable != this.root.first) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.last; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - - // one the display object hits this. we can break the loop - - var tempObject = displayObject.first; - var testObject = displayObject.last._iNext; - do - { - tempObject.__renderGroup = this; - - if(tempObject.renderable) - { - - this.insertObject(tempObject, previousRenderable, nextRenderable); - previousRenderable = tempObject; - } - - tempObject = tempObject._iNext; - } - while(tempObject != testObject) -} - -/** - * Removes a display object and children to the webgl context - * - * @method removeDisplayObjectAndChildren - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeDisplayObjectAndChildren = function(displayObject) -{ - if(displayObject.__renderGroup != this)return; - -// var displayObject = displayObject.first; - var lastObject = displayObject.last; - do - { - displayObject.__renderGroup = null; - if(displayObject.renderable)this.removeObject(displayObject); - displayObject = displayObject._iNext; - } - while(displayObject) -} - -/** - * Inserts a displayObject into the linked list - * - * @method insertObject - * @param displayObject {DisplayObject} - * @param previousObject {DisplayObject} - * @param nextObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.insertObject = function(displayObject, previousObject, nextObject) -{ - // while looping below THE OBJECT MAY NOT HAVE BEEN ADDED - var previousSprite = previousObject; - var nextSprite = nextObject; - - /* - * so now we have the next renderable and the previous renderable - * - */ - if(displayObject instanceof PIXI.Sprite) - { - var previousBatch - var nextBatch - - if(previousSprite instanceof PIXI.Sprite) - { - previousBatch = previousSprite.batch; - if(previousBatch) - { - if(previousBatch.texture == displayObject.texture.baseTexture && previousBatch.blendMode == displayObject.blendMode) - { - previousBatch.insertAfter(displayObject, previousSprite); - return; - } - } - } - else - { - // TODO reword! - previousBatch = previousSprite; - } - - if(nextSprite) - { - if(nextSprite instanceof PIXI.Sprite) - { - nextBatch = nextSprite.batch; - - //batch may not exist if item was added to the display list but not to the webGL - if(nextBatch) - { - if(nextBatch.texture == displayObject.texture.baseTexture && nextBatch.blendMode == displayObject.blendMode) - { - nextBatch.insertBefore(displayObject, nextSprite); - return; - } - else - { - if(nextBatch == previousBatch) - { - // THERE IS A SPLIT IN THIS BATCH! // - var splitBatch = previousBatch.split(nextSprite); - // COOL! - // add it back into the array - /* - * OOPS! - * seems the new sprite is in the middle of a batch - * lets split it.. - */ - var batch = PIXI.WebGLRenderer.getBatch(); - - var index = this.batchs.indexOf( previousBatch ); - batch.init(displayObject); - this.batchs.splice(index+1, 0, batch, splitBatch); - - return; - } - } - } - } - else - { - // TODO re-word! - - nextBatch = nextSprite; - } - } - - /* - * looks like it does not belong to any batch! - * but is also not intersecting one.. - * time to create anew one! - */ - - var batch = PIXI.WebGLRenderer.getBatch(); - batch.init(displayObject); - - if(previousBatch) // if this is invalid it means - { - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, batch); - } - else - { - this.batchs.push(batch); - } - - return; - } - else if(displayObject instanceof PIXI.TilingSprite) - { - - // add to a batch!! - this.initTilingSprite(displayObject); - // this.batchs.push(displayObject); - - } - else if(displayObject instanceof PIXI.Strip) - { - // add to a batch!! - this.initStrip(displayObject); - // this.batchs.push(displayObject); - } - else if(displayObject)// instanceof PIXI.Graphics) - { - //displayObject.initWebGL(this); - - // add to a batch!! - //this.initStrip(displayObject); - //this.batchs.push(displayObject); - } - - this.insertAfter(displayObject, previousSprite); - - // insert and SPLIT! - -} - -/** - * Inserts a displayObject into the linked list - * - * @method insertAfter - * @param item {DisplayObject} - * @param displayObject {DisplayObject} The object to insert - * @private - */ -PIXI.WebGLRenderGroup.prototype.insertAfter = function(item, displayObject) -{ - if(displayObject instanceof PIXI.Sprite) - { - var previousBatch = displayObject.batch; - - if(previousBatch) - { - // so this object is in a batch! - - // is it not? need to split the batch - if(previousBatch.tail == displayObject) - { - // is it tail? insert in to batchs - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, item); - } - else - { - // TODO MODIFY ADD / REMOVE CHILD TO ACCOUNT FOR FILTERS (also get prev and next) // - - // THERE IS A SPLIT IN THIS BATCH! // - var splitBatch = previousBatch.split(displayObject.__next); - - // COOL! - // add it back into the array - /* - * OOPS! - * seems the new sprite is in the middle of a batch - * lets split it.. - */ - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, item, splitBatch); - } - } - else - { - this.batchs.push(item); - } - } - else - { - var index = this.batchs.indexOf( displayObject ); - this.batchs.splice(index+1, 0, item); - } -} - -/** - * Removes a displayObject from the linked list - * - * @method removeObject - * @param displayObject {DisplayObject} The object to remove - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeObject = function(displayObject) -{ - // loop through children.. - // display object // - - // add a child from the render group.. - // remove it and all its children! - //displayObject.cacheVisible = false;//displayObject.visible; - - /* - * removing is a lot quicker.. - * - */ - var batchToRemove; - - if(displayObject instanceof PIXI.Sprite) - { - // should always have a batch! - var batch = displayObject.batch; - if(!batch)return; // this means the display list has been altered befre rendering - - batch.remove(displayObject); - - if(batch.size==0) - { - batchToRemove = batch; - } - } - else - { - batchToRemove = displayObject; - } - - /* - * Looks like there is somthing that needs removing! - */ - if(batchToRemove) - { - var index = this.batchs.indexOf( batchToRemove ); - if(index == -1)return;// this means it was added then removed before rendered - - // ok so.. check to see if you adjacent batchs should be joined. - // TODO may optimise? - if(index == 0 || index == this.batchs.length-1) - { - // wha - eva! just get of the empty batch! - this.batchs.splice(index, 1); - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - - return; - } - - if(this.batchs[index-1] instanceof PIXI.WebGLBatch && this.batchs[index+1] instanceof PIXI.WebGLBatch) - { - if(this.batchs[index-1].texture == this.batchs[index+1].texture && this.batchs[index-1].blendMode == this.batchs[index+1].blendMode) - { - //console.log("MERGE") - this.batchs[index-1].merge(this.batchs[index+1]); - - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - PIXI.WebGLRenderer.returnBatch(this.batchs[index+1]); - this.batchs.splice(index, 2); - return; - } - } - - this.batchs.splice(index, 1); - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - } -} - -/** - * Initializes a tiling sprite - * - * @method initTilingSprite - * @param sprite {TilingSprite} The tiling sprite to initialize - * @private - */ -PIXI.WebGLRenderGroup.prototype.initTilingSprite = function(sprite) -{ - var gl = this.gl; - - // make the texture tilable.. - - sprite.verticies = new Float32Array([0, 0, - sprite.width, 0, - sprite.width, sprite.height, - 0, sprite.height]); - - sprite.uvs = new Float32Array([0, 0, - 1, 0, - 1, 1, - 0, 1]); - - sprite.colors = new Float32Array([1,1,1,1]); - - sprite.indices = new Uint16Array([0, 1, 3,2])//, 2]); - - sprite._vertexBuffer = gl.createBuffer(); - sprite._indexBuffer = gl.createBuffer(); - sprite._uvBuffer = gl.createBuffer(); - sprite._colorBuffer = gl.createBuffer(); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.verticies, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.uvs, gl.DYNAMIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.colors, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, sprite._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, sprite.indices, gl.STATIC_DRAW); - -// return ( (x > 0) && ((x & (x - 1)) == 0) ); - - if(sprite.texture.baseTexture._glTexture) - { - gl.bindTexture(gl.TEXTURE_2D, sprite.texture.baseTexture._glTexture); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); - sprite.texture.baseTexture._powerOf2 = true; - } - else - { - sprite.texture.baseTexture._powerOf2 = true; - } -} - -/** - * Renders a Strip - * - * @method renderStrip - * @param strip {Strip} The strip to render - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderStrip = function(strip, projection) -{ - var gl = this.gl; - var shaderProgram = PIXI.shaderProgram; -// mat - //var mat4Real = PIXI.mat3.toMat4(strip.worldTransform); - //PIXI.mat4.transpose(mat4Real); - //PIXI.mat4.multiply(projectionMatrix, mat4Real, mat4Real ) - - - gl.useProgram(PIXI.stripShaderProgram); - - var m = PIXI.mat3.clone(strip.worldTransform); - - PIXI.mat3.transpose(m); - - // set the matrix transform for the - gl.uniformMatrix3fv(PIXI.stripShaderProgram.translationMatrix, false, m); - gl.uniform2f(PIXI.stripShaderProgram.projectionVector, projection.x, projection.y); - gl.uniform1f(PIXI.stripShaderProgram.alpha, strip.worldAlpha); - -/* - if(strip.blendMode == PIXI.blendModes.NORMAL) - { - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - } - else - { - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR); - } - */ - - - if(!strip.dirty) - { - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferSubData(gl.ARRAY_BUFFER, 0, strip.verticies) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - } - else - { - strip.dirty = false; - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW); - - } - //console.log(gl.TRIANGLE_STRIP); - - gl.drawElements(gl.TRIANGLE_STRIP, strip.indices.length, gl.UNSIGNED_SHORT, 0); - - gl.useProgram(PIXI.shaderProgram); -} - -/** - * Renders a TilingSprite - * - * @method renderTilingSprite - * @param sprite {TilingSprite} The tiling sprite to render - * @param projectionMatrix {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderTilingSprite = function(sprite, projectionMatrix) -{ - var gl = this.gl; - var shaderProgram = PIXI.shaderProgram; - - var tilePosition = sprite.tilePosition; - var tileScale = sprite.tileScale; - - var offsetX = tilePosition.x/sprite.texture.baseTexture.width; - var offsetY = tilePosition.y/sprite.texture.baseTexture.height; - - var scaleX = (sprite.width / sprite.texture.baseTexture.width) / tileScale.x; - var scaleY = (sprite.height / sprite.texture.baseTexture.height) / tileScale.y; - - sprite.uvs[0] = 0 - offsetX; - sprite.uvs[1] = 0 - offsetY; - - sprite.uvs[2] = (1 * scaleX) -offsetX; - sprite.uvs[3] = 0 - offsetY; - - sprite.uvs[4] = (1 *scaleX) - offsetX; - sprite.uvs[5] = (1 *scaleY) - offsetY; - - sprite.uvs[6] = 0 - offsetX; - sprite.uvs[7] = (1 *scaleY) - offsetY; - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._uvBuffer); - gl.bufferSubData(gl.ARRAY_BUFFER, 0, sprite.uvs) - - this.renderStrip(sprite, projectionMatrix); -} - -/** - * Initializes a strip to be rendered - * - * @method initStrip - * @param strip {Strip} The strip to initialize - * @private - */ -PIXI.WebGLRenderGroup.prototype.initStrip = function(strip) -{ - // build the strip! - var gl = this.gl; - var shaderProgram = this.shaderProgram; - - strip._vertexBuffer = gl.createBuffer(); - strip._indexBuffer = gl.createBuffer(); - strip._uvBuffer = gl.createBuffer(); - strip._colorBuffer = gl.createBuffer(); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.DYNAMIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW); - - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW); -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * the CanvasRenderer draws the stage and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. - * Dont forget to add the view to your DOM or you will not see anything :) - * - * @class CanvasRenderer - * @constructor - * @param width=0 {Number} the width of the canvas view - * @param height=0 {Number} the height of the canvas view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - */ -PIXI.CanvasRenderer = function(width, height, view, transparent) -{ - this.transparent = transparent; - - /** - * The width of the canvas view - * - * @property width - * @type Number - * @default 800 - */ - this.width = width || 800; - - /** - * The height of the canvas view - * - * @property height - * @type Number - * @default 600 - */ - this.height = height || 600; - - /** - * The canvas element that the everything is drawn to - * - * @property view - * @type Canvas - */ - this.view = view || document.createElement( 'canvas' ); - - /** - * The canvas context that the everything is drawn to - * @property context - * @type Canvas 2d Context - */ - this.context = this.view.getContext("2d"); - - this.refresh = true; - // hack to enable some hardware acceleration! - //this.view.style["transform"] = "translatez(0)"; - - this.view.width = this.width; - this.view.height = this.height; - this.count = 0; -} - -// constructor -PIXI.CanvasRenderer.prototype.constructor = PIXI.CanvasRenderer; - -/** - * Renders the stage to its canvas view - * - * @method render - * @param stage {Stage} the Stage element to be rendered - */ -PIXI.CanvasRenderer.prototype.render = function(stage) -{ - // update children if need be - - //stage.__childrenAdded = []; - //stage.__childrenRemoved = []; - - // update textures if need be - PIXI.texturesToUpdate = []; - PIXI.texturesToDestroy = []; - - stage.updateTransform(); - - // update the background color - if(this.view.style.backgroundColor!=stage.backgroundColorString && !this.transparent)this.view.style.backgroundColor = stage.backgroundColorString; - - this.context.setTransform(1,0,0,1,0,0); - this.context.clearRect(0, 0, this.width, this.height) - this.renderDisplayObject(stage); - //as - - // run interaction! - if(stage.interactive) - { - //need to add some events! - if(!stage._interactiveEventsAdded) - { - stage._interactiveEventsAdded = true; - stage.interactionManager.setTarget(this); - } - } - - // remove frame updates.. - if(PIXI.Texture.frameUpdates.length > 0) - { - PIXI.Texture.frameUpdates = []; - } - - -} - -/** - * resizes the canvas view to the specified width and height - * - * @method resize - * @param width {Number} the new width of the canvas view - * @param height {Number} the new height of the canvas view - */ -PIXI.CanvasRenderer.prototype.resize = function(width, height) -{ - this.width = width; - this.height = height; - - this.view.width = width; - this.view.height = height; -} - -/** - * Renders a display object - * - * @method renderDisplayObject - * @param displayObject {DisplayObject} The displayObject to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject) -{ - // no loger recurrsive! - var transform; - var context = this.context; - - context.globalCompositeOperation = 'source-over'; - - // one the display object hits this. we can break the loop - var testObject = displayObject.last._iNext; - displayObject = displayObject.first; - - do - { - transform = displayObject.worldTransform; - - if(!displayObject.visible) - { - displayObject = displayObject.last._iNext; - continue; - } - - if(!displayObject.renderable) - { - displayObject = displayObject._iNext; - continue; - } - - if(displayObject instanceof PIXI.Sprite) - { - - var frame = displayObject.texture.frame; - - if(frame) - { - context.globalAlpha = displayObject.worldAlpha; - - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]); - - context.drawImage(displayObject.texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, - (displayObject.anchor.x) * -frame.width, - (displayObject.anchor.y) * -frame.height, - frame.width, - frame.height); - } - } - else if(displayObject instanceof PIXI.Strip) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - this.renderStrip(displayObject); - } - else if(displayObject instanceof PIXI.TilingSprite) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - this.renderTilingSprite(displayObject); - } - else if(displayObject instanceof PIXI.CustomRenderable) - { - displayObject.renderCanvas(this); - } - else if(displayObject instanceof PIXI.Graphics) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - PIXI.CanvasGraphics.renderGraphics(displayObject, context); - } - else if(displayObject instanceof PIXI.FilterBlock) - { - if(displayObject.open) - { - context.save(); - - var cacheAlpha = displayObject.mask.alpha; - var maskTransform = displayObject.mask.worldTransform; - - context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5]) - - displayObject.mask.worldAlpha = 0.5; - - context.worldAlpha = 0; - - PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, context); - // context.fillStyle = 0xFF0000; - // context.fillRect(0, 0, 200, 200); - context.clip(); - - displayObject.mask.worldAlpha = cacheAlpha; - //context.globalCompositeOperation = 'lighter'; - } - else - { - //context.globalCompositeOperation = 'source-over'; - context.restore(); - } - } - // count++ - displayObject = displayObject._iNext; - - - } - while(displayObject != testObject) - - -} - -/** - * Renders a flat strip - * - * @method renderStripFlat - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip) -{ - var context = this.context; - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - - context.beginPath(); - for (var i=1; i < length-2; i++) - { - - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - - }; - - context.fillStyle = "#FF0000"; - context.fill(); - context.closePath(); -} - -/** - * Renders a tiling sprite - * - * @method renderTilingSprite - * @param sprite {TilingSprite} The tilingsprite to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderTilingSprite = function(sprite) -{ - var context = this.context; - - context.globalAlpha = sprite.worldAlpha; - - if(!sprite.__tilePattern) sprite.__tilePattern = context.createPattern(sprite.texture.baseTexture.source, "repeat"); - - context.beginPath(); - - var tilePosition = sprite.tilePosition; - var tileScale = sprite.tileScale; - - // offset - context.scale(tileScale.x,tileScale.y); - context.translate(tilePosition.x, tilePosition.y); - - context.fillStyle = sprite.__tilePattern; - context.fillRect(-tilePosition.x,-tilePosition.y,sprite.width / tileScale.x, sprite.height / tileScale.y); - - context.scale(1/tileScale.x, 1/tileScale.y); - context.translate(-tilePosition.x, -tilePosition.y); - - context.closePath(); -} - -/** - * Renders a strip - * - * @method renderStrip - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStrip = function(strip) -{ - var context = this.context; - //context.globalCompositeOperation = 'lighter'; - // draw triangles!! - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - for (var i=1; i < length-2; i++) - { - - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; - var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height; - - - context.save(); - context.beginPath(); - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - context.closePath(); - - // context.fillStyle = "white"//rgb(1, 1, 1,1)); - // context.fill(); - context.clip(); - - - // Compute matrix transform - var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2; - var delta_a = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2; - var delta_b = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2; - var delta_c = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2; - var delta_d = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2; - var delta_e = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2; - var delta_f = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2; - - - - - context.transform(delta_a/delta, delta_d/delta, - delta_b/delta, delta_e/delta, - delta_c/delta, delta_f/delta); - - context.drawImage(strip.texture.baseTexture.source, 0, 0); - context.restore(); - }; - -// context.globalCompositeOperation = 'source-over'; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * A set of functions used by the canvas renderer to draw the primitive graphics data - * - * @class CanvasGraphics - */ -PIXI.CanvasGraphics = function() -{ - -} - - -/* - * Renders the graphics object - * - * @static - * @private - * @method renderGraphics - * @param graphics {Graphics} - * @param context {Context2D} - */ -PIXI.CanvasGraphics.renderGraphics = function(graphics, context) -{ - var worldAlpha = graphics.worldAlpha; - - for (var i=0; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - var points = data.points; - - context.strokeStyle = color = '#' + ('00000' + ( data.lineColor | 0).toString(16)).substr(-6); - - context.lineWidth = data.lineWidth; - - if(data.type == PIXI.Graphics.POLY) - { - //if(data.lineWidth <= 0)continue; - - context.beginPath(); - - context.moveTo(points[0], points[1]); - - for (var j=1; j < points.length/2; j++) - { - context.lineTo(points[j * 2], points[j * 2 + 1]); - } - - // if the first and last point are the same close the path - much neater :) - if(points[0] == points[points.length-2] && points[1] == points[points.length-1]) - { - context.closePath(); - } - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - else if(data.type == PIXI.Graphics.RECT) - { - - // TODO - need to be Undefined! - if(data.fillColor) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fillRect(points[0], points[1], points[2], points[3]); - - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.strokeRect(points[0], points[1], points[2], points[3]); - } - - } - else if(data.type == PIXI.Graphics.CIRC) - { - // TODO - need to be Undefined! - context.beginPath(); - context.arc(points[0], points[1], points[2],0,2*Math.PI); - context.closePath(); - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - else if(data.type == PIXI.Graphics.ELIP) - { - - // elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - - var elipseData = data.points; - - var w = elipseData[2] * 2; - var h = elipseData[3] * 2; - - var x = elipseData[0] - w/2; - var y = elipseData[1] - h/2; - - context.beginPath(); - - var kappa = .5522848, - ox = (w / 2) * kappa, // control point offset horizontal - oy = (h / 2) * kappa, // control point offset vertical - xe = x + w, // x-end - ye = y + h, // y-end - xm = x + w / 2, // x-middle - ym = y + h / 2; // y-middle - - context.moveTo(x, ym); - context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - - context.closePath(); - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - - }; -} - -/* - * Renders a graphics mask - * - * @static - * @private - * @method renderGraphicsMask - * @param graphics {Graphics} - * @param context {Context2D} - */ -PIXI.CanvasGraphics.renderGraphicsMask = function(graphics, context) -{ - var worldAlpha = graphics.worldAlpha; - - var len = graphics.graphicsData.length; - if(len > 1) - { - len = 1; - console.log("Pixi.js warning: masks in canvas can only mask using the first path in the graphics object") - } - - for (var i=0; i < 1; i++) - { - var data = graphics.graphicsData[i]; - var points = data.points; - - if(data.type == PIXI.Graphics.POLY) - { - //if(data.lineWidth <= 0)continue; - - context.beginPath(); - context.moveTo(points[0], points[1]); - - for (var j=1; j < points.length/2; j++) - { - context.lineTo(points[j * 2], points[j * 2 + 1]); - } - - // if the first and last point are the same close the path - much neater :) - if(points[0] == points[points.length-2] && points[1] == points[points.length-1]) - { - context.closePath(); - } - - } - else if(data.type == PIXI.Graphics.RECT) - { - context.beginPath(); - context.rect(points[0], points[1], points[2], points[3]); - context.closePath(); - } - else if(data.type == PIXI.Graphics.CIRC) - { - // TODO - need to be Undefined! - context.beginPath(); - context.arc(points[0], points[1], points[2],0,2*Math.PI); - context.closePath(); - } - else if(data.type == PIXI.Graphics.ELIP) - { - - // elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - var elipseData = data.points; - - var w = elipseData[2] * 2; - var h = elipseData[3] * 2; - - var x = elipseData[0] - w/2; - var y = elipseData[1] - h/2; - - context.beginPath(); - - var kappa = .5522848, - ox = (w / 2) * kappa, // control point offset horizontal - oy = (h / 2) * kappa, // control point offset vertical - xe = x + w, // x-end - ye = y + h, // y-end - xm = x + w / 2, // x-middle - ym = y + h / 2; // y-middle - - context.moveTo(x, ym); - context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - context.closePath(); - } - - - }; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * The Graphics class contains a set of methods that you can use to create primitive shapes and lines. - * It is important to know that with the webGL renderer only simple polys can be filled at this stage - * Complex polys will not be filled. Heres an example of a complex poly: http://www.goodboydigital.com/wp-content/uploads/2013/06/complexPolygon.png - * - * @class Graphics - * @extends DisplayObjectContainer - * @constructor - */ -PIXI.Graphics = function() -{ - PIXI.DisplayObjectContainer.call( this ); - - this.renderable = true; - - /** - * The alpha of the fill of this graphics object - * - * @property fillAlpha - * @type Number - */ - this.fillAlpha = 1; - - /** - * The width of any lines drawn - * - * @property lineWidth - * @type Number - */ - this.lineWidth = 0; - - /** - * The color of any lines drawn - * - * @property lineColor - * @type String - */ - this.lineColor = "black"; - - /** - * Graphics data - * - * @property graphicsData - * @type Array - * @private - */ - this.graphicsData = []; - - /** - * Current path - * - * @property currentPath - * @type Object - * @private - */ - this.currentPath = {points:[]}; -} - -// constructor -PIXI.Graphics.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Graphics.prototype.constructor = PIXI.Graphics; - -/** - * Specifies a line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method. - * - * @method lineStyle - * @param lineWidth {Number} width of the line to draw, will update the object's stored style - * @param color {Number} color of the line to draw, will update the object's stored style - * @param alpha {Number} alpha of the line to draw, will update the object's stored style - */ -PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.lineWidth = lineWidth || 0; - this.lineColor = color || 0; - this.lineAlpha = (alpha == undefined) ? 1 : alpha; - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; - - this.graphicsData.push(this.currentPath); -} - -/** - * Moves the current drawing position to (x, y). - * - * @method moveTo - * @param x {Number} the X coord to move to - * @param y {Number} the Y coord to move to - */ -PIXI.Graphics.prototype.moveTo = function(x, y) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; - - this.currentPath.points.push(x, y); - - this.graphicsData.push(this.currentPath); -} - -/** - * Draws a line using the current line style from the current drawing position to (x, y); - * the current drawing position is then set to (x, y). - * - * @method lineTo - * @param x {Number} the X coord to draw to - * @param y {Number} the Y coord to draw to - */ -PIXI.Graphics.prototype.lineTo = function(x, y) -{ - this.currentPath.points.push(x, y); - this.dirty = true; -} - -/** - * Specifies a simple one-color fill that subsequent calls to other Graphics methods - * (such as lineTo() or drawCircle()) use when drawing. - * - * @method beginFill - * @param color {uint} the color of the fill - * @param alpha {Number} the alpha - */ -PIXI.Graphics.prototype.beginFill = function(color, alpha) -{ - this.filling = true; - this.fillColor = color || 0; - this.fillAlpha = alpha || 1; -} - -/** - * Applies a fill to the lines and shapes that were added since the last call to the beginFill() method. - * - * @method endFill - */ -PIXI.Graphics.prototype.endFill = function() -{ - this.filling = false; - this.fillColor = null; - this.fillAlpha = 1; -} - -/** - * @method drawRect - * - * @param x {Number} The X coord of the top-left of the rectangle - * @param y {Number} The Y coord of the top-left of the rectangle - * @param width {Number} The width of the rectangle - * @param height {Number} The height of the rectangle - */ -PIXI.Graphics.prototype.drawRect = function( x, y, width, height ) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, width, height], type:PIXI.Graphics.RECT}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Draws a circle. - * - * @method drawCircle - * @param x {Number} The X coord of the center of the circle - * @param y {Number} The Y coord of the center of the circle - * @param radius {Number} The radius of the circle - */ -PIXI.Graphics.prototype.drawCircle = function( x, y, radius) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, radius, radius], type:PIXI.Graphics.CIRC}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Draws an elipse. - * - * @method drawElipse - * @param x {Number} - * @param y {Number} - * @param width {Number} - * @param height {Number} - */ -PIXI.Graphics.prototype.drawElipse = function( x, y, width, height) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, width, height], type:PIXI.Graphics.ELIP}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings. - * - * @method clear - */ -PIXI.Graphics.prototype.clear = function() -{ - this.lineWidth = 0; - this.filling = false; - - this.dirty = true; - this.clearDirty = true; - this.graphicsData = []; -} - -// SOME TYPES: -PIXI.Graphics.POLY = 0; -PIXI.Graphics.RECT = 1; -PIXI.Graphics.CIRC = 2; -PIXI.Graphics.ELIP = 3; - -/** - * @author Mat Groves http://matgroves.com/ - */ - -PIXI.Strip = function(texture, width, height) -{ - PIXI.DisplayObjectContainer.call( this ); - this.texture = texture; - this.blendMode = PIXI.blendModes.NORMAL; - - try - { - this.uvs = new Float32Array([0, 1, - 1, 1, - 1, 0, 0,1]); - - this.verticies = new Float32Array([0, 0, - 0,0, - 0,0, 0, - 0, 0]); - - this.colors = new Float32Array([1, 1, 1, 1]); - - this.indices = new Uint16Array([0, 1, 2, 3]); - } - catch(error) - { - this.uvs = [0, 1, - 1, 1, - 1, 0, 0,1]; - - this.verticies = [0, 0, - 0,0, - 0,0, 0, - 0, 0]; - - this.colors = [1, 1, 1, 1]; - - this.indices = [0, 1, 2, 3]; - } - - - /* - this.uvs = new Float32Array() - this.verticies = new Float32Array() - this.colors = new Float32Array() - this.indices = new Uint16Array() -*/ - this.width = width; - this.height = height; - - // load the texture! - if(texture.baseTexture.hasLoaded) - { - this.width = this.texture.frame.width; - this.height = this.texture.frame.height; - this.updateFrame = true; - } - else - { - this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); - } - - this.renderable = true; -} - -// constructor -PIXI.Strip.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Strip.prototype.constructor = PIXI.Strip; - -PIXI.Strip.prototype.setTexture = function(texture) -{ - //TODO SET THE TEXTURES - //TODO VISIBILITY - - // stop current texture - this.texture = texture; - this.width = texture.frame.width; - this.height = texture.frame.height; - this.updateFrame = true; -} - -PIXI.Strip.prototype.onTextureUpdate = function(event) -{ - this.updateFrame = true; -} -// some helper functions.. - - -/** - * @author Mat Groves http://matgroves.com/ - */ - - -PIXI.Rope = function(texture, points) -{ - PIXI.Strip.call( this, texture ); - this.points = points; - - try - { - this.verticies = new Float32Array( points.length * 4); - this.uvs = new Float32Array( points.length * 4); - this.colors = new Float32Array( points.length * 2); - this.indices = new Uint16Array( points.length * 2); - } - catch(error) - { - this.verticies = verticies - - this.uvs = uvs - this.colors = colors - this.indices = indices - } - - this.refresh(); -} - - -// constructor -PIXI.Rope.prototype = Object.create( PIXI.Strip.prototype ); -PIXI.Rope.prototype.constructor = PIXI.Rope; - -PIXI.Rope.prototype.refresh = function() -{ - var points = this.points; - if(points.length < 1)return; - - var uvs = this.uvs - var indices = this.indices; - var colors = this.colors; - - var lastPoint = points[0]; - var nextPoint; - var perp = {x:0, y:0}; - var point = points[0]; - - this.count-=0.2; - - - uvs[0] = 0 - uvs[1] = 1 - uvs[2] = 0 - uvs[3] = 1 - - colors[0] = 1; - colors[1] = 1; - - indices[0] = 0; - indices[1] = 1; - - var total = points.length; - - for (var i = 1; i < total; i++) - { - - var point = points[i]; - var index = i * 4; - // time to do some smart drawing! - var amount = i/(total-1) - - if(i%2) - { - uvs[index] = amount; - uvs[index+1] = 0; - - uvs[index+2] = amount - uvs[index+3] = 1 - - } - else - { - uvs[index] = amount - uvs[index+1] = 0 - - uvs[index+2] = amount - uvs[index+3] = 1 - } - - index = i * 2; - colors[index] = 1; - colors[index+1] = 1; - - index = i * 2; - indices[index] = index; - indices[index + 1] = index + 1; - - lastPoint = point; - } -} - -PIXI.Rope.prototype.updateTransform = function() -{ - - var points = this.points; - if(points.length < 1)return; - - var verticies = this.verticies - - var lastPoint = points[0]; - var nextPoint; - var perp = {x:0, y:0}; - var point = points[0]; - - this.count-=0.2; - - verticies[0] = point.x + perp.x - verticies[1] = point.y + perp.y //+ 200 - verticies[2] = point.x - perp.x - verticies[3] = point.y - perp.y//+200 - // time to do some smart drawing! - - var total = points.length; - - for (var i = 1; i < total; i++) - { - - var point = points[i]; - var index = i * 4; - - if(i < points.length-1) - { - nextPoint = points[i+1]; - } - else - { - nextPoint = point - } - - perp.y = -(nextPoint.x - lastPoint.x); - perp.x = nextPoint.y - lastPoint.y; - - var ratio = (1 - (i / (total-1))) * 10; - if(ratio > 1)ratio = 1; - - var perpLength = Math.sqrt(perp.x * perp.x + perp.y * perp.y); - var num = this.texture.height/2//(20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio; - perp.x /= perpLength; - perp.y /= perpLength; - - perp.x *= num; - perp.y *= num; - - verticies[index] = point.x + perp.x - verticies[index+1] = point.y + perp.y - verticies[index+2] = point.x - perp.x - verticies[index+3] = point.y - perp.y - - lastPoint = point; - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call( this ); -} - -PIXI.Rope.prototype.setTexture = function(texture) -{ - // stop current texture - this.texture = texture; - this.updateFrame = true; -} - - - - - -/** - * @author Mat Groves http://matgroves.com/ - */ - -/** - * A tiling sprite is a fast way of rendering a tiling image - * - * @class TilingSprite - * @extends DisplayObjectContainer - * @constructor - * @param texture {Texture} the texture of the tiling sprite - * @param width {Number} the width of the tiling sprite - * @param height {Number} the height of the tiling sprite - */ -PIXI.TilingSprite = function(texture, width, height) -{ - PIXI.DisplayObjectContainer.call( this ); - - /** - * The texture that the sprite is using - * - * @property texture - * @type Texture - */ - this.texture = texture; - - /** - * The width of the tiling sprite - * - * @property width - * @type Number - */ - this.width = width; - - /** - * The height of the tiling sprite - * - * @property height - * @type Number - */ - this.height = height; - - /** - * The scaling of the image that is being tiled - * - * @property tileScale - * @type Point - */ - this.tileScale = new PIXI.Point(1,1); - - /** - * The offset position of the image that is being tiled - * - * @property tilePosition - * @type Point - */ - this.tilePosition = new PIXI.Point(0,0); - - this.renderable = true; - - this.blendMode = PIXI.blendModes.NORMAL -} - -// constructor -PIXI.TilingSprite.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.TilingSprite.prototype.constructor = PIXI.TilingSprite; - -/** - * Sets the texture of the tiling sprite - * - * @method setTexture - * @param texture {Texture} The PIXI texture that is displayed by the sprite - */ -PIXI.TilingSprite.prototype.setTexture = function(texture) -{ - //TODO SET THE TEXTURES - //TODO VISIBILITY - - // stop current texture - this.texture = texture; - this.updateFrame = true; -} - -/** - * When the texture is updated, this event will fire to update the frame - * - * @method onTextureUpdate - * @param event - * @private - */ -PIXI.TilingSprite.prototype.onTextureUpdate = function(event) -{ - this.updateFrame = true; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi - * - * Awesome JS run time provided by EsotericSoftware - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -/** - * A class that enables the you to import and run your spine animations in pixi. - * Spine animation data needs to be loaded using the PIXI.AssetLoader or PIXI.SpineLoader before it can be used by this class - * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source - * - * @class Spine - * @extends DisplayObjectContainer - * @constructor - * @param url {String} The url of the spine anim file to be used - */ -PIXI.Spine = function(url) -{ - PIXI.DisplayObjectContainer.call(this); - - this.spineData = PIXI.AnimCache[url]; - - if(!this.spineData) - { - throw new Error("Spine data must be preloaded using PIXI.SpineLoader or PIXI.AssetLoader: " + url); - return; - } - - this.count = 0; - - this.sprites = []; - - this.skeleton = new spine.Skeleton(this.spineData); - this.skeleton.updateWorldTransform(); - - this.stateData = new spine.AnimationStateData(this.spineData); - this.state = new spine.AnimationState(this.stateData); - - // add the sprites.. - for (var i = 0; i < this.skeleton.drawOrder.length; i++) { - - var attachmentName = this.skeleton.drawOrder[i].data.attachmentName; - - // kind of an assumtion here. that its a png - if(!PIXI.TextureCache[attachmentName]) - { - attachmentName += ".png"; - } - - - var sprite = new PIXI.Sprite(PIXI.Texture.fromFrame(attachmentName)); - sprite.anchor.x = sprite.anchor.y = 0.5; - this.addChild(sprite); - this.sprites.push(sprite); - }; -} - -PIXI.Spine.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Spine.prototype.constructor = PIXI.Spine; - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.Spine.prototype.updateTransform = function() -{ - // TODO should make this time based really.. - this.state.update(1/60); - this.state.apply(this.skeleton); - this.skeleton.updateWorldTransform(); - - - for (var i = 0; i < this.skeleton.drawOrder.length; i++) - { - var slot = this.skeleton.drawOrder[i]; - - var x = slot.bone.worldX + slot.attachment.x * slot.bone.m00 + slot.attachment.y * slot.bone.m01 + slot.attachment.width * 0.5; - var y = slot.bone.worldY + slot.attachment.x * slot.bone.m10 + slot.attachment.y * slot.bone.m11 + slot.attachment.height * 0.5; - //console.log(x + ' : ' + y); - - - //console.log(slot.attachment.name) - if(slot.cacheName != slot.attachment.name) - { - var attachmentName = slot.attachment.name; - - if(!PIXI.TextureCache[attachmentName]) - { - attachmentName += ".png"; - } - - this.sprites[i].setTexture(PIXI.TextureCache[attachmentName]); - - slot.cacheName = slot.attachment.name; - } - - x += -((slot.attachment.width * (slot.bone.worldScaleX + slot.attachment.scaleX - 1))>>1); - y += -((slot.attachment.height * (slot.bone.worldScaleY + slot.attachment.scaleY - 1))>>1); - - - this.sprites[i].position.x = x; - this.sprites[i].position.y = y; - this.sprites[i].rotation = (-(slot.bone.worldRotation + slot.attachment.rotation)) * (Math.PI/180); - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call(this); -} - -/* - * Awesome JS run time provided by EsotericSoftware - * - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -var spine = {}; - -spine.BoneData = function (name, parent) { - this.name = name; - this.parent = parent; -}; -spine.BoneData.prototype = { - length: 0, - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1 -}; - -spine.SlotData = function (name, boneData) { - this.name = name; - this.boneData = boneData; -}; -spine.SlotData.prototype = { - r: 1, g: 1, b: 1, a: 1, - attachmentName: null -}; - -spine.Bone = function (boneData, parent) { - this.data = boneData; - this.parent = parent; - this.setToSetupPose(); -}; -spine.Bone.yDown = false; -spine.Bone.prototype = { - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1, - m00: 0, m01: 0, worldX: 0, // a b x - m10: 0, m11: 0, worldY: 0, // c d y - worldRotation: 0, - worldScaleX: 1, worldScaleY: 1, - updateWorldTransform: function (flipX, flipY) { - var parent = this.parent; - if (parent != null) { - this.worldX = this.x * parent.m00 + this.y * parent.m01 + parent.worldX; - this.worldY = this.x * parent.m10 + this.y * parent.m11 + parent.worldY; - this.worldScaleX = parent.worldScaleX * this.scaleX; - this.worldScaleY = parent.worldScaleY * this.scaleY; - this.worldRotation = parent.worldRotation + this.rotation; - } else { - this.worldX = this.x; - this.worldY = this.y; - this.worldScaleX = this.scaleX; - this.worldScaleY = this.scaleY; - this.worldRotation = this.rotation; - } - var radians = this.worldRotation * Math.PI / 180; - var cos = Math.cos(radians); - var sin = Math.sin(radians); - this.m00 = cos * this.worldScaleX; - this.m10 = sin * this.worldScaleX; - this.m01 = -sin * this.worldScaleY; - this.m11 = cos * this.worldScaleY; - if (flipX) { - this.m00 = -this.m00; - this.m01 = -this.m01; - } - if (flipY) { - this.m10 = -this.m10; - this.m11 = -this.m11; - } - if (spine.Bone.yDown) { - this.m10 = -this.m10; - this.m11 = -this.m11; - } - }, - setToSetupPose: function () { - var data = this.data; - this.x = data.x; - this.y = data.y; - this.rotation = data.rotation; - this.scaleX = data.scaleX; - this.scaleY = data.scaleY; - } -}; - -spine.Slot = function (slotData, skeleton, bone) { - this.data = slotData; - this.skeleton = skeleton; - this.bone = bone; - this.setToSetupPose(); -}; -spine.Slot.prototype = { - r: 1, g: 1, b: 1, a: 1, - _attachmentTime: 0, - attachment: null, - setAttachment: function (attachment) { - this.attachment = attachment; - this._attachmentTime = this.skeleton.time; - }, - setAttachmentTime: function (time) { - this._attachmentTime = this.skeleton.time - time; - }, - getAttachmentTime: function () { - return this.skeleton.time - this._attachmentTime; - }, - setToSetupPose: function () { - var data = this.data; - this.r = data.r; - this.g = data.g; - this.b = data.b; - this.a = data.a; - - var slotDatas = this.skeleton.data.slots; - for (var i = 0, n = slotDatas.length; i < n; i++) { - if (slotDatas[i] == data) { - this.setAttachment(!data.attachmentName ? null : this.skeleton.getAttachmentBySlotIndex(i, data.attachmentName)); - break; - } - } - } -}; - -spine.Skin = function (name) { - this.name = name; - this.attachments = {}; -}; -spine.Skin.prototype = { - addAttachment: function (slotIndex, name, attachment) { - this.attachments[slotIndex + ":" + name] = attachment; - }, - getAttachment: function (slotIndex, name) { - return this.attachments[slotIndex + ":" + name]; - }, - _attachAll: function (skeleton, oldSkin) { - for (var key in oldSkin.attachments) { - var colon = key.indexOf(":"); - var slotIndex = parseInt(key.substring(0, colon)); - var name = key.substring(colon + 1); - var slot = skeleton.slots[slotIndex]; - if (slot.attachment && slot.attachment.name == name) { - var attachment = this.getAttachment(slotIndex, name); - if (attachment) slot.setAttachment(attachment); - } - } - } -}; - -spine.Animation = function (name, timelines, duration) { - this.name = name; - this.timelines = timelines; - this.duration = duration; -}; -spine.Animation.prototype = { - apply: function (skeleton, time, loop) { - if (loop && this.duration != 0) time %= this.duration; - var timelines = this.timelines; - for (var i = 0, n = timelines.length; i < n; i++) - timelines[i].apply(skeleton, time, 1); - }, - mix: function (skeleton, time, loop, alpha) { - if (loop && this.duration != 0) time %= this.duration; - var timelines = this.timelines; - for (var i = 0, n = timelines.length; i < n; i++) - timelines[i].apply(skeleton, time, alpha); - } -}; - -spine.binarySearch = function (values, target, step) { - var low = 0; - var high = Math.floor(values.length / step) - 2; - if (high == 0) return step; - var current = high >>> 1; - while (true) { - if (values[(current + 1) * step] <= target) - low = current + 1; - else - high = current; - if (low == high) return (low + 1) * step; - current = (low + high) >>> 1; - } -}; -spine.linearSearch = function (values, target, step) { - for (var i = 0, last = values.length - step; i <= last; i += step) - if (values[i] > target) return i; - return -1; -}; - -spine.Curves = function (frameCount) { - this.curves = []; // dfx, dfy, ddfx, ddfy, dddfx, dddfy, ... - this.curves.length = (frameCount - 1) * 6; -}; -spine.Curves.prototype = { - setLinear: function (frameIndex) { - this.curves[frameIndex * 6] = 0/*LINEAR*/; - }, - setStepped: function (frameIndex) { - this.curves[frameIndex * 6] = -1/*STEPPED*/; - }, - /** Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next. - * cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of - * the difference between the keyframe's values. */ - setCurve: function (frameIndex, cx1, cy1, cx2, cy2) { - var subdiv_step = 1 / 10/*BEZIER_SEGMENTS*/; - var subdiv_step2 = subdiv_step * subdiv_step; - var subdiv_step3 = subdiv_step2 * subdiv_step; - var pre1 = 3 * subdiv_step; - var pre2 = 3 * subdiv_step2; - var pre4 = 6 * subdiv_step2; - var pre5 = 6 * subdiv_step3; - var tmp1x = -cx1 * 2 + cx2; - var tmp1y = -cy1 * 2 + cy2; - var tmp2x = (cx1 - cx2) * 3 + 1; - var tmp2y = (cy1 - cy2) * 3 + 1; - var i = frameIndex * 6; - var curves = this.curves; - curves[i] = cx1 * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3; - curves[i + 1] = cy1 * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3; - curves[i + 2] = tmp1x * pre4 + tmp2x * pre5; - curves[i + 3] = tmp1y * pre4 + tmp2y * pre5; - curves[i + 4] = tmp2x * pre5; - curves[i + 5] = tmp2y * pre5; - }, - getCurvePercent: function (frameIndex, percent) { - percent = percent < 0 ? 0 : (percent > 1 ? 1 : percent); - var curveIndex = frameIndex * 6; - var curves = this.curves; - var dfx = curves[curveIndex]; - if (!dfx/*LINEAR*/) return percent; - if (dfx == -1/*STEPPED*/) return 0; - var dfy = curves[curveIndex + 1]; - var ddfx = curves[curveIndex + 2]; - var ddfy = curves[curveIndex + 3]; - var dddfx = curves[curveIndex + 4]; - var dddfy = curves[curveIndex + 5]; - var x = dfx, y = dfy; - var i = 10/*BEZIER_SEGMENTS*/ - 2; - while (true) { - if (x >= percent) { - var lastX = x - dfx; - var lastY = y - dfy; - return lastY + (y - lastY) * (percent - lastX) / (x - lastX); - } - if (i == 0) break; - i--; - dfx += ddfx; - dfy += ddfy; - ddfx += dddfx; - ddfy += dddfy; - x += dfx; - y += dfy; - } - return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1. - } -}; - -spine.RotateTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, angle, ... - this.frames.length = frameCount * 2; -}; -spine.RotateTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, angle) { - frameIndex *= 2; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = angle; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 2]) { // Time is after last frame. - var amount = bone.data.rotation + frames[frames.length - 1] - bone.rotation; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - bone.rotation += amount * alpha; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 2); - var lastFrameValue = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex - 2/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 2 - 1, percent); - - var amount = frames[frameIndex + 1/*FRAME_VALUE*/] - lastFrameValue; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - amount = bone.data.rotation + (lastFrameValue + amount * percent) - bone.rotation; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - bone.rotation += amount * alpha; - } -}; - -spine.TranslateTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, x, y, ... - this.frames.length = frameCount * 3; -}; -spine.TranslateTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 3; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 3; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = x; - this.frames[frameIndex + 2] = y; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 3]) { // Time is after last frame. - bone.x += (bone.data.x + frames[frames.length - 2] - bone.x) * alpha; - bone.y += (bone.data.y + frames[frames.length - 1] - bone.y) * alpha; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 3); - var lastFrameX = frames[frameIndex - 2]; - var lastFrameY = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent); - bone.x += (bone.data.x + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.x) * alpha; - bone.y += (bone.data.y + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.y) * alpha; - } -}; - -spine.ScaleTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, x, y, ... - this.frames.length = frameCount * 3; -}; -spine.ScaleTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 3; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 3; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = x; - this.frames[frameIndex + 2] = y; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 3]) { // Time is after last frame. - bone.scaleX += (bone.data.scaleX - 1 + frames[frames.length - 2] - bone.scaleX) * alpha; - bone.scaleY += (bone.data.scaleY - 1 + frames[frames.length - 1] - bone.scaleY) * alpha; - - - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 3); - var lastFrameX = frames[frameIndex - 2]; - var lastFrameY = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent); - - bone.scaleX += (bone.data.scaleX - 1 + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.scaleX) * alpha; - bone.scaleY += (bone.data.scaleY - 1 + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.scaleY) * alpha; - } -}; - -spine.ColorTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, r, g, b, a, ... - this.frames.length = frameCount * 5; -}; -spine.ColorTimeline.prototype = { - slotIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 5; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = r; - this.frames[frameIndex + 2] = g; - this.frames[frameIndex + 3] = b; - this.frames[frameIndex + 4] = a; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - var slot = skeleton.slots[this.slotIndex]; - - if (time >= frames[frames.length - 5]) { // Time is after last frame. - var i = frames.length - 1; - slot.r = frames[i - 3]; - slot.g = frames[i - 2]; - slot.b = frames[i - 1]; - slot.a = frames[i]; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 5); - var lastFrameR = frames[frameIndex - 4]; - var lastFrameG = frames[frameIndex - 3]; - var lastFrameB = frames[frameIndex - 2]; - var lastFrameA = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex - 5/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 5 - 1, percent); - - var r = lastFrameR + (frames[frameIndex + 1/*FRAME_R*/] - lastFrameR) * percent; - var g = lastFrameG + (frames[frameIndex + 2/*FRAME_G*/] - lastFrameG) * percent; - var b = lastFrameB + (frames[frameIndex + 3/*FRAME_B*/] - lastFrameB) * percent; - var a = lastFrameA + (frames[frameIndex + 4/*FRAME_A*/] - lastFrameA) * percent; - if (alpha < 1) { - slot.r += (r - slot.r) * alpha; - slot.g += (g - slot.g) * alpha; - slot.b += (b - slot.b) * alpha; - slot.a += (a - slot.a) * alpha; - } else { - slot.r = r; - slot.g = g; - slot.b = b; - slot.a = a; - } - } -}; - -spine.AttachmentTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, ... - this.frames.length = frameCount; - this.attachmentNames = []; // time, ... - this.attachmentNames.length = frameCount; -}; -spine.AttachmentTimeline.prototype = { - slotIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, attachmentName) { - this.frames[frameIndex] = time; - this.attachmentNames[frameIndex] = attachmentName; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var frameIndex; - if (time >= frames[frames.length - 1]) // Time is after last frame. - frameIndex = frames.length - 1; - else - frameIndex = spine.binarySearch(frames, time, 1) - 1; - - var attachmentName = this.attachmentNames[frameIndex]; - //console.log(skeleton.slots[this.slotIndex]) - - // change the name! - // skeleton.slots[this.slotIndex].attachmentName = attachmentName; - - skeleton.slots[this.slotIndex].setAttachment(!attachmentName ? null : skeleton.getAttachmentBySlotIndex(this.slotIndex, attachmentName)); - } -}; - -spine.SkeletonData = function () { - this.bones = []; - this.slots = []; - this.skins = []; - this.animations = []; -}; -spine.SkeletonData.prototype = { - defaultSkin: null, - /** @return May be null. */ - findBone: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].name == boneName) return bones[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findBoneIndex: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].name == boneName) return i; - return -1; - }, - /** @return May be null. */ - findSlot: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) { - if (slots[i].name == slotName) return slot[i]; - } - return null; - }, - /** @return -1 if the bone was not found. */ - findSlotIndex: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].name == slotName) return i; - return -1; - }, - /** @return May be null. */ - findSkin: function (skinName) { - var skins = this.skins; - for (var i = 0, n = skins.length; i < n; i++) - if (skins[i].name == skinName) return skins[i]; - return null; - }, - /** @return May be null. */ - findAnimation: function (animationName) { - var animations = this.animations; - for (var i = 0, n = animations.length; i < n; i++) - if (animations[i].name == animationName) return animations[i]; - return null; - } -}; - -spine.Skeleton = function (skeletonData) { - this.data = skeletonData; - - this.bones = []; - for (var i = 0, n = skeletonData.bones.length; i < n; i++) { - var boneData = skeletonData.bones[i]; - var parent = !boneData.parent ? null : this.bones[skeletonData.bones.indexOf(boneData.parent)]; - this.bones.push(new spine.Bone(boneData, parent)); - } - - this.slots = []; - this.drawOrder = []; - for (var i = 0, n = skeletonData.slots.length; i < n; i++) { - var slotData = skeletonData.slots[i]; - var bone = this.bones[skeletonData.bones.indexOf(slotData.boneData)]; - var slot = new spine.Slot(slotData, this, bone); - this.slots.push(slot); - this.drawOrder.push(slot); - } -}; -spine.Skeleton.prototype = { - x: 0, y: 0, - skin: null, - r: 1, g: 1, b: 1, a: 1, - time: 0, - flipX: false, flipY: false, - /** Updates the world transform for each bone. */ - updateWorldTransform: function () { - var flipX = this.flipX; - var flipY = this.flipY; - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - bones[i].updateWorldTransform(flipX, flipY); - }, - /** Sets the bones and slots to their setup pose values. */ - setToSetupPose: function () { - this.setBonesToSetupPose(); - this.setSlotsToSetupPose(); - }, - setBonesToSetupPose: function () { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - bones[i].setToSetupPose(); - }, - setSlotsToSetupPose: function () { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - slots[i].setToSetupPose(i); - }, - /** @return May return null. */ - getRootBone: function () { - return this.bones.length == 0 ? null : this.bones[0]; - }, - /** @return May be null. */ - findBone: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].data.name == boneName) return bones[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findBoneIndex: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].data.name == boneName) return i; - return -1; - }, - /** @return May be null. */ - findSlot: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].data.name == slotName) return slots[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findSlotIndex: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].data.name == slotName) return i; - return -1; - }, - setSkinByName: function (skinName) { - var skin = this.data.findSkin(skinName); - if (!skin) throw "Skin not found: " + skinName; - this.setSkin(skin); - }, - /** Sets the skin used to look up attachments not found in the {@link SkeletonData#getDefaultSkin() default skin}. Attachments - * from the new skin are attached if the corresponding attachment from the old skin was attached. - * @param newSkin May be null. */ - setSkin: function (newSkin) { - if (this.skin && newSkin) newSkin._attachAll(this, this.skin); - this.skin = newSkin; - }, - /** @return May be null. */ - getAttachmentBySlotName: function (slotName, attachmentName) { - return this.getAttachmentBySlotIndex(this.data.findSlotIndex(slotName), attachmentName); - }, - /** @return May be null. */ - getAttachmentBySlotIndex: function (slotIndex, attachmentName) { - if (this.skin) { - var attachment = this.skin.getAttachment(slotIndex, attachmentName); - if (attachment) return attachment; - } - if (this.data.defaultSkin) return this.data.defaultSkin.getAttachment(slotIndex, attachmentName); - return null; - }, - /** @param attachmentName May be null. */ - setAttachment: function (slotName, attachmentName) { - var slots = this.slots; - for (var i = 0, n = slots.size; i < n; i++) { - var slot = slots[i]; - if (slot.data.name == slotName) { - var attachment = null; - if (attachmentName) { - - attachment = this.getAttachment(i, attachmentName); - if (attachment == null) throw "Attachment not found: " + attachmentName + ", for slot: " + slotName; - } - - slot.setAttachment(attachment); - return; - } - } - throw "Slot not found: " + slotName; - }, - update: function (delta) { - time += delta; - } -}; - -spine.AttachmentType = { - region: 0 -}; - -spine.RegionAttachment = function () { - this.offset = []; - this.offset.length = 8; - this.uvs = []; - this.uvs.length = 8; -}; -spine.RegionAttachment.prototype = { - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1, - width: 0, height: 0, - rendererObject: null, - regionOffsetX: 0, regionOffsetY: 0, - regionWidth: 0, regionHeight: 0, - regionOriginalWidth: 0, regionOriginalHeight: 0, - setUVs: function (u, v, u2, v2, rotate) { - var uvs = this.uvs; - if (rotate) { - uvs[2/*X2*/] = u; - uvs[3/*Y2*/] = v2; - uvs[4/*X3*/] = u; - uvs[5/*Y3*/] = v; - uvs[6/*X4*/] = u2; - uvs[7/*Y4*/] = v; - uvs[0/*X1*/] = u2; - uvs[1/*Y1*/] = v2; - } else { - uvs[0/*X1*/] = u; - uvs[1/*Y1*/] = v2; - uvs[2/*X2*/] = u; - uvs[3/*Y2*/] = v; - uvs[4/*X3*/] = u2; - uvs[5/*Y3*/] = v; - uvs[6/*X4*/] = u2; - uvs[7/*Y4*/] = v2; - } - }, - updateOffset: function () { - var regionScaleX = this.width / this.regionOriginalWidth * this.scaleX; - var regionScaleY = this.height / this.regionOriginalHeight * this.scaleY; - var localX = -this.width / 2 * this.scaleX + this.regionOffsetX * regionScaleX; - var localY = -this.height / 2 * this.scaleY + this.regionOffsetY * regionScaleY; - var localX2 = localX + this.regionWidth * regionScaleX; - var localY2 = localY + this.regionHeight * regionScaleY; - var radians = this.rotation * Math.PI / 180; - var cos = Math.cos(radians); - var sin = Math.sin(radians); - var localXCos = localX * cos + this.x; - var localXSin = localX * sin; - var localYCos = localY * cos + this.y; - var localYSin = localY * sin; - var localX2Cos = localX2 * cos + this.x; - var localX2Sin = localX2 * sin; - var localY2Cos = localY2 * cos + this.y; - var localY2Sin = localY2 * sin; - var offset = this.offset; - offset[0/*X1*/] = localXCos - localYSin; - offset[1/*Y1*/] = localYCos + localXSin; - offset[2/*X2*/] = localXCos - localY2Sin; - offset[3/*Y2*/] = localY2Cos + localXSin; - offset[4/*X3*/] = localX2Cos - localY2Sin; - offset[5/*Y3*/] = localY2Cos + localX2Sin; - offset[6/*X4*/] = localX2Cos - localYSin; - offset[7/*Y4*/] = localYCos + localX2Sin; - }, - computeVertices: function (x, y, bone, vertices) { - - x += bone.worldX; - y += bone.worldY; - var m00 = bone.m00; - var m01 = bone.m01; - var m10 = bone.m10; - var m11 = bone.m11; - var offset = this.offset; - vertices[0/*X1*/] = offset[0/*X1*/] * m00 + offset[1/*Y1*/] * m01 + x; - vertices[1/*Y1*/] = offset[0/*X1*/] * m10 + offset[1/*Y1*/] * m11 + y; - vertices[2/*X2*/] = offset[2/*X2*/] * m00 + offset[3/*Y2*/] * m01 + x; - vertices[3/*Y2*/] = offset[2/*X2*/] * m10 + offset[3/*Y2*/] * m11 + y; - vertices[4/*X3*/] = offset[4/*X3*/] * m00 + offset[5/*X3*/] * m01 + x; - vertices[5/*X3*/] = offset[4/*X3*/] * m10 + offset[5/*X3*/] * m11 + y; - vertices[6/*X4*/] = offset[6/*X4*/] * m00 + offset[7/*Y4*/] * m01 + x; - vertices[7/*Y4*/] = offset[6/*X4*/] * m10 + offset[7/*Y4*/] * m11 + y; - } -} - -spine.AnimationStateData = function (skeletonData) { - this.skeletonData = skeletonData; - this.animationToMixTime = {}; -}; -spine.AnimationStateData.prototype = { - setMixByName: function (fromName, toName, duration) { - var from = this.skeletonData.findAnimation(fromName); - if (!from) throw "Animation not found: " + fromName; - var to = this.skeletonData.findAnimation(toName); - if (!to) throw "Animation not found: " + toName; - this.setMix(from, to, duration); - }, - setMix: function (from, to, duration) { - this.animationToMixTime[from.name + ":" + to.name] = duration; - }, - getMix: function (from, to) { - var time = this.animationToMixTime[from.name + ":" + to.name]; - return time ? time : 0; - } -}; - -spine.AnimationState = function (stateData) { - this.data = stateData; - this.queue = []; -}; -spine.AnimationState.prototype = { - current: null, - previous: null, - currentTime: 0, - previousTime: 0, - currentLoop: false, - previousLoop: false, - mixTime: 0, - mixDuration: 0, - update: function (delta) { - this.currentTime += delta; - this.previousTime += delta; - this.mixTime += delta; - - if (this.queue.length > 0) { - var entry = this.queue[0]; - if (this.currentTime >= entry.delay) { - this._setAnimation(entry.animation, entry.loop); - this.queue.shift(); - } - } - }, - apply: function (skeleton) { - if (!this.current) return; - if (this.previous) { - this.previous.apply(skeleton, this.previousTime, this.previousLoop); - var alpha = this.mixTime / this.mixDuration; - if (alpha >= 1) { - alpha = 1; - this.previous = null; - } - this.current.mix(skeleton, this.currentTime, this.currentLoop, alpha); - } else - this.current.apply(skeleton, this.currentTime, this.currentLoop); - }, - clearAnimation: function () { - this.previous = null; - this.current = null; - this.queue.length = 0; - }, - _setAnimation: function (animation, loop) { - this.previous = null; - if (animation && this.current) { - this.mixDuration = this.data.getMix(this.current, animation); - if (this.mixDuration > 0) { - this.mixTime = 0; - this.previous = this.current; - this.previousTime = this.currentTime; - this.previousLoop = this.currentLoop; - } - } - this.current = animation; - this.currentLoop = loop; - this.currentTime = 0; - }, - /** @see #setAnimation(Animation, Boolean) */ - setAnimationByName: function (animationName, loop) { - var animation = this.data.skeletonData.findAnimation(animationName); - if (!animation) throw "Animation not found: " + animationName; - this.setAnimation(animation, loop); - }, - /** Set the current animation. Any queued animations are cleared and the current animation time is set to 0. - * @param animation May be null. */ - setAnimation: function (animation, loop) { - this.queue.length = 0; - this._setAnimation(animation, loop); - }, - /** @see #addAnimation(Animation, Boolean, Number) */ - addAnimationByName: function (animationName, loop, delay) { - var animation = this.data.skeletonData.findAnimation(animationName); - if (!animation) throw "Animation not found: " + animationName; - this.addAnimation(animation, loop, delay); - }, - /** Adds an animation to be played delay seconds after the current or last queued animation. - * @param delay May be <= 0 to use duration of previous animation minus any mix duration plus the negative delay. */ - addAnimation: function (animation, loop, delay) { - var entry = {}; - entry.animation = animation; - entry.loop = loop; - - if (!delay || delay <= 0) { - var previousAnimation = this.queue.length == 0 ? this.current : this.queue[this.queue.length - 1].animation; - if (previousAnimation != null) - delay = previousAnimation.duration - this.data.getMix(previousAnimation, animation) + (delay || 0); - else - delay = 0; - } - entry.delay = delay; - - this.queue.push(entry); - }, - /** Returns true if no animation is set or if the current time is greater than the animation duration, regardless of looping. */ - isComplete: function () { - return !this.current || this.currentTime >= this.current.duration; - } -}; - -spine.SkeletonJson = function (attachmentLoader) { - this.attachmentLoader = attachmentLoader; -}; -spine.SkeletonJson.prototype = { - scale: 1, - readSkeletonData: function (root) { - var skeletonData = new spine.SkeletonData(); - - // Bones. - var bones = root["bones"]; - for (var i = 0, n = bones.length; i < n; i++) { - var boneMap = bones[i]; - var parent = null; - if (boneMap["parent"]) { - parent = skeletonData.findBone(boneMap["parent"]); - if (!parent) throw "Parent bone not found: " + boneMap["parent"]; - } - var boneData = new spine.BoneData(boneMap["name"], parent); - boneData.length = (boneMap["length"] || 0) * this.scale; - boneData.x = (boneMap["x"] || 0) * this.scale; - boneData.y = (boneMap["y"] || 0) * this.scale; - boneData.rotation = (boneMap["rotation"] || 0); - boneData.scaleX = boneMap["scaleX"] || 1; - boneData.scaleY = boneMap["scaleY"] || 1; - skeletonData.bones.push(boneData); - } - - // Slots. - var slots = root["slots"]; - for (var i = 0, n = slots.length; i < n; i++) { - var slotMap = slots[i]; - var boneData = skeletonData.findBone(slotMap["bone"]); - if (!boneData) throw "Slot bone not found: " + slotMap["bone"]; - var slotData = new spine.SlotData(slotMap["name"], boneData); - - var color = slotMap["color"]; - if (color) { - slotData.r = spine.SkeletonJson.toColor(color, 0); - slotData.g = spine.SkeletonJson.toColor(color, 1); - slotData.b = spine.SkeletonJson.toColor(color, 2); - slotData.a = spine.SkeletonJson.toColor(color, 3); - } - - slotData.attachmentName = slotMap["attachment"]; - - skeletonData.slots.push(slotData); - } - - // Skins. - var skins = root["skins"]; - for (var skinName in skins) { - if (!skins.hasOwnProperty(skinName)) continue; - var skinMap = skins[skinName]; - var skin = new spine.Skin(skinName); - for (var slotName in skinMap) { - if (!skinMap.hasOwnProperty(slotName)) continue; - var slotIndex = skeletonData.findSlotIndex(slotName); - var slotEntry = skinMap[slotName]; - for (var attachmentName in slotEntry) { - if (!slotEntry.hasOwnProperty(attachmentName)) continue; - var attachment = this.readAttachment(skin, attachmentName, slotEntry[attachmentName]); - if (attachment != null) skin.addAttachment(slotIndex, attachmentName, attachment); - } - } - skeletonData.skins.push(skin); - if (skin.name == "default") skeletonData.defaultSkin = skin; - } - - // Animations. - var animations = root["animations"]; - for (var animationName in animations) { - if (!animations.hasOwnProperty(animationName)) continue; - this.readAnimation(animationName, animations[animationName], skeletonData); - } - - return skeletonData; - }, - readAttachment: function (skin, name, map) { - name = map["name"] || name; - - var type = spine.AttachmentType[map["type"] || "region"]; - - // @ekelokorpi - // var attachment = this.attachmentLoader.newAttachment(skin, type, name); - var attachment = new spine.RegionAttachment(); - - // @Doormat23 - // add the name of the attachment - attachment.name = name; - - if (type == spine.AttachmentType.region) { - attachment.x = (map["x"] || 0) * this.scale; - attachment.y = (map["y"] || 0) * this.scale; - attachment.scaleX = map["scaleX"] || 1; - attachment.scaleY = map["scaleY"] || 1; - attachment.rotation = map["rotation"] || 0; - attachment.width = (map["width"] || 32) * this.scale; - attachment.height = (map["height"] || 32) * this.scale; - attachment.updateOffset(); - } - - return attachment; - }, - readAnimation: function (name, map, skeletonData) { - var timelines = []; - var duration = 0; - - var bones = map["bones"]; - for (var boneName in bones) { - if (!bones.hasOwnProperty(boneName)) continue; - var boneIndex = skeletonData.findBoneIndex(boneName); - if (boneIndex == -1) throw "Bone not found: " + boneName; - var boneMap = bones[boneName]; - - for (var timelineName in boneMap) { - if (!boneMap.hasOwnProperty(timelineName)) continue; - var values = boneMap[timelineName]; - if (timelineName == "rotate") { - var timeline = new spine.RotateTimeline(values.length); - timeline.boneIndex = boneIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - timeline.setFrame(frameIndex, valueMap["time"], valueMap["angle"]); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 2 - 2]); - - } else if (timelineName == "translate" || timelineName == "scale") { - var timeline; - var timelineScale = 1; - if (timelineName == "scale") - timeline = new spine.ScaleTimeline(values.length); - else { - timeline = new spine.TranslateTimeline(values.length); - timelineScale = this.scale; - } - timeline.boneIndex = boneIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - var x = (valueMap["x"] || 0) * timelineScale; - var y = (valueMap["y"] || 0) * timelineScale; - timeline.setFrame(frameIndex, valueMap["time"], x, y); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 3 - 3]); - - } else - throw "Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")"; - } - } - var slots = map["slots"]; - for (var slotName in slots) { - if (!slots.hasOwnProperty(slotName)) continue; - var slotMap = slots[slotName]; - var slotIndex = skeletonData.findSlotIndex(slotName); - - for (var timelineName in slotMap) { - if (!slotMap.hasOwnProperty(timelineName)) continue; - var values = slotMap[timelineName]; - if (timelineName == "color") { - var timeline = new spine.ColorTimeline(values.length); - timeline.slotIndex = slotIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - var color = valueMap["color"]; - var r = spine.SkeletonJson.toColor(color, 0); - var g = spine.SkeletonJson.toColor(color, 1); - var b = spine.SkeletonJson.toColor(color, 2); - var a = spine.SkeletonJson.toColor(color, 3); - timeline.setFrame(frameIndex, valueMap["time"], r, g, b, a); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 5 - 5]); - - } else if (timelineName == "attachment") { - var timeline = new spine.AttachmentTimeline(values.length); - timeline.slotIndex = slotIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - timeline.setFrame(frameIndex++, valueMap["time"], valueMap["name"]); - } - timelines.push(timeline); - // PIXI FIX - duration = Math.max(duration, timeline.frames[Math.floor(timeline.getFrameCount()) - 1]); - } else - throw "Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")"; - } - } - skeletonData.animations.push(new spine.Animation(name, timelines, duration)); - } -}; -spine.SkeletonJson.readCurve = function (timeline, frameIndex, valueMap) { - var curve = valueMap["curve"]; - if (!curve) return; - if (curve == "stepped") - timeline.curves.setStepped(frameIndex); - else if (curve instanceof Array) - timeline.curves.setCurve(frameIndex, curve[0], curve[1], curve[2], curve[3]); -}; -spine.SkeletonJson.toColor = function (hexString, colorIndex) { - if (hexString.length != 8) throw "Color hexidecimal length must be 8, recieved: " + hexString; - return parseInt(hexString.substring(colorIndex * 2, 2), 16) / 255; -}; - -spine.Atlas = function (atlasText, textureLoader) { - this.textureLoader = textureLoader; - this.pages = []; - this.regions = []; - - var reader = new spine.AtlasReader(atlasText); - var tuple = []; - tuple.length = 4; - var page = null; - while (true) { - var line = reader.readLine(); - if (line == null) break; - line = reader.trim(line); - if (line.length == 0) - page = null; - else if (!page) { - page = new spine.AtlasPage(); - page.name = line; - - page.format = spine.Atlas.Format[reader.readValue()]; - - reader.readTuple(tuple); - page.minFilter = spine.Atlas.TextureFilter[tuple[0]]; - page.magFilter = spine.Atlas.TextureFilter[tuple[1]]; - - var direction = reader.readValue(); - page.uWrap = spine.Atlas.TextureWrap.clampToEdge; - page.vWrap = spine.Atlas.TextureWrap.clampToEdge; - if (direction == "x") - page.uWrap = spine.Atlas.TextureWrap.repeat; - else if (direction == "y") - page.vWrap = spine.Atlas.TextureWrap.repeat; - else if (direction == "xy") - page.uWrap = page.vWrap = spine.Atlas.TextureWrap.repeat; - - textureLoader.load(page, line); - - this.pages.push(page); - - } else { - var region = new spine.AtlasRegion(); - region.name = line; - region.page = page; - - region.rotate = reader.readValue() == "true"; - - reader.readTuple(tuple); - var x = parseInt(tuple[0]); - var y = parseInt(tuple[1]); - - reader.readTuple(tuple); - var width = parseInt(tuple[0]); - var height = parseInt(tuple[1]); - - region.u = x / page.width; - region.v = y / page.height; - if (region.rotate) { - region.u2 = (x + height) / page.width; - region.v2 = (y + width) / page.height; - } else { - region.u2 = (x + width) / page.width; - region.v2 = (y + height) / page.height; - } - region.x = x; - region.y = y; - region.width = Math.abs(width); - region.height = Math.abs(height); - - if (reader.readTuple(tuple) == 4) { // split is optional - region.splits = [parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])]; - - if (reader.readTuple(tuple) == 4) { // pad is optional, but only present with splits - region.pads = [parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])]; - - reader.readTuple(tuple); - } - } - - region.originalWidth = parseInt(tuple[0]); - region.originalHeight = parseInt(tuple[1]); - - reader.readTuple(tuple); - region.offsetX = parseInt(tuple[0]); - region.offsetY = parseInt(tuple[1]); - - region.index = parseInt(reader.readValue()); - - this.regions.push(region); - } - } -}; -spine.Atlas.prototype = { - findRegion: function (name) { - var regions = this.regions; - for (var i = 0, n = regions.length; i < n; i++) - if (regions[i].name == name) return regions[i]; - return null; - }, - dispose: function () { - var pages = this.pages; - for (var i = 0, n = pages.length; i < n; i++) - this.textureLoader.unload(pages[i].rendererObject); - }, - updateUVs: function (page) { - var regions = this.regions; - for (var i = 0, n = regions.length; i < n; i++) { - var region = regions[i]; - if (region.page != page) continue; - region.u = region.x / page.width; - region.v = region.y / page.height; - if (region.rotate) { - region.u2 = (region.x + region.height) / page.width; - region.v2 = (region.y + region.width) / page.height; - } else { - region.u2 = (region.x + region.width) / page.width; - region.v2 = (region.y + region.height) / page.height; - } - } - } -}; - -spine.Atlas.Format = { - alpha: 0, - intensity: 1, - luminanceAlpha: 2, - rgb565: 3, - rgba4444: 4, - rgb888: 5, - rgba8888: 6 -}; - -spine.Atlas.TextureFilter = { - nearest: 0, - linear: 1, - mipMap: 2, - mipMapNearestNearest: 3, - mipMapLinearNearest: 4, - mipMapNearestLinear: 5, - mipMapLinearLinear: 6 -}; - -spine.Atlas.TextureWrap = { - mirroredRepeat: 0, - clampToEdge: 1, - repeat: 2 -}; - -spine.AtlasPage = function () {}; -spine.AtlasPage.prototype = { - name: null, - format: null, - minFilter: null, - magFilter: null, - uWrap: null, - vWrap: null, - rendererObject: null, - width: 0, - height: 0 -}; - -spine.AtlasRegion = function () {}; -spine.AtlasRegion.prototype = { - page: null, - name: null, - x: 0, y: 0, - width: 0, height: 0, - u: 0, v: 0, u2: 0, v2: 0, - offsetX: 0, offsetY: 0, - originalWidth: 0, originalHeight: 0, - index: 0, - rotate: false, - splits: null, - pads: null, -}; - -spine.AtlasReader = function (text) { - this.lines = text.split(/\r\n|\r|\n/); -}; -spine.AtlasReader.prototype = { - index: 0, - trim: function (value) { - return value.replace(/^\s+|\s+$/g, ""); - }, - readLine: function () { - if (this.index >= this.lines.length) return null; - return this.lines[this.index++]; - }, - readValue: function () { - var line = this.readLine(); - var colon = line.indexOf(":"); - if (colon == -1) throw "Invalid line: " + line; - return this.trim(line.substring(colon + 1)); - }, - /** Returns the number of tuple values read (2 or 4). */ - readTuple: function (tuple) { - var line = this.readLine(); - var colon = line.indexOf(":"); - if (colon == -1) throw "Invalid line: " + line; - var i = 0, lastMatch= colon + 1; - for (; i < 3; i++) { - var comma = line.indexOf(",", lastMatch); - if (comma == -1) { - if (i == 0) throw "Invalid line: " + line; - break; - } - tuple[i] = this.trim(line.substr(lastMatch, comma - lastMatch)); - lastMatch = comma + 1; - } - tuple[i] = this.trim(line.substring(lastMatch)); - return i + 1; - } -} - -spine.AtlasAttachmentLoader = function (atlas) { - this.atlas = atlas; -} -spine.AtlasAttachmentLoader.prototype = { - newAttachment: function (skin, type, name) { - switch (type) { - case spine.AttachmentType.region: - var region = this.atlas.findRegion(name); - if (!region) throw "Region not found in atlas: " + name + " (" + type + ")"; - var attachment = new spine.RegionAttachment(name); - attachment.rendererObject = region; - attachment.setUVs(region.u, region.v, region.u2, region.v2, region.rotate); - attachment.regionOffsetX = region.offsetX; - attachment.regionOffsetY = region.offsetY; - attachment.regionWidth = region.width; - attachment.regionHeight = region.height; - attachment.regionOriginalWidth = region.originalWidth; - attachment.regionOriginalHeight = region.originalHeight; - return attachment; - } - throw "Unknown attachment type: " + type; - } -} - -PIXI.AnimCache = {}; -spine.Bone.yDown = true; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * This object is one that will allow you to specify custom rendering functions based on render type - * - * @class CustomRenderable - * @extends DisplayObject - * @constructor - */ -PIXI.CustomRenderable = function() -{ - PIXI.DisplayObject.call( this ); - -} - -// constructor -PIXI.CustomRenderable.prototype = Object.create( PIXI.DisplayObject.prototype ); -PIXI.CustomRenderable.prototype.constructor = PIXI.CustomRenderable; - -/** - * If this object is being rendered by a CanvasRenderer it will call this callback - * - * @method renderCanvas - * @param renderer {CanvasRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.renderCanvas = function(renderer) -{ - // override! -} - -/** - * If this object is being rendered by a WebGLRenderer it will call this callback to initialize - * - * @method initWebGL - * @param renderer {WebGLRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.initWebGL = function(renderer) -{ - // override! -} - -/** - * If this object is being rendered by a WebGLRenderer it will call this callback - * - * @method renderWebGL - * @param renderer {WebGLRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.renderWebGL = function(renderGroup, projectionMatrix) -{ - // not sure if both needed? but ya have for now! - // override! -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI.BaseTextureCache = {}; -PIXI.texturesToUpdate = []; -PIXI.texturesToDestroy = []; - -/** - * A texture stores the information that represents an image. All textures have a base texture - * - * @class BaseTexture - * @uses EventTarget - * @constructor - * @param source {String} the source object (image or canvas) - */ -PIXI.BaseTexture = function(source) -{ - PIXI.EventTarget.call( this ); - - /** - * [read-only] The width of the base texture set when the image has loaded - * - * @property width - * @type Number - * @readOnly - */ - this.width = 100; - - /** - * [read-only] The height of the base texture set when the image has loaded - * - * @property height - * @type Number - * @readOnly - */ - this.height = 100; - - /** - * [read-only] Describes if the base texture has loaded or not - * - * @property hasLoaded - * @type Boolean - * @readOnly - */ - this.hasLoaded = false; - - /** - * The source that is loaded to create the texture - * - * @property source - * @type Image - */ - this.source = source; - - if(!source)return; - - if(this.source instanceof Image || this.source instanceof HTMLImageElement) - { - if(this.source.complete) - { - this.hasLoaded = true; - this.width = this.source.width; - this.height = this.source.height; - - PIXI.texturesToUpdate.push(this); - } - else - { - - var scope = this; - this.source.onload = function(){ - - scope.hasLoaded = true; - scope.width = scope.source.width; - scope.height = scope.source.height; - - // add it to somewhere... - PIXI.texturesToUpdate.push(scope); - scope.dispatchEvent( { type: 'loaded', content: scope } ); - } - // this.image.src = imageUrl; - } - } - else - { - this.hasLoaded = true; - this.width = this.source.width; - this.height = this.source.height; - - PIXI.texturesToUpdate.push(this); - } - - this._powerOf2 = false; -} - -PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; - -/** - * Destroys this base texture - * - * @method destroy - */ -PIXI.BaseTexture.prototype.destroy = function() -{ - if(this.source instanceof Image) - { - this.source.src = null; - } - this.source = null; - PIXI.texturesToDestroy.push(this); -} - -/** - * Helper function that returns a base texture based on an image url - * If the image is not in the base texture cache it will be created and loaded - * - * @static - * @method fromImage - * @param imageUrl {String} The image url of the texture - * @return BaseTexture - */ -PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin) -{ - var baseTexture = PIXI.BaseTextureCache[imageUrl]; - if(!baseTexture) - { - // new Image() breaks tex loading in some versions of Chrome. - // See https://code.google.com/p/chromium/issues/detail?id=238071 - var image = new Image();//document.createElement('img'); - if (crossorigin) - { - image.crossOrigin = ''; - } - image.src = imageUrl; - baseTexture = new PIXI.BaseTexture(image); - PIXI.BaseTextureCache[imageUrl] = baseTexture; - } - - return baseTexture; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI.TextureCache = {}; -PIXI.FrameCache = {}; - -/** - * A texture stores the information that represents an image or part of an image. It cannot be added - * to the display list directly. To do this use PIXI.Sprite. If no frame is provided then the whole image is used - * - * @class Texture - * @uses EventTarget - * @constructor - * @param baseTexture {BaseTexture} The base texture source to create the texture from - * @param frmae {Rectangle} The rectangle frame of the texture to show - */ -PIXI.Texture = function(baseTexture, frame) -{ - PIXI.EventTarget.call( this ); - - if(!frame) - { - this.noFrame = true; - frame = new PIXI.Rectangle(0,0,1,1); - } - - if(baseTexture instanceof PIXI.Texture) - baseTexture = baseTexture.baseTexture; - - /** - * The base texture of this texture - * - * @property baseTexture - * @type BaseTexture - */ - this.baseTexture = baseTexture; - - /** - * The frame specifies the region of the base texture that this texture uses - * - * @property frame - * @type Rectangle - */ - this.frame = frame; - - /** - * The trim point - * - * @property trim - * @type Point - */ - this.trim = new PIXI.Point(); - - this.scope = this; - - if(baseTexture.hasLoaded) - { - if(this.noFrame)frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); - //console.log(frame) - - this.setFrame(frame); - } - else - { - var scope = this; - baseTexture.addEventListener( 'loaded', function(){ scope.onBaseTextureLoaded()} ); - } -} - -PIXI.Texture.prototype.constructor = PIXI.Texture; - -/** - * Called when the base texture is loaded - * - * @method onBaseTextureLoaded - * @param event - * @private - */ -PIXI.Texture.prototype.onBaseTextureLoaded = function(event) -{ - var baseTexture = this.baseTexture; - baseTexture.removeEventListener( 'loaded', this.onLoaded ); - - if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); - this.noFrame = false; - this.width = this.frame.width; - this.height = this.frame.height; - - this.scope.dispatchEvent( { type: 'update', content: this } ); -} - -/** - * Destroys this texture - * - * @method destroy - * @param destroyBase {Boolean} Whether to destroy the base texture as well - */ -PIXI.Texture.prototype.destroy = function(destroyBase) -{ - if(destroyBase)this.baseTexture.destroy(); -} - -/** - * Specifies the rectangle region of the baseTexture - * - * @method setFrame - * @param frame {Rectangle} The frame of the texture to set it to - */ -PIXI.Texture.prototype.setFrame = function(frame) -{ - this.frame = frame; - this.width = frame.width; - this.height = frame.height; - - if(frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error("Texture Error: frame does not fit inside the base Texture dimensions " + this); - } - - this.updateFrame = true; - - PIXI.Texture.frameUpdates.push(this); - //this.dispatchEvent( { type: 'update', content: this } ); -} - -/** - * Helper function that returns a texture based on an image url - * If the image is not in the texture cache it will be created and loaded - * - * @static - * @method fromImage - * @param imageUrl {String} The image url of the texture - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - * @return Texture - */ -PIXI.Texture.fromImage = function(imageUrl, crossorigin) -{ - var texture = PIXI.TextureCache[imageUrl]; - - if(!texture) - { - texture = new PIXI.Texture(PIXI.BaseTexture.fromImage(imageUrl, crossorigin)); - PIXI.TextureCache[imageUrl] = texture; - } - - return texture; -} - -/** - * Helper function that returns a texture based on a frame id - * If the frame id is not in the texture cache an error will be thrown - * - * @static - * @method fromFrame - * @param frameId {String} The frame id of the texture - * @return Texture - */ -PIXI.Texture.fromFrame = function(frameId) -{ - var texture = PIXI.TextureCache[frameId]; - if(!texture)throw new Error("The frameId '"+ frameId +"' does not exist in the texture cache " + this); - return texture; -} - -/** - * Helper function that returns a texture based on a canvas element - * If the canvas is not in the texture cache it will be created and loaded - * - * @static - * @method fromCanvas - * @param canvas {Canvas} The canvas element source of the texture - * @return Texture - */ -PIXI.Texture.fromCanvas = function(canvas) -{ - var baseTexture = new PIXI.BaseTexture(canvas); - return new PIXI.Texture(baseTexture); -} - - -/** - * Adds a texture to the textureCache. - * - * @static - * @method addTextureToCache - * @param texture {Texture} - * @param id {String} the id that the texture will be stored against. - */ -PIXI.Texture.addTextureToCache = function(texture, id) -{ - PIXI.TextureCache[id] = texture; -} - -/** - * Remove a texture from the textureCache. - * - * @static - * @method removeTextureFromCache - * @param id {String} the id of the texture to be removed - * @return {Texture} the texture that was removed - */ -PIXI.Texture.removeTextureFromCache = function(id) -{ - var texture = PIXI.TextureCache[id] - PIXI.TextureCache[id] = null; - return texture; -} - -// this is more for webGL.. it contains updated frames.. -PIXI.Texture.frameUpdates = []; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - A RenderTexture is a special texture that allows any pixi displayObject to be rendered to it. - - __Hint__: All DisplayObjects (exmpl. Sprites) that renders on RenderTexture should be preloaded. - Otherwise black rectangles will be drawn instead. - - RenderTexture takes snapshot of DisplayObject passed to render method. If DisplayObject is passed to render method, position and rotation of it will be ignored. For example: - - var renderTexture = new PIXI.RenderTexture(800, 600); - var sprite = PIXI.Sprite.fromImage("spinObj_01.png"); - sprite.position.x = 800/2; - sprite.position.y = 600/2; - sprite.anchor.x = 0.5; - sprite.anchor.y = 0.5; - renderTexture.render(sprite); - - Sprite in this case will be rendered to 0,0 position. To render this sprite at center DisplayObjectContainer should be used: - - var doc = new PIXI.DisplayObjectContainer(); - doc.addChild(sprite); - renderTexture.render(doc); // Renders to center of renderTexture - - @class RenderTexture - @extends Texture - @constructor - @param width {Number} The width of the render texture - @param height {Number} The height of the render texture - */ -PIXI.RenderTexture = function(width, height) -{ - PIXI.EventTarget.call( this ); - - this.width = width || 100; - this.height = height || 100; - - this.indetityMatrix = PIXI.mat3.create(); - - this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); - - if(PIXI.gl) - { - this.initWebGL(); - } - else - { - this.initCanvas(); - } -} - -PIXI.RenderTexture.prototype = Object.create( PIXI.Texture.prototype ); -PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture; - -/** - * Initializes the webgl data for this texture - * - * @method initWebGL - * @private - */ -PIXI.RenderTexture.prototype.initWebGL = function() -{ - var gl = PIXI.gl; - this.glFramebuffer = gl.createFramebuffer(); - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - - this.glFramebuffer.width = this.width; - this.glFramebuffer.height = this.height; - - this.baseTexture = new PIXI.BaseTexture(); - - this.baseTexture.width = this.width; - this.baseTexture.height = this.height; - - this.baseTexture._glTexture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); - - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - - this.baseTexture.isRender = true; - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0); - - // create a projection matrix.. - this.projection = new PIXI.Point(this.width/2 , this.height/2); -/* - this.projectionMatrix = PIXI.mat4.create(); - - this.projectionMatrix[5] = 2/this.height// * 0.5; - this.projectionMatrix[13] = -1; - - this.projectionMatrix[0] = 2/this.width; - this.projectionMatrix[12] = -1; -*/ - // set the correct render function.. - this.render = this.renderWebGL; - - -} - - -PIXI.RenderTexture.prototype.resize = function(width, height) -{ - - this.width = width; - this.height = height; - - //this.frame.width = this.width - //this.frame.height = this.height; - - - if(PIXI.gl) - { - this.projection.x = this.width/2 - this.projection.y = this.height/2; - - var gl = PIXI.gl; - gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - } - else - { - - this.frame.width = this.width - this.frame.height = this.height; - this.renderer.resize(this.width, this.height); - } -} - -/** - * Initializes the canvas data for this texture - * - * @method initCanvas - * @private - */ -PIXI.RenderTexture.prototype.initCanvas = function() -{ - this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, 0); - - this.baseTexture = new PIXI.BaseTexture(this.renderer.view); - this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); - - this.render = this.renderCanvas; -} - -/** - * This function will draw the display object to the texture. - * - * @method renderWebGL - * @param displayObject {DisplayObject} The display object to render this texture on - * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn - * @private - */ -PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear) -{ - var gl = PIXI.gl; - - // enable the alpha color mask.. - gl.colorMask(true, true, true, true); - - gl.viewport(0, 0, this.width, this.height); - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - - if(clear) - { - gl.clearColor(0,0,0, 0); - gl.clear(gl.COLOR_BUFFER_BIT); - } - - // THIS WILL MESS WITH HIT TESTING! - var children = displayObject.children; - - //TODO -? create a new one??? dont think so! - displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix; - // modify to flip... - displayObject.worldTransform[4] = -1; - displayObject.worldTransform[5] = this.projection.y * 2; - - - if(position) - { - displayObject.worldTransform[2] = position.x; - displayObject.worldTransform[5] -= position.y; - } - - - - for(var i=0,j=children.length; i} assetURLs an array of image/sprite sheet urls that you would like loaded - * supported. Supported image formats include "jpeg", "jpg", "png", "gif". Supported - * sprite sheet data formats only include "JSON" at this time. Supported bitmap font - * data formats include "xml" and "fnt". - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.AssetLoader = function(assetURLs, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The array of asset URLs that are going to be loaded - * - * @property assetURLs - * @type Array - */ - this.assetURLs = assetURLs; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * Maps file extension to loader types - * - * @property loadersByType - * @type Object - */ - this.loadersByType = { - "jpg": PIXI.ImageLoader, - "jpeg": PIXI.ImageLoader, - "png": PIXI.ImageLoader, - "gif": PIXI.ImageLoader, - "json": PIXI.JsonLoader, - "anim": PIXI.SpineLoader, - "xml": PIXI.BitmapFontLoader, - "fnt": PIXI.BitmapFontLoader - }; - - -}; - -/** - * Fired when an item has loaded - * @event onProgress - */ - -/** - * Fired when all the assets have loaded - * @event onComplete - */ - -// constructor -PIXI.AssetLoader.prototype.constructor = PIXI.AssetLoader; - -/** - * Starts loading the assets sequentially - * - * @method load - */ -PIXI.AssetLoader.prototype.load = function() -{ - var scope = this; - - this.loadCount = this.assetURLs.length; - - for (var i=0; i < this.assetURLs.length; i++) - { - var fileName = this.assetURLs[i]; - var fileType = fileName.split(".").pop().toLowerCase(); - - var loaderClass = this.loadersByType[fileType]; - if(!loaderClass) - throw new Error(fileType + " is an unsupported file type"); - - var loader = new loaderClass(fileName, this.crossorigin); - - loader.addEventListener("loaded", function() - { - scope.onAssetLoaded(); - }); - loader.load(); - } -}; - -/** - * Invoked after each file is loaded - * - * @method onAssetLoaded - * @private - */ -PIXI.AssetLoader.prototype.onAssetLoaded = function() -{ - this.loadCount--; - this.dispatchEvent({type: "onProgress", content: this}); - if(this.onProgress) this.onProgress(); - - if(this.loadCount == 0) - { - this.dispatchEvent({type: "onComplete", content: this}); - if(this.onComplete) this.onComplete(); - } -}; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The json file loader is used to load in JSON data and parsing it - * When loaded this class will dispatch a "loaded" event - * If load failed this class will dispatch a "error" event - * - * @class JsonLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.JsonLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * [read-only] Whether the data has loaded yet - * - * @property loaded - * @type Boolean - * @readOnly - */ - this.loaded = false; - -}; - -// constructor -PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader; - -/** - * Loads the JSON data - * - * @method load - */ -PIXI.JsonLoader.prototype.load = function () { - this.ajaxRequest = new AjaxRequest(); - var scope = this; - this.ajaxRequest.onreadystatechange = function () { - scope.onJSONLoaded(); - }; - - this.ajaxRequest.open("GET", this.url, true); - if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json"); - this.ajaxRequest.send(null); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.JsonLoader.prototype.onJSONLoaded = function () { - if (this.ajaxRequest.readyState == 4) { - if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) { - this.json = JSON.parse(this.ajaxRequest.responseText); - - if(this.json.frames) - { - // sprite sheet - var scope = this; - var textureUrl = this.baseUrl + this.json.meta.image; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - var frameData = this.json.frames; - - this.texture = image.texture.baseTexture; - image.addEventListener("loaded", function (event) { - scope.onLoaded(); - }); - - for (var i in frameData) { - var rect = frameData[i].frame; - if (rect) { - PIXI.TextureCache[i] = new PIXI.Texture(this.texture, { - x: rect.x, - y: rect.y, - width: rect.w, - height: rect.h - }); - if (frameData[i].trimmed) { - //var realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w) - // calculate the offset! - } - } - } - - image.load(); - - } - else if(this.json.bones) - { - // spine animation - var spineJsonParser = new spine.SkeletonJson(); - var skeletonData = spineJsonParser.readSkeletonData(this.json); - PIXI.AnimCache[this.url] = skeletonData; - this.onLoaded(); - } - else - { - this.onLoaded(); - } - } - else - { - this.onError(); - } - } -}; - -/** - * Invoke when json file loaded - * - * @method onLoaded - * @private - */ -PIXI.JsonLoader.prototype.onLoaded = function () { - this.loaded = true; - this.dispatchEvent({ - type: "loaded", - content: this - }); -}; - -/** - * Invoke when error occured - * - * @method onError - * @private - */ -PIXI.JsonLoader.prototype.onError = function () { - this.dispatchEvent({ - type: "error", - content: this - }); -}; -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The sprite sheet loader is used to load in JSON sprite sheet data - * To generate the data you can use http://www.codeandweb.com/texturepacker and publish the "JSON" format - * There is a free version so thats nice, although the paid version is great value for money. - * It is highly recommended to use Sprite sheets (also know as texture atlas") as it means sprite"s can be batched and drawn together for highly increased rendering speed. - * Once the data has been loaded the frames are stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId() - * This loader will also load the image file that the Spritesheet points to as well as the data. - * When loaded this class will dispatch a "loaded" event - * - * @class SpriteSheetLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the sprite sheet JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ - -PIXI.SpriteSheetLoader = function (url, crossorigin) { - /* - * i use texture packer to load the assets.. - * http://www.codeandweb.com/texturepacker - * make sure to set the format as "JSON" - */ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * The texture being loaded - * - * @property texture - * @type Texture - */ - this.texture = null; - - /** - * The frames of the sprite sheet - * - * @property frames - * @type Object - */ - this.frames = {}; -}; - -// constructor -PIXI.SpriteSheetLoader.prototype.constructor = PIXI.SpriteSheetLoader; - -/** - * This will begin loading the JSON file - * - * @method load - */ -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; - scope.onJSONLoaded(); - }); - jsonLoader.load(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () { - var scope = this; - var textureUrl = this.baseUrl + this.json.meta.image; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - var frameData = this.json.frames; - - this.texture = image.texture.baseTexture; - image.addEventListener("loaded", function (event) { - scope.onLoaded(); - }); - - for (var i in frameData) { - var rect = frameData[i].frame; - if (rect) { - PIXI.TextureCache[i] = new PIXI.Texture(this.texture, { - x: rect.x, - y: rect.y, - width: rect.w, - height: rect.h - }); - if (frameData[i].trimmed) { - //var realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w) - // calculate the offset! - } - } - } - - image.load(); -}; -/** - * Invoke when all files are loaded (json and texture) - * - * @method onLoaded - * @private - */ -PIXI.SpriteSheetLoader.prototype.onLoaded = function () { - this.dispatchEvent({ - type: "loaded", - content: this - }); -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The image loader class is responsible for loading images file formats ("jpeg", "jpg", "png" and "gif") - * Once the image has been loaded it is stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId() - * When loaded this class will dispatch a 'loaded' event - * - * @class ImageLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the image - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.ImageLoader = function(url, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The texture being loaded - * - * @property texture - * @type Texture - */ - this.texture = PIXI.Texture.fromImage(url, crossorigin); -}; - -// constructor -PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader; - -/** - * Loads image or takes it from cache - * - * @method load - */ -PIXI.ImageLoader.prototype.load = function() -{ - if(!this.texture.baseTexture.hasLoaded) - { - var scope = this; - this.texture.baseTexture.addEventListener("loaded", function() - { - scope.onLoaded(); - }); - } - else - { - this.onLoaded(); - } -}; - -/** - * Invoked when image file is loaded or it is already cached and ready to use - * - * @method onLoaded - * @private - */ -PIXI.ImageLoader.prototype.onLoaded = function() -{ - this.dispatchEvent({type: "loaded", content: this}); -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The xml loader is used to load in XML bitmap font data ("xml" or "fnt") - * To generate the data you can use http://www.angelcode.com/products/bmfont/ - * This loader will also load the image file as the data. - * When loaded this class will dispatch a "loaded" event - * - * @class BitmapFontLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the sprite sheet JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.BitmapFontLoader = function(url, crossorigin) -{ - /* - * i use texture packer to load the assets.. - * http://www.codeandweb.com/texturepacker - * make sure to set the format as "JSON" - */ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * [read-only] The texture of the bitmap font - * - * @property baseUrl - * @type String - */ - this.texture = null; -}; - -// constructor -PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; - -/** - * Loads the XML font data - * - * @method load - */ -PIXI.BitmapFontLoader.prototype.load = function() -{ - this.ajaxRequest = new XMLHttpRequest(); - var scope = this; - this.ajaxRequest.onreadystatechange = function() - { - scope.onXMLLoaded(); - }; - - this.ajaxRequest.open("GET", this.url, true); - if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/xml"); - this.ajaxRequest.send(null) -}; - -/** - * Invoked when XML file is loaded, parses the data - * - * @method onXMLLoaded - * @private - */ -PIXI.BitmapFontLoader.prototype.onXMLLoaded = function() -{ - if (this.ajaxRequest.readyState == 4) - { - if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) - { - var textureUrl = this.baseUrl + this.ajaxRequest.responseXML.getElementsByTagName("page")[0].attributes.getNamedItem("file").nodeValue; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - this.texture = image.texture.baseTexture; - - var data = {}; - var info = this.ajaxRequest.responseXML.getElementsByTagName("info")[0]; - var common = this.ajaxRequest.responseXML.getElementsByTagName("common")[0]; - data.font = info.attributes.getNamedItem("face").nodeValue; - data.size = parseInt(info.attributes.getNamedItem("size").nodeValue, 10); - data.lineHeight = parseInt(common.attributes.getNamedItem("lineHeight").nodeValue, 10); - data.chars = {}; - - //parse letters - var letters = this.ajaxRequest.responseXML.getElementsByTagName("char"); - - for (var i = 0; i < letters.length; i++) - { - var charCode = parseInt(letters[i].attributes.getNamedItem("id").nodeValue, 10); - - var textureRect = { - x: parseInt(letters[i].attributes.getNamedItem("x").nodeValue, 10), - y: parseInt(letters[i].attributes.getNamedItem("y").nodeValue, 10), - width: parseInt(letters[i].attributes.getNamedItem("width").nodeValue, 10), - height: parseInt(letters[i].attributes.getNamedItem("height").nodeValue, 10) - }; - PIXI.TextureCache[charCode] = new PIXI.Texture(this.texture, textureRect); - - data.chars[charCode] = { - xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), - yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), - xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), - kerning: {}, - texture:new PIXI.Texture(this.texture, textureRect) - - }; - } - - //parse kernings - var kernings = this.ajaxRequest.responseXML.getElementsByTagName("kerning"); - for (i = 0; i < kernings.length; i++) - { - var first = parseInt(kernings[i].attributes.getNamedItem("first").nodeValue, 10); - var second = parseInt(kernings[i].attributes.getNamedItem("second").nodeValue, 10); - var amount = parseInt(kernings[i].attributes.getNamedItem("amount").nodeValue, 10); - - data.chars[second].kerning[first] = amount; - - } - - PIXI.BitmapText.fonts[data.font] = data; - - var scope = this; - image.addEventListener("loaded", function() { - scope.onLoaded(); - }); - image.load(); - } - } -}; - -/** - * Invoked when all files are loaded (xml/fnt and texture) - * - * @method onLoaded - * @private - */ -PIXI.BitmapFontLoader.prototype.onLoaded = function() -{ - this.dispatchEvent({type: "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 - * - * Awesome JS run time provided by EsotericSoftware - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -/** - * The Spine loader is used to load in JSON spine data - * To generate the data you need to use http://esotericsoftware.com/ and export the "JSON" format - * Due to a clash of names You will need to change the extension of the spine file from *.json to *.anim for it to load - * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source - * You will need to generate a sprite sheet to accompany the spine data - * When loaded this class will dispatch a "loaded" event - * - * @class Spine - * @uses EventTarget - * @constructor - * @param url {String} The url of the JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.SpineLoader = function(url, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] Whether the data has loaded yet - * - * @property loaded - * @type Boolean - * @readOnly - */ - this.loaded = false; -} - -PIXI.SpineLoader.prototype.constructor = PIXI.SpineLoader; - -/** - * Loads the JSON data - * - * @method load - */ -PIXI.SpineLoader.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; - scope.onJSONLoaded(); - }); - jsonLoader.load(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.SpineLoader.prototype.onJSONLoaded = function (event) { - var spineJsonParser = new spine.SkeletonJson(); - var skeletonData = spineJsonParser.readSkeletonData(this.json); - - PIXI.AnimCache[this.url] = skeletonData; - - this.onLoaded(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onLoaded - * @private - */ -PIXI.SpineLoader.prototype.onLoaded = function () { - this.loaded = true; - this.dispatchEvent({type: "loaded", content: this}); -}; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - if (typeof exports !== 'undefined') { - if (typeof module !== 'undefined' && module.exports) { - exports = module.exports = PIXI; - } - exports.PIXI = PIXI; - } else { - root.PIXI = PIXI; - } - - -}).call(this); \ No newline at end of file diff --git a/examples/example 6 - Interactivity/index.html b/examples/example 6 - Interactivity/index.html index d6ef03f..acdd8a9 100644 --- a/examples/example 6 - Interactivity/index.html +++ b/examples/example 6 - Interactivity/index.html @@ -8,7 +8,7 @@ padding: 0; background-color: #000000; } - + #help{ position: absolute; z-index: 20; @@ -19,71 +19,71 @@ - - + + diff --git a/examples/example 6 - Interactivity/pixi.js b/examples/example 6 - Interactivity/pixi.js deleted file mode 100644 index a6e7055..0000000 --- a/examples/example 6 - Interactivity/pixi.js +++ /dev/null @@ -1,10438 +0,0 @@ -/** - * @license - * Pixi.JS - v1.3.0 - * Copyright (c) 2012, Mat Groves - * http://goodboydigital.com/ - * - * Compiled: 2013-07-24 - * - * Pixi.JS is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license.php - */ -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -(function(){ - - var root = this; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * @module PIXI - */ -var PIXI = PIXI || {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis. - * - * @class Point - * @constructor - * @param x {Number} position of the point - * @param y {Number} position of the point - */ -PIXI.Point = function(x, y) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; -} - -/** - * Creates a clone of this point - * - * @method clone - * @return {Point} a copy of the point - */ -PIXI.Point.prototype.clone = function() -{ - return new PIXI.Point(this.x, this.y); -} - -// constructor -PIXI.Point.prototype.constructor = PIXI.Point; - - -/** - * @author Mat Groves http://matgroves.com/ - */ - -/** - * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. - * - * @class Rectangle - * @constructor - * @param x {Number} The X coord of the upper-left corner of the rectangle - * @param y {Number} The Y coord of the upper-left corner of the rectangle - * @param width {Number} The overall wisth of this rectangle - * @param height {Number} The overall height of this rectangle - */ -PIXI.Rectangle = function(x, y, width, height) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property width - * @type Number - * @default 0 - */ - this.width = width || 0; - - /** - * @property height - * @type Number - * @default 0 - */ - this.height = height || 0; -} - -/** - * Creates a clone of this Rectangle - * - * @method clone - * @return {Rectangle} a copy of the rectangle - */ -PIXI.Rectangle.prototype.clone = function() -{ - return new PIXI.Rectangle(this.x, this.y, this.width, this.height); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this Rectangle - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this Rectangle - */ -PIXI.Rectangle.prototype.contains = function(x, y) -{ - if(this.width <= 0 || this.height <= 0) - return false; - - var x1 = this.x; - if(x > x1 && x < x1 + this.width) - { - var y1 = this.y; - - if(y > y1 && y < y1 + this.height) - { - return true; - } - } - - return false; -} - -// constructor -PIXI.Rectangle.prototype.constructor = PIXI.Rectangle; - - -/** - * @author Adrien Brault - */ - -/** - * @class Polygon - * @constructor - * @param points* {Array|Array|Point...|Number...} This can be an array of Points that form the polygon, - * a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arugments passed can be - * all the points of the polygon e.g. `new PIXI.Polygon(new PIXI.Point(), new PIXI.Point(), ...)`, or the - * arguments passed can be flat x,y values e.g. `new PIXI.Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are - * Numbers. - */ -PIXI.Polygon = function(points) -{ - //if points isn't an array, use arguments as the array - if(!(points instanceof Array)) - points = Array.prototype.slice.call(arguments); - - //if this is a flat array of numbers, convert it to points - if(typeof points[0] === 'number') { - var p = []; - for(var i = 0, il = points.length; i < il; i+=2) { - p.push( - new PIXI.Point(points[i], points[i + 1]) - ); - } - - points = p; - } - - this.points = points; -} - -/** - * Creates a clone of this polygon - * - * @method clone - * @return {Polygon} a copy of the polygon - */ -PIXI.Polygon.prototype.clone = function() -{ - var points = []; - for (var i=0; i y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi); - - if(intersect) inside = !inside; - } - - return inside; -} - -PIXI.Polygon.prototype.constructor = PIXI.Polygon; - - -/** - * @author Chad Engler - */ - -/** - * The Circle object can be used to specify a hit area for displayobjects - * - * @class Circle - * @constructor - * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this circle - * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this circle - * @param radius {Number} The radius of the circle - */ -PIXI.Circle = function(x, y, radius) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property radius - * @type Number - * @default 0 - */ - this.radius = radius || 0; -} - -/** - * Creates a clone of this Circle instance - * - * @method clone - * @return {Circle} a copy of the polygon - */ -PIXI.Circle.prototype.clone = function() -{ - return new PIXI.Circle(this.x, this.y, this.radius); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this circle - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this polygon - */ -PIXI.Circle.prototype.contains = function(x, y) -{ - if(this.radius <= 0) - return false; - - var dx = (this.x - x), - dy = (this.y - y), - r2 = this.radius * this.radius; - - dx *= dx; - dy *= dy; - - return (dx + dy <= r2); -} - -PIXI.Circle.prototype.constructor = PIXI.Circle; - - -/** - * @author Chad Engler - */ - -/** - * The Ellipse object can be used to specify a hit area for displayobjects - * - * @class Ellipse - * @constructor - * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this ellipse - * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this ellipse - * @param width {Number} The overall height of this ellipse - * @param height {Number} The overall width of this ellipse - */ -PIXI.Ellipse = function(x, y, width, height) -{ - /** - * @property x - * @type Number - * @default 0 - */ - this.x = x || 0; - - /** - * @property y - * @type Number - * @default 0 - */ - this.y = y || 0; - - /** - * @property width - * @type Number - * @default 0 - */ - this.width = width || 0; - - /** - * @property height - * @type Number - * @default 0 - */ - this.height = height || 0; -} - -/** - * Creates a clone of this Ellipse instance - * - * @method clone - * @return {Ellipse} a copy of the ellipse - */ -PIXI.Ellipse.prototype.clone = function() -{ - return new PIXI.Ellipse(this.x, this.y, this.width, this.height); -} - -/** - * Checks if the x, and y coords passed to this function are contained within this ellipse - * - * @method contains - * @param x {Number} The X coord of the point to test - * @param y {Number} The Y coord of the point to test - * @return {Boolean} if the x/y coords are within this ellipse - */ -PIXI.Ellipse.prototype.contains = function(x, y) -{ - if(this.width <= 0 || this.height <= 0) - return false; - - //normalize the coords to an ellipse with center 0,0 - //and a radius of 0.5 - var normx = ((x - this.x) / this.width) - 0.5, - normy = ((y - this.y) / this.height) - 0.5; - - normx *= normx; - normy *= normy; - - return (normx + normy < 0.25); -} - -PIXI.Ellipse.getBounds = function() -{ - return new PIXI.Rectangle(this.x, this.y, this.width, this.height); -} - -PIXI.Ellipse.prototype.constructor = PIXI.Ellipse; - - - - -/* - * A lighter version of the rad gl-matrix created by Brandon Jones, Colin MacKenzie IV - * you both rock! - */ - -function determineMatrixArrayType() { - PIXI.Matrix = (typeof Float32Array !== 'undefined') ? Float32Array : Array; - return PIXI.Matrix; -} - -determineMatrixArrayType(); - -PIXI.mat3 = {}; - -PIXI.mat3.create = function() -{ - var matrix = new PIXI.Matrix(9); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 1; - matrix[5] = 0; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 1; - - return matrix; -} - - -PIXI.mat3.identity = function(matrix) -{ - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 1; - matrix[5] = 0; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 1; - - return matrix; -} - - -PIXI.mat4 = {}; - -PIXI.mat4.create = function() -{ - var matrix = new PIXI.Matrix(16); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 0; - matrix[5] = 1; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 0; - matrix[9] = 0; - matrix[10] = 1; - matrix[11] = 0; - matrix[12] = 0; - matrix[13] = 0; - matrix[14] = 0; - matrix[15] = 1; - - return matrix; -} - -PIXI.mat3.multiply = function (mat, mat2, dest) -{ - if (!dest) { dest = mat; } - - // Cache the matrix values (makes for huge speed increases!) - var a00 = mat[0], a01 = mat[1], a02 = mat[2], - a10 = mat[3], a11 = mat[4], a12 = mat[5], - a20 = mat[6], a21 = mat[7], a22 = mat[8], - - b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], - b10 = mat2[3], b11 = mat2[4], b12 = mat2[5], - b20 = mat2[6], b21 = mat2[7], b22 = mat2[8]; - - dest[0] = b00 * a00 + b01 * a10 + b02 * a20; - dest[1] = b00 * a01 + b01 * a11 + b02 * a21; - dest[2] = b00 * a02 + b01 * a12 + b02 * a22; - - dest[3] = b10 * a00 + b11 * a10 + b12 * a20; - dest[4] = b10 * a01 + b11 * a11 + b12 * a21; - dest[5] = b10 * a02 + b11 * a12 + b12 * a22; - - dest[6] = b20 * a00 + b21 * a10 + b22 * a20; - dest[7] = b20 * a01 + b21 * a11 + b22 * a21; - dest[8] = b20 * a02 + b21 * a12 + b22 * a22; - - return dest; -} - -PIXI.mat3.clone = function(mat) -{ - var matrix = new PIXI.Matrix(9); - - matrix[0] = mat[0]; - matrix[1] = mat[1]; - matrix[2] = mat[2]; - matrix[3] = mat[3]; - matrix[4] = mat[4]; - matrix[5] = mat[5]; - matrix[6] = mat[6]; - matrix[7] = mat[7]; - matrix[8] = mat[8]; - - return matrix; -} - -PIXI.mat3.transpose = function (mat, dest) -{ - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (!dest || mat === dest) { - var a01 = mat[1], a02 = mat[2], - a12 = mat[5]; - - mat[1] = mat[3]; - mat[2] = mat[6]; - mat[3] = a01; - mat[5] = mat[7]; - mat[6] = a02; - mat[7] = a12; - return mat; - } - - dest[0] = mat[0]; - dest[1] = mat[3]; - dest[2] = mat[6]; - dest[3] = mat[1]; - dest[4] = mat[4]; - dest[5] = mat[7]; - dest[6] = mat[2]; - dest[7] = mat[5]; - dest[8] = mat[8]; - return dest; -} - -PIXI.mat3.toMat4 = function (mat, dest) -{ - if (!dest) { dest = PIXI.mat4.create(); } - - dest[15] = 1; - dest[14] = 0; - dest[13] = 0; - dest[12] = 0; - - dest[11] = 0; - dest[10] = mat[8]; - dest[9] = mat[7]; - dest[8] = mat[6]; - - dest[7] = 0; - dest[6] = mat[5]; - dest[5] = mat[4]; - dest[4] = mat[3]; - - dest[3] = 0; - dest[2] = mat[2]; - dest[1] = mat[1]; - dest[0] = mat[0]; - - return dest; -} - - -///// - - -PIXI.mat4.create = function() -{ - var matrix = new PIXI.Matrix(16); - - matrix[0] = 1; - matrix[1] = 0; - matrix[2] = 0; - matrix[3] = 0; - matrix[4] = 0; - matrix[5] = 1; - matrix[6] = 0; - matrix[7] = 0; - matrix[8] = 0; - matrix[9] = 0; - matrix[10] = 1; - matrix[11] = 0; - matrix[12] = 0; - matrix[13] = 0; - matrix[14] = 0; - matrix[15] = 1; - - return matrix; -} - -PIXI.mat4.transpose = function (mat, dest) -{ - // If we are transposing ourselves we can skip a few steps but have to cache some values - if (!dest || mat === dest) - { - var a01 = mat[1], a02 = mat[2], a03 = mat[3], - a12 = mat[6], a13 = mat[7], - a23 = mat[11]; - - mat[1] = mat[4]; - mat[2] = mat[8]; - mat[3] = mat[12]; - mat[4] = a01; - mat[6] = mat[9]; - mat[7] = mat[13]; - mat[8] = a02; - mat[9] = a12; - mat[11] = mat[14]; - mat[12] = a03; - mat[13] = a13; - mat[14] = a23; - return mat; - } - - dest[0] = mat[0]; - dest[1] = mat[4]; - dest[2] = mat[8]; - dest[3] = mat[12]; - dest[4] = mat[1]; - dest[5] = mat[5]; - dest[6] = mat[9]; - dest[7] = mat[13]; - dest[8] = mat[2]; - dest[9] = mat[6]; - dest[10] = mat[10]; - dest[11] = mat[14]; - dest[12] = mat[3]; - dest[13] = mat[7]; - dest[14] = mat[11]; - dest[15] = mat[15]; - return dest; -} - -PIXI.mat4.multiply = function (mat, mat2, dest) -{ - if (!dest) { dest = mat; } - - // Cache the matrix values (makes for huge speed increases!) - var a00 = mat[ 0], a01 = mat[ 1], a02 = mat[ 2], a03 = mat[3]; - var a10 = mat[ 4], a11 = mat[ 5], a12 = mat[ 6], a13 = mat[7]; - var a20 = mat[ 8], a21 = mat[ 9], a22 = mat[10], a23 = mat[11]; - var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15]; - - // Cache only the current line of the second matrix - var b0 = mat2[0], b1 = mat2[1], b2 = mat2[2], b3 = mat2[3]; - dest[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[4]; - b1 = mat2[5]; - b2 = mat2[6]; - b3 = mat2[7]; - dest[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[8]; - b1 = mat2[9]; - b2 = mat2[10]; - b3 = mat2[11]; - dest[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - b0 = mat2[12]; - b1 = mat2[13]; - b2 = mat2[14]; - b3 = mat2[15]; - dest[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30; - dest[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31; - dest[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32; - dest[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33; - - return dest; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The base class for all objects that are rendered on the screen. - * - * @class DisplayObject - * @constructor - */ -PIXI.DisplayObject = function() -{ - this.last = this; - this.first = this; - - /** - * The coordinate of the object relative to the local coordinates of the parent. - * - * @property position - * @type Point - */ - this.position = new PIXI.Point(); - - /** - * The scale factor of the object. - * - * @property scale - * @type Point - */ - this.scale = new PIXI.Point(1,1);//{x:1, y:1}; - - /** - * The pivot point of the displayObject that it rotates around - * - * @property pivot - * @type Point - */ - this.pivot = new PIXI.Point(0,0); - - /** - * The rotation of the object in radians. - * - * @property rotation - * @type Number - */ - this.rotation = 0; - - /** - * The opacity of the object. - * - * @property alpha - * @type Number - */ - this.alpha = 1; - - /** - * The visibility of the object. - * - * @property visible - * @type Boolean - */ - this.visible = true; - - /** - * This is the defined area that will pick up mouse / touch events. It is null by default. - * Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children) - * - * @property hitArea - * @type Rectangle|Circle|Ellipse|Polygon - */ - this.hitArea = null; - - /** - * This is used to indicate if the displayObject should display a mouse hand cursor on rollover - * - * @property buttonMode - * @type Boolean - */ - this.buttonMode = false; - - /** - * Can this object be rendered - * - * @property renderable - * @type Boolean - */ - this.renderable = false; - - /** - * [read-only] The visibility of the object based on world (parent) factors. - * - * @property worldVisible - * @type Boolean - * @readOnly - */ - this.worldVisible = false; - - /** - * [read-only] The display object container that contains this display object. - * - * @property parent - * @type DisplayObjectContainer - * @readOnly - */ - this.parent = null; - - /** - * [read-only] The stage the display object is connected to, or undefined if it is not connected to the stage. - * - * @property stage - * @type Stage - * @readOnly - */ - this.stage = null; - - /** - * [read-only] The index of this object in the parent's `children` array - * - * @property childIndex - * @type Number - * @readOnly - */ - this.childIndex = 0; - - /** - * [read-only] The multiplied alpha of the displayobject - * - * @property worldAlpha - * @type Number - * @readOnly - */ - this.worldAlpha = 1; - - /** - * [read-only] Whether or not the object is interactive, do not toggle directly! use the `interactive` property - * - * @property _interactive - * @type Boolean - * @readOnly - * @private - */ - this._interactive = false; - - /** - * [read-only] Current transform of the object based on world (parent) factors - * - * @property worldTransform - * @type Mat3 - * @readOnly - * @private - */ - this.worldTransform = PIXI.mat3.create()//mat3.identity(); - - /** - * [read-only] Current transform of the object locally - * - * @property localTransform - * @type Mat3 - * @readOnly - * @private - */ - this.localTransform = PIXI.mat3.create()//mat3.identity(); - - /** - * [NYI] Unkown - * - * @property color - * @type Array<> - * @private - */ - this.color = []; - - /** - * [NYI] Holds whether or not this object is dynamic, for rendering optimization - * - * @property dynamic - * @type Boolean - * @private - */ - this.dynamic = true; - - // chach that puppy! - this._sr = 0; - this._cr = 1; - - /* - * MOUSE Callbacks - */ - - /** - * A callback that is used when the users clicks on the displayObject with their mouse - * @method click - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user clicks the mouse down over the sprite - * @method mousedown - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the mouse that was over the displayObject - * for this callback to be fired the mouse must have been pressed down over the displayObject - * @method mouseup - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject - * for this callback to be fired, The touch must have started over the displayObject - * @method mouseupoutside - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the users mouse rolls over the displayObject - * @method mouseover - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the users mouse leaves the displayObject - * @method mouseout - * @param interactionData {InteractionData} - */ - - - /* - * TOUCH Callbacks - */ - - /** - * A callback that is used when the users taps on the sprite with their finger - * basically a touch version of click - * @method tap - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user touch's over the displayObject - * @method touchstart - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases a touch over the displayObject - * @method touchend - * @param interactionData {InteractionData} - */ - - /** - * A callback that is used when the user releases the touch that was over the displayObject - * for this callback to be fired, The touch must have started over the sprite - * @method touchendoutside - * @param interactionData {InteractionData} - */ -} - -// constructor -PIXI.DisplayObject.prototype.constructor = PIXI.DisplayObject; - -//TODO make visible a getter setter -/* -Object.defineProperty(PIXI.DisplayObject.prototype, 'visible', { - get: function() { - return this._visible; - }, - set: function(value) { - this._visible = value; - } -});*/ - -/** - * [Deprecated] Indicates if the sprite will have touch and mouse interactivity. It is false by default - * Instead of using this function you can now simply set the interactive property to true or false - * - * @method setInteractive - * @param interactive {Boolean} - * @deprecated Simply set the `interactive` property directly - */ -PIXI.DisplayObject.prototype.setInteractive = function(interactive) -{ - this.interactive = interactive; -} - -/** - * Indicates if the sprite will have touch and mouse interactivity. It is false by default - * - * @property interactive - * @type Boolean - * @default false - */ -Object.defineProperty(PIXI.DisplayObject.prototype, 'interactive', { - get: function() { - return this._interactive; - }, - set: function(value) { - this._interactive = value; - - // TODO more to be done here.. - // need to sort out a re-crawl! - if(this.stage)this.stage.dirty = true; - } -}); - -/** - * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. - * In PIXI a regular mask must be a PIXI.Ggraphics object. This allows for much faster masking in canvas as it utilises shape clipping. - * To remove a mask, set this property to null. - * - * @property mask - * @type Graphics - */ -Object.defineProperty(PIXI.DisplayObject.prototype, 'mask', { - get: function() { - return this._mask; - }, - set: function(value) { - - this._mask = value; - - if(value) - { - this.addFilter(value) - } - else - { - this.removeFilter(); - } - } -}); - -/* - * Adds a filter to this displayObject - * - * @method addFilter - * @param mask {Graphics} the graphics object to use as a filter - * @private - */ -PIXI.DisplayObject.prototype.addFilter = function(mask) -{ - if(this.filter)return; - this.filter = true; - - - // insert a filter block.. - var start = new PIXI.FilterBlock(); - var end = new PIXI.FilterBlock(); - - - start.mask = mask; - end.mask = mask; - - start.first = start.last = this; - end.first = end.last = this; - - start.open = true; - - /* - * - * insert start - * - */ - - var childFirst = start - var childLast = start - var nextObject; - var previousObject; - - previousObject = this.first._iPrev; - - if(previousObject) - { - nextObject = previousObject._iNext; - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - } - else - { - nextObject = this; - } - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - - // now insert the end filter block.. - - /* - * - * insert end filter - * - */ - var childFirst = end - var childLast = end - var nextObject = null; - var previousObject = null; - - previousObject = this.last; - nextObject = previousObject._iNext; - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - var updateLast = this; - - var prevLast = this.last; - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = end; - } - updateLast = updateLast.parent; - } - - this.first = start; - - // if webGL... - if(this.__renderGroup) - { - this.__renderGroup.addFilterBlocks(start, end); - } - - mask.renderable = false; - -} - -/* - * Removes the filter to this displayObject - * - * @method removeFilter - * @private - */ -PIXI.DisplayObject.prototype.removeFilter = function() -{ - if(!this.filter)return; - this.filter = false; - - // modify the list.. - var startBlock = this.first; - - var nextObject = startBlock._iNext; - var previousObject = startBlock._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - if(previousObject)previousObject._iNext = nextObject; - - this.first = startBlock._iNext; - - - // remove the end filter - var lastBlock = this.last; - - var nextObject = lastBlock._iNext; - var previousObject = lastBlock._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - previousObject._iNext = nextObject; - - // this is always true too! -// if(this.last == lastBlock) - //{ - var tempLast = lastBlock._iPrev; - // need to make sure the parents last is updated too - var updateLast = this; - while(updateLast.last == lastBlock) - { - updateLast.last = tempLast; - updateLast = updateLast.parent; - if(!updateLast)break; - } - - var mask = startBlock.mask - mask.renderable = true; - - // if webGL... - if(this.__renderGroup) - { - this.__renderGroup.removeFilterBlocks(startBlock, lastBlock); - } - //} -} - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.DisplayObject.prototype.updateTransform = function() -{ - // TODO OPTIMIZE THIS!! with dirty - if(this.rotation != this.rotationCache) - { - this.rotationCache = this.rotation; - this._sr = Math.sin(this.rotation); - this._cr = Math.cos(this.rotation); - } - - var localTransform = this.localTransform; - var parentTransform = this.parent.worldTransform; - var worldTransform = this.worldTransform; - //console.log(localTransform) - localTransform[0] = this._cr * this.scale.x; - localTransform[1] = -this._sr * this.scale.y - localTransform[3] = this._sr * this.scale.x; - localTransform[4] = this._cr * this.scale.y; - - // TODO --> do we even need a local matrix??? - - var px = this.pivot.x; - var py = this.pivot.y; - - // Cache the matrix values (makes for huge speed increases!) - var a00 = localTransform[0], a01 = localTransform[1], a02 = this.position.x - localTransform[0] * px - py * localTransform[1], - a10 = localTransform[3], a11 = localTransform[4], a12 = this.position.y - localTransform[4] * py - px * localTransform[3], - - b00 = parentTransform[0], b01 = parentTransform[1], b02 = parentTransform[2], - b10 = parentTransform[3], b11 = parentTransform[4], b12 = parentTransform[5]; - - localTransform[2] = a02 - localTransform[5] = a12 - - worldTransform[0] = b00 * a00 + b01 * a10; - worldTransform[1] = b00 * a01 + b01 * a11; - worldTransform[2] = b00 * a02 + b01 * a12 + b02; - - worldTransform[3] = b10 * a00 + b11 * a10; - worldTransform[4] = b10 * a01 + b11 * a11; - worldTransform[5] = b10 * a02 + b11 * a12 + b12; - - // because we are using affine transformation, we can optimise the matrix concatenation process.. wooo! - // mat3.multiply(this.localTransform, this.parent.worldTransform, this.worldTransform); - this.worldAlpha = this.alpha * this.parent.worldAlpha; - -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * A DisplayObjectContainer represents a collection of display objects. - * It is the base class of all display objects that act as a container for other objects. - * - * @class DisplayObjectContainer - * @extends DisplayObject - * @constructor - */ -PIXI.DisplayObjectContainer = function() -{ - PIXI.DisplayObject.call( this ); - - /** - * [read-only] The of children of this container. - * - * @property children - * @type Array - * @readOnly - */ - this.children = []; -} - -// constructor -PIXI.DisplayObjectContainer.prototype = Object.create( PIXI.DisplayObject.prototype ); -PIXI.DisplayObjectContainer.prototype.constructor = PIXI.DisplayObjectContainer; - -//TODO make visible a getter setter -/* -Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'visible', { - get: function() { - return this._visible; - }, - set: function(value) { - this._visible = value; - - } -});*/ - -/** - * Adds a child to the container. - * - * @method addChild - * @param child {DisplayObject} The DisplayObject to add to the container - */ -PIXI.DisplayObjectContainer.prototype.addChild = function(child) -{ - if(child.parent != undefined) - { - - //// COULD BE THIS??? - child.parent.removeChild(child); - // return; - } - - child.parent = this; - child.childIndex = this.children.length; - - this.children.push(child); - - // updae the stage refference.. - - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = this.stage; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // LINKED LIST // - - // modify the list.. - var childFirst = child.first - var childLast = child.last; - var nextObject; - var previousObject; - - // this could be wrong if there is a filter?? - if(this.filter) - { - previousObject = this.last._iPrev; - } - else - { - previousObject = this.last; - } - - nextObject = previousObject._iNext; - - // always true in this case - //this.last = child.last; - // need to make sure the parents last is updated too - var updateLast = this; - var prevLast = previousObject; - - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = child.last; - } - updateLast = updateLast.parent; - } - - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - // need to remove any render groups.. - if(this.__renderGroup) - { - // being used by a renderTexture.. if it exists then it must be from a render texture; - if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child); - // add them to the new render group.. - this.__renderGroup.addDisplayObjectAndChildren(child); - } - -} - -/** - * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown - * - * @method addChildAt - * @param child {DisplayObject} The child to add - * @param index {Number} The index to place the child in - */ -PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index) -{ - if(index >= 0 && index <= this.children.length) - { - if(child.parent != undefined) - { - child.parent.removeChild(child); - } - child.parent = this; - - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = this.stage; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // modify the list.. - var childFirst = child.first - var childLast = child.last; - var nextObject; - var previousObject; - - if(index == this.children.length) - { - previousObject = this.last; - var updateLast = this;//.parent; - var prevLast = this.last; - while(updateLast) - { - if(updateLast.last == prevLast) - { - updateLast.last = child.last; - } - updateLast = updateLast.parent; - } - } - else if(index == 0) - { - previousObject = this; - } - else - { - previousObject = this.children[index-1].last; - } - - nextObject = previousObject._iNext; - - // always true in this case - if(nextObject) - { - nextObject._iPrev = childLast; - childLast._iNext = nextObject; - } - - childFirst._iPrev = previousObject; - previousObject._iNext = childFirst; - - this.children.splice(index, 0, child); - // need to remove any render groups.. - if(this.__renderGroup) - { - // being used by a renderTexture.. if it exists then it must be from a render texture; - if(child.__renderGroup)child.__renderGroup.removeDisplayObjectAndChildren(child); - // add them to the new render group.. - this.__renderGroup.addDisplayObjectAndChildren(child); - } - - } - else - { - throw new Error(child + " The index "+ index +" supplied is out of bounds " + this.children.length); - } -} - -/** - * [NYI] Swaps the depth of 2 displayObjects - * - * @method swapChildren - * @param child {DisplayObject} - * @param child2 {DisplayObject} - * @private - */ -PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2) -{ - /* - * this funtion needs to be recoded.. - * can be done a lot faster.. - */ - return; - - // need to fix this function :/ - /* - // TODO I already know this?? - var index = this.children.indexOf( child ); - var index2 = this.children.indexOf( child2 ); - - if ( index !== -1 && index2 !== -1 ) - { - // cool - - /* - if(this.stage) - { - // this is to satisfy the webGL batching.. - // TODO sure there is a nicer way to achieve this! - this.stage.__removeChild(child); - this.stage.__removeChild(child2); - - this.stage.__addChild(child); - this.stage.__addChild(child2); - } - - // swap the positions.. - this.children[index] = child2; - this.children[index2] = child; - - } - else - { - throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this); - }*/ -} - -/** - * Returns the Child at the specified index - * - * @method getChildAt - * @param index {Number} The index to get the child from - */ -PIXI.DisplayObjectContainer.prototype.getChildAt = function(index) -{ - if(index >= 0 && index < this.children.length) - { - return this.children[index]; - } - else - { - throw new Error(child + " Both the supplied DisplayObjects must be a child of the caller " + this); - } -} - -/** - * Removes a child from the container. - * - * @method removeChild - * @param child {DisplayObject} The DisplayObject to remove - */ -PIXI.DisplayObjectContainer.prototype.removeChild = function(child) -{ - var index = this.children.indexOf( child ); - if ( index !== -1 ) - { - // unlink // - // modify the list.. - var childFirst = child.first - var childLast = child.last; - - var nextObject = childLast._iNext; - var previousObject = childFirst._iPrev; - - if(nextObject)nextObject._iPrev = previousObject; - previousObject._iNext = nextObject; - - if(this.last == childLast) - { - var tempLast = childFirst._iPrev; - // need to make sure the parents last is updated too - var updateLast = this; - while(updateLast.last == childLast.last) - { - updateLast.last = tempLast; - updateLast = updateLast.parent; - if(!updateLast)break; - } - } - - childLast._iNext = null; - childFirst._iPrev = null; - - // update the stage reference.. - if(this.stage) - { - var tmpChild = child; - do - { - if(tmpChild.interactive)this.stage.dirty = true; - tmpChild.stage = null; - tmpChild = tmpChild._iNext; - } - while(tmpChild) - } - - // webGL trim - if(child.__renderGroup) - { - child.__renderGroup.removeDisplayObjectAndChildren(child); - } - - child.parent = undefined; - this.children.splice( index, 1 ); - } - else - { - throw new Error(child + " The supplied DisplayObject must be a child of the caller " + this); - } -} - -/* - * Updates the container's children's transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.DisplayObjectContainer.prototype.updateTransform = function() -{ - if(!this.visible)return; - - PIXI.DisplayObject.prototype.updateTransform.call( this ); - - for(var i=0,j=this.children.length; i} an array of {Texture} objects that make up the animation - */ -PIXI.MovieClip = function(textures) -{ - PIXI.Sprite.call(this, textures[0]); - - /** - * The array of textures that make up the animation - * - * @property textures - * @type Array - */ - this.textures = textures; - - /** - * The speed that the MovieClip will play at. Higher is faster, lower is slower - * - * @property animationSpeed - * @type Number - * @default 1 - */ - this.animationSpeed = 1; - - /** - * Whether or not the movie clip repeats after playing. - * - * @property loop - * @type Boolean - * @default true - */ - this.loop = true; - - /** - * Function to call when a MovieClip finishes playing - * - * @property onComplete - * @type Function - */ - this.onComplete = null; - - /** - * [read-only] The index MovieClips current frame (this may not have to be a whole number) - * - * @property currentFrame - * @type Number - * @default 0 - * @readOnly - */ - this.currentFrame = 0; - - /** - * [read-only] Indicates if the MovieClip is currently playing - * - * @property playing - * @type Boolean - * @readOnly - */ - this.playing = false; -} - -// constructor -PIXI.MovieClip.prototype = Object.create( PIXI.Sprite.prototype ); -PIXI.MovieClip.prototype.constructor = PIXI.MovieClip; - -/** - * Stops the MovieClip - * - * @method stop - */ -PIXI.MovieClip.prototype.stop = function() -{ - this.playing = false; -} - -/** - * Plays the MovieClip - * - * @method play - */ -PIXI.MovieClip.prototype.play = function() -{ - this.playing = true; -} - -/** - * Stops the MovieClip and goes to a specific frame - * - * @method gotoAndStop - * @param frameNumber {Number} frame index to stop at - */ -PIXI.MovieClip.prototype.gotoAndStop = function(frameNumber) -{ - this.playing = false; - this.currentFrame = frameNumber; - var round = (this.currentFrame + 0.5) | 0; - this.setTexture(this.textures[round % this.textures.length]); -} - -/** - * Goes to a specific frame and begins playing the MovieClip - * - * @method gotoAndPlay - * @param frameNumber {Number} frame index to start at - */ -PIXI.MovieClip.prototype.gotoAndPlay = function(frameNumber) -{ - this.currentFrame = frameNumber; - this.playing = true; -} - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.MovieClip.prototype.updateTransform = function() -{ - PIXI.Sprite.prototype.updateTransform.call(this); - - if(!this.playing)return; - - this.currentFrame += this.animationSpeed; - var round = (this.currentFrame + 0.5) | 0; - if(this.loop || round < this.textures.length) - { - this.setTexture(this.textures[round % this.textures.length]); - } - else if(round >= this.textures.length) - { - this.gotoAndStop(this.textures.length - 1); - if(this.onComplete) - { - this.onComplete(); - } - } -} -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - - -PIXI.FilterBlock = function(mask) -{ - this.graphics = mask - this.visible = true; - this.renderable = true; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Text Object will create a line(s) of text to split a line you can use "\n" - * - * @class Text - * @extends Sprite - * @constructor - * @param text {String} The copy that you would like the text to display - * @param [style] {Object} The style parameters - * @param [style.font] {String} default "bold 20pt Arial" The style and size of the font - * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00" - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - * @param [style.stroke] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00" - * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke) - * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used - * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap - */ -PIXI.Text = function(text, style) -{ - this.canvas = document.createElement("canvas"); - this.context = this.canvas.getContext("2d"); - PIXI.Sprite.call(this, PIXI.Texture.fromCanvas(this.canvas)); - - this.setText(text); - this.setStyle(style); - - this.updateText(); - this.dirty = false; -}; - -// constructor -PIXI.Text.prototype = Object.create(PIXI.Sprite.prototype); -PIXI.Text.prototype.constructor = PIXI.Text; - -/** - * Set the style of the text - * - * @method setStyle - * @param [style] {Object} The style parameters - * @param [style.font="bold 20pt Arial"] {String} The style and size of the font - * @param [style.fill="black"] {Object} A canvas fillstyle that will be used on the text eg "red", "#00FF00" - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - * @param [style.stroke="black"] {String} A canvas fillstyle that will be used on the text stroke eg "blue", "#FCFF00" - * @param [style.strokeThickness=0] {Number} A number that represents the thickness of the stroke. Default is 0 (no stroke) - * @param [style.wordWrap=false] {Boolean} Indicates if word wrap should be used - * @param [style.wordWrapWidth=100] {Number} The width at which text will wrap - */ -PIXI.Text.prototype.setStyle = function(style) -{ - style = style || {}; - style.font = style.font || "bold 20pt Arial"; - style.fill = style.fill || "black"; - style.align = style.align || "left"; - style.stroke = style.stroke || "black"; //provide a default, see: https://github.com/GoodBoyDigital/pixi.js/issues/136 - style.strokeThickness = style.strokeThickness || 0; - style.wordWrap = style.wordWrap || false; - style.wordWrapWidth = style.wordWrapWidth || 100; - this.style = style; - this.dirty = true; -}; - -/** - * Set the copy for the text object. To split a line you can use "\n" - * - * @methos setText - * @param {String} text The copy that you would like the text to display - */ -PIXI.Sprite.prototype.setText = function(text) -{ - this.text = text.toString() || " "; - this.dirty = true; -}; - -/** - * Renders text - * - * @method updateText - * @private - */ -PIXI.Text.prototype.updateText = function() -{ - this.context.font = this.style.font; - - var outputText = this.text; - - // word wrap - // preserve original text - if(this.style.wordWrap)outputText = this.wordWrap(this.text); - - //split text into lines - var lines = outputText.split(/(?:\r\n|\r|\n)/); - - //calculate text width - var lineWidths = []; - var maxLineWidth = 0; - for (var i = 0; i < lines.length; i++) - { - var lineWidth = this.context.measureText(lines[i]).width; - lineWidths[i] = lineWidth; - maxLineWidth = Math.max(maxLineWidth, lineWidth); - } - this.canvas.width = maxLineWidth + this.style.strokeThickness; - - //calculate text height - var lineHeight = this.determineFontHeight("font: " + this.style.font + ";") + this.style.strokeThickness; - this.canvas.height = lineHeight * lines.length; - - //set canvas text styles - this.context.fillStyle = this.style.fill; - this.context.font = this.style.font; - - this.context.strokeStyle = this.style.stroke; - this.context.lineWidth = this.style.strokeThickness; - - this.context.textBaseline = "top"; - - //draw lines line by line - for (i = 0; i < lines.length; i++) - { - var linePosition = new PIXI.Point(this.style.strokeThickness / 2, this.style.strokeThickness / 2 + i * lineHeight); - - if(this.style.align == "right") - { - linePosition.x += maxLineWidth - lineWidths[i]; - } - else if(this.style.align == "center") - { - linePosition.x += (maxLineWidth - lineWidths[i]) / 2; - } - - if(this.style.stroke && this.style.strokeThickness) - { - this.context.strokeText(lines[i], linePosition.x, linePosition.y); - } - - if(this.style.fill) - { - this.context.fillText(lines[i], linePosition.x, linePosition.y); - } - } - - this.updateTexture(); -}; - -/** - * Updates texture size based on canvas size - * - * @method updateTexture - * @private - */ -PIXI.Text.prototype.updateTexture = function() -{ - this.texture.baseTexture.width = this.canvas.width; - this.texture.baseTexture.height = this.canvas.height; - this.texture.frame.width = this.canvas.width; - this.texture.frame.height = this.canvas.height; - - this._width = this.canvas.width; - this._height = this.canvas.height; - - PIXI.texturesToUpdate.push(this.texture.baseTexture); -}; - -/** - * Updates the transfor of this object - * - * @method updateTransform - * @private - */ -PIXI.Text.prototype.updateTransform = function() -{ - if(this.dirty) - { - this.updateText(); - this.dirty = false; - } - - PIXI.Sprite.prototype.updateTransform.call(this); -}; - -/* - * http://stackoverflow.com/users/34441/ellisbben - * great solution to the problem! - * - * @method determineFontHeight - * @param fontStyle {Object} - * @private - */ -PIXI.Text.prototype.determineFontHeight = function(fontStyle) -{ - // build a little reference dictionary so if the font style has been used return a - // cached version... - var result = PIXI.Text.heightCache[fontStyle]; - - if(!result) - { - var body = document.getElementsByTagName("body")[0]; - var dummy = document.createElement("div"); - var dummyText = document.createTextNode("M"); - dummy.appendChild(dummyText); - dummy.setAttribute("style", fontStyle + ';position:absolute;top:0;left:0'); - body.appendChild(dummy); - - result = dummy.offsetHeight; - PIXI.Text.heightCache[fontStyle] = result; - - body.removeChild(dummy); - } - - return result; -}; - -/** - * A Text Object will apply wordwrap - * - * @method wordWrap - * @param text {String} - * @private - */ -PIXI.Text.prototype.wordWrap = function(text) -{ - // search good wrap position - var searchWrapPos = function(ctx, text, start, end, wrapWidth) - { - var p = Math.floor((end-start) / 2) + start; - if(p == start) { - return 1; - } - - if(ctx.measureText(text.substring(0,p)).width <= wrapWidth) - { - if(ctx.measureText(text.substring(0,p+1)).width > wrapWidth) - { - return p; - } - else - { - return arguments.callee(ctx, text, p, end, wrapWidth); - } - } - else - { - return arguments.callee(ctx, text, start, p, wrapWidth); - } - }; - - var lineWrap = function(ctx, text, wrapWidth) - { - if(ctx.measureText(text).width <= wrapWidth || text.length < 1) - { - return text; - } - var pos = searchWrapPos(ctx, text, 0, text.length, wrapWidth); - return text.substring(0, pos) + "\n" + arguments.callee(ctx, text.substring(pos), wrapWidth); - }; - - var result = ""; - var lines = text.split("\n"); - for (var i = 0; i < lines.length; i++) - { - result += lineWrap(this.context, lines[i], this.style.wordWrapWidth) + "\n"; - } - - return result; -}; - -/** - * Destroys this text object - * - * @method destroy - * @param destroyTexture {Boolean} - */ -PIXI.Text.prototype.destroy = function(destroyTexture) -{ - if(destroyTexture) - { - this.texture.destroy(); - } - -}; - -PIXI.Text.heightCache = {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Text Object will create a line(s) of text using bitmap font. To split a line you can use "\n", "\r" or "\r\n" - * You can generate the fnt files using - * http://www.angelcode.com/products/bmfont/ for windows or - * http://www.bmglyph.com/ for mac. - * - * @class BitmapText - * @extends DisplayObjectContainer - * @constructor - * @param text {String} The copy that you would like the text to display - * @param style {Object} The style parameters - * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously) - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - */ -PIXI.BitmapText = function(text, style) -{ - PIXI.DisplayObjectContainer.call(this); - - this.setText(text); - this.setStyle(style); - this.updateText(); - this.dirty = false - -}; - -// constructor -PIXI.BitmapText.prototype = Object.create(PIXI.DisplayObjectContainer.prototype); -PIXI.BitmapText.prototype.constructor = PIXI.BitmapText; - -/** - * Set the copy for the text object - * - * @method setText - * @param text {String} The copy that you would like the text to display - */ -PIXI.BitmapText.prototype.setText = function(text) -{ - this.text = text || " "; - this.dirty = true; -}; - -/** - * Set the style of the text - * - * @method setStyle - * @param style {Object} The style parameters - * @param style.font {String} The size (optional) and bitmap font id (required) eq "Arial" or "20px Arial" (must have loaded previously) - * @param [style.align="left"] {String} An alignment of the multiline text ("left", "center" or "right") - */ -PIXI.BitmapText.prototype.setStyle = function(style) -{ - style = style || {}; - style.align = style.align || "left"; - this.style = style; - - var font = style.font.split(" "); - this.fontName = font[font.length - 1]; - this.fontSize = font.length >= 2 ? parseInt(font[font.length - 2], 10) : PIXI.BitmapText.fonts[this.fontName].size; - - this.dirty = true; -}; - -/** - * Renders text - * - * @method updateText - * @private - */ -PIXI.BitmapText.prototype.updateText = function() -{ - var data = PIXI.BitmapText.fonts[this.fontName]; - var pos = new PIXI.Point(); - var prevCharCode = null; - var chars = []; - var maxLineWidth = 0; - var lineWidths = []; - var line = 0; - var scale = this.fontSize / data.size; - for(var i = 0; i < this.text.length; i++) - { - var charCode = this.text.charCodeAt(i); - if(/(?:\r\n|\r|\n)/.test(this.text.charAt(i))) - { - lineWidths.push(pos.x); - maxLineWidth = Math.max(maxLineWidth, pos.x); - line++; - - pos.x = 0; - pos.y += data.lineHeight; - prevCharCode = null; - continue; - } - - var charData = data.chars[charCode]; - if(!charData) continue; - - if(prevCharCode && charData[prevCharCode]) - { - pos.x += charData.kerning[prevCharCode]; - } - chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); - pos.x += charData.xAdvance; - - prevCharCode = charCode; - } - - lineWidths.push(pos.x); - maxLineWidth = Math.max(maxLineWidth, pos.x); - - var lineAlignOffsets = []; - for(i = 0; i <= line; i++) - { - var alignOffset = 0; - if(this.style.align == "right") - { - alignOffset = maxLineWidth - lineWidths[i]; - } - else if(this.style.align == "center") - { - alignOffset = (maxLineWidth - lineWidths[i]) / 2; - } - lineAlignOffsets.push(alignOffset); - } - - for(i = 0; i < chars.length; i++) - { - var c = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode); - c.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; - c.position.y = chars[i].position.y * scale; - c.scale.x = c.scale.y = scale; - this.addChild(c); - } - - this.width = pos.x * scale; - this.height = (pos.y + data.lineHeight) * scale; -}; - -/** - * Updates the transfor of this object - * - * @method updateTransform - * @private - */ -PIXI.BitmapText.prototype.updateTransform = function() -{ - if(this.dirty) - { - while(this.children.length > 0) - { - this.removeChild(this.getChildAt(0)); - } - this.updateText(); - - this.dirty = false; - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call(this); -}; - -PIXI.BitmapText.fonts = {}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - - -/** - * The interaction manager deals with mouse and touch events. Any DisplayObject can be interactive - * This manager also supports multitouch. - * - * @class InteractionManager - * @constructor - * @param stage {Stage} The stage to handle interactions - */ -PIXI.InteractionManager = function(stage) -{ - /** - * a refference to the stage - * - * @property stage - * @type Stage - */ - this.stage = stage; - - /** - * the mouse data - * - * @property mouse - * @type InteractionData - */ - this.mouse = new PIXI.InteractionData(); - - /** - * an object that stores current touches (InteractionData) by id reference - * - * @property touchs - * @type Object - */ - this.touchs = {}; - - // helpers - this.tempPoint = new PIXI.Point(); - //this.tempMatrix = mat3.create(); - - this.mouseoverEnabled = true; - - //tiny little interactiveData pool! - this.pool = []; - - this.interactiveItems = []; - - this.last = 0; -} - -// constructor -PIXI.InteractionManager.prototype.constructor = PIXI.InteractionManager; - -/** - * Collects an interactive sprite recursively to have their interactions managed - * - * @method collectInteractiveSprite - * @param displayObject {DisplayObject} the displayObject to collect - * @param iParent {DisplayObject} - * @private - */ -PIXI.InteractionManager.prototype.collectInteractiveSprite = function(displayObject, iParent) -{ - var children = displayObject.children; - var length = children.length; - - /// make an interaction tree... {item.__interactiveParent} - for (var i = length-1; i >= 0; i--) - { - var child = children[i]; - - if(child.visible) { - // push all interactive bits - if(child.interactive) - { - iParent.interactiveChildren = true; - //child.__iParent = iParent; - this.interactiveItems.push(child); - - if(child.children.length > 0) - { - this.collectInteractiveSprite(child, child); - } - } - else - { - child.__iParent = null; - - if(child.children.length > 0) - { - this.collectInteractiveSprite(child, iParent); - } - } - } - } -} - -/** - * Sets the target for event delegation - * - * @method setTarget - * @param target {WebGLRenderer|CanvasRenderer} the renderer to bind events to - * @private - */ -PIXI.InteractionManager.prototype.setTarget = function(target) -{ - if (window.navigator.msPointerEnabled) - { - // time to remove some of that zoom in ja.. - target.view.style["-ms-content-zooming"] = "none"; - target.view.style["-ms-touch-action"] = "none" - - // DO some window specific touch! - } - - this.target = target; - target.view.addEventListener('mousemove', this.onMouseMove.bind(this), true); - target.view.addEventListener('mousedown', this.onMouseDown.bind(this), true); - document.body.addEventListener('mouseup', this.onMouseUp.bind(this), true); - target.view.addEventListener('mouseout', this.onMouseUp.bind(this), true); - - // aint no multi touch just yet! - target.view.addEventListener("touchstart", this.onTouchStart.bind(this), true); - target.view.addEventListener("touchend", this.onTouchEnd.bind(this), true); - target.view.addEventListener("touchmove", this.onTouchMove.bind(this), true); -} - -/** - * updates the state of interactive objects - * - * @method update - * @private - */ -PIXI.InteractionManager.prototype.update = function() -{ - if(!this.target)return; - - // frequency of 30fps?? - var now = Date.now(); - var diff = now - this.last; - diff = (diff * 30) / 1000; - if(diff < 1)return; - this.last = now; - // - - // ok.. so mouse events?? - // yes for now :) - // OPTIMSE - how often to check?? - if(this.dirty) - { - this.dirty = false; - - var len = this.interactiveItems.length; - - for (var i=0; i < len; i++) { - this.interactiveItems[i].interactiveChildren = false; - } - - this.interactiveItems = []; - - if(this.stage.interactive)this.interactiveItems.push(this.stage); - // go through and collect all the objects that are interactive.. - this.collectInteractiveSprite(this.stage, this.stage); - } - - // loop through interactive objects! - var length = this.interactiveItems.length; - - this.target.view.style.cursor = "default"; - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - if(!item.visible)continue; - - // OPTIMISATION - only calculate every time if the mousemove function exists.. - // OK so.. does the object have any other interactive functions? - // hit-test the clip! - - - if(item.mouseover || item.mouseout || item.buttonMode) - { - // ok so there are some functions so lets hit test it.. - item.__hit = this.hitTest(item, this.mouse); - this.mouse.target = item; - // ok so deal with interactions.. - // loks like there was a hit! - if(item.__hit) - { - if(item.buttonMode)this.target.view.style.cursor = "pointer"; - - if(!item.__isOver) - { - - if(item.mouseover)item.mouseover(this.mouse); - item.__isOver = true; - } - } - else - { - if(item.__isOver) - { - // roll out! - if(item.mouseout)item.mouseout(this.mouse); - item.__isOver = false; - } - } - } - - // ---> - } -} - -/** - * Is called when the mouse moves accross the renderer element - * - * @method onMouseMove - * @param event {Event} The DOM event of the mouse moving - * @private - */ -PIXI.InteractionManager.prototype.onMouseMove = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - // TODO optimize by not check EVERY TIME! maybe half as often? // - var rect = this.target.view.getBoundingClientRect(); - - this.mouse.global.x = (event.clientX - rect.left) * (this.target.width / rect.width); - this.mouse.global.y = (event.clientY - rect.top) * ( this.target.height / rect.height); - - var length = this.interactiveItems.length; - var global = this.mouse.global; - - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mousemove) - { - //call the function! - item.mousemove(this.mouse); - } - } -} - -/** - * Is called when the mouse button is pressed down on the renderer element - * - * @method onMouseDown - * @param event {Event} The DOM event of a mouse button being pressed down - * @private - */ -PIXI.InteractionManager.prototype.onMouseDown = function(event) -{ - event.preventDefault(); - this.mouse.originalEvent = event || window.event; //IE uses window.event - - // loop through inteaction tree... - // hit test each item! -> - // get interactive items under point?? - //stage.__i - var length = this.interactiveItems.length; - var global = this.mouse.global; - - var index = 0; - var parent = this.stage; - - // while - // hit test - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mousedown || item.click) - { - item.__mouseIsDown = true; - item.__hit = this.hitTest(item, this.mouse); - - if(item.__hit) - { - //call the function! - if(item.mousedown)item.mousedown(this.mouse); - item.__isDown = true; - - // just the one! - if(!item.interactiveChildren)break; - } - } - } -} - -/** - * Is called when the mouse button is released on the renderer element - * - * @method onMouseUp - * @param event {Event} The DOM event of a mouse button being released - * @private - */ -PIXI.InteractionManager.prototype.onMouseUp = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - - var global = this.mouse.global; - - - var length = this.interactiveItems.length; - var up = false; - - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - - if(item.mouseup || item.mouseupoutside || item.click) - { - item.__hit = this.hitTest(item, this.mouse); - - if(item.__hit && !up) - { - //call the function! - if(item.mouseup) - { - item.mouseup(this.mouse); - } - if(item.__isDown) - { - if(item.click)item.click(this.mouse); - } - - if(!item.interactiveChildren)up = true; - } - else - { - if(item.__isDown) - { - if(item.mouseupoutside)item.mouseupoutside(this.mouse); - } - } - - item.__isDown = false; - } - } -} - -/** - * Tests if the current mouse coords hit a sprite - * - * @method hitTest - * @param item {DisplayObject} The displayObject to test for a hit - * @param interactionData {InteractionData} The interactiondata object to update in the case of a hit - * @private - */ -PIXI.InteractionManager.prototype.hitTest = function(item, interactionData) -{ - var global = interactionData.global; - - if(!item.visible)return false; - - var isSprite = (item instanceof PIXI.Sprite), - worldTransform = item.worldTransform, - a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2], - a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5], - id = 1 / (a00 * a11 + a01 * -a10), - x = a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id, - y = a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id; - - interactionData.target = item; - - //a sprite or display object with a hit area defined - if(item.hitArea && item.hitArea.contains) { - if(item.hitArea.contains(x, y)) { - //if(isSprite) - interactionData.target = item; - - return true; - } - - return false; - } - // a sprite with no hitarea defined - else if(isSprite) - { - var width = item.texture.frame.width, - height = item.texture.frame.height, - x1 = -width * item.anchor.x, - y1; - - if(x > x1 && x < x1 + width) - { - y1 = -height * item.anchor.y; - - if(y > y1 && y < y1 + height) - { - // set the target property if a hit is true! - interactionData.target = item - return true; - } - } - } - - var length = item.children.length; - - for (var i = 0; i < length; i++) - { - var tempItem = item.children[i]; - var hit = this.hitTest(tempItem, interactionData); - if(hit) - { - // hmm.. TODO SET CORRECT TARGET? - interactionData.target = item - return true; - } - } - - return false; -} - -/** - * Is called when a touch is moved accross the renderer element - * - * @method onTouchMove - * @param event {Event} The DOM event of a touch moving accross the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchMove = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - var rect = this.target.view.getBoundingClientRect(); - var changedTouches = event.changedTouches; - - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - var touchData = this.touchs[touchEvent.identifier]; - - // update the touch position - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - } - - var length = this.interactiveItems.length; - for (var i = 0; i < length; i++) - { - var item = this.interactiveItems[i]; - if(item.touchmove)item.touchmove(touchData); - } -} - -/** - * Is called when a touch is started on the renderer element - * - * @method onTouchStart - * @param event {Event} The DOM event of a touch starting on the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchStart = function(event) -{ - event.preventDefault(); - this.mouse.originalEvent = event || window.event; //IE uses window.event - - var rect = this.target.view.getBoundingClientRect(); - - var changedTouches = event.changedTouches; - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - - var touchData = this.pool.pop(); - if(!touchData)touchData = new PIXI.InteractionData(); - - this.touchs[touchEvent.identifier] = touchData; - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - - var length = this.interactiveItems.length; - - for (var j = 0; j < length; j++) - { - var item = this.interactiveItems[j]; - - if(item.touchstart || item.tap) - { - item.__hit = this.hitTest(item, touchData); - - if(item.__hit) - { - //call the function! - if(item.touchstart)item.touchstart(touchData); - item.__isDown = true; - item.__touchData = touchData; - - if(!item.interactiveChildren)break; - } - } - } - } -} - -/** - * Is called when a touch is ended on the renderer element - * - * @method onTouchEnd - * @param event {Event} The DOM event of a touch ending on the renderer view - * @private - */ -PIXI.InteractionManager.prototype.onTouchEnd = function(event) -{ - this.mouse.originalEvent = event || window.event; //IE uses window.event - var rect = this.target.view.getBoundingClientRect(); - var changedTouches = event.changedTouches; - - for (var i=0; i < changedTouches.length; i++) - { - var touchEvent = changedTouches[i]; - var touchData = this.touchs[touchEvent.identifier]; - var up = false; - touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); - touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); - - var length = this.interactiveItems.length; - for (var j = 0; j < length; j++) - { - var item = this.interactiveItems[j]; - var itemTouchData = item.__touchData; // <-- Here! - item.__hit = this.hitTest(item, touchData); - - if(itemTouchData == touchData) - { - // so this one WAS down... - - // hitTest?? - - if(item.touchend || item.tap) - { - if(item.__hit && !up) - { - if(item.touchend)item.touchend(touchData); - if(item.__isDown) - { - if(item.tap)item.tap(touchData); - } - - if(!item.interactiveChildren)up = true; - } - else - { - if(item.__isDown) - { - if(item.touchendoutside)item.touchendoutside(touchData); - } - } - - item.__isDown = false; - } - - item.__touchData = null; - - } - else - { - - } - } - // remove the touch.. - this.pool.push(touchData); - this.touchs[touchEvent.identifier] = null; - } -} - -/** - * Holds all information related to an Interaction event - * - * @class InteractionData - * @constructor - */ -PIXI.InteractionData = function() -{ - /** - * This point stores the global coords of where the touch/mouse event happened - * - * @property global - * @type Point - */ - this.global = new PIXI.Point(); - - // this is here for legacy... but will remove - this.local = new PIXI.Point(); - - /** - * The target Sprite that was interacted with - * - * @property target - * @type Sprite - */ - this.target; - - /** - * When passed to an event handler, this will be the original DOM Event that was captured - * - * @property originalEvent - * @type Event - */ - this.originalEvent; -} - -/** - * This will return the local coords of the specified displayObject for this InteractionData - * - * @method getLocalPosition - * @param displayObject {DisplayObject} The DisplayObject that you would like the local coords off - * @return {Point} A point containing the coords of the InteractionData position relative to the DisplayObject - */ -PIXI.InteractionData.prototype.getLocalPosition = function(displayObject) -{ - var worldTransform = displayObject.worldTransform; - var global = this.global; - - // do a cheeky transform to get the mouse coords; - var a00 = worldTransform[0], a01 = worldTransform[1], a02 = worldTransform[2], - a10 = worldTransform[3], a11 = worldTransform[4], a12 = worldTransform[5], - id = 1 / (a00 * a11 + a01 * -a10); - // set the mouse coords... - return new PIXI.Point(a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id, - a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id) -} - -// constructor -PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A Stage represents the root of the display tree. Everything connected to the stage is rendered - * - * @class Stage - * @extends DisplayObjectContainer - * @constructor - * @param backgroundColor {Number} the background color of the stage, easiest way to pass this in is in hex format - * like: 0xFFFFFF for white - * @param interactive {Boolean} enable / disable interaction (default is false) - */ -PIXI.Stage = function(backgroundColor, interactive) -{ - PIXI.DisplayObjectContainer.call( this ); - - /** - * [read-only] Current transform of the object based on world (parent) factors - * - * @property worldTransform - * @type Mat3 - * @readOnly - * @private - */ - this.worldTransform = PIXI.mat3.create(); - - /** - * Whether or not the stage is interactive - * - * @property interactive - * @type Boolean - */ - this.interactive = interactive; - - /** - * The interaction manage for this stage, manages all interactive activity on the stage - * - * @property interactive - * @type InteractionManager - */ - this.interactionManager = new PIXI.InteractionManager(this); - - /** - * Whether the stage is dirty and needs to have interactions updated - * - * @property dirty - * @type Boolean - * @private - */ - this.dirty = true; - - this.__childrenAdded = []; - this.__childrenRemoved = []; - - //the stage is it's own stage - this.stage = this; - - //optimize hit detection a bit - this.stage.hitArea = new PIXI.Rectangle(0,0,100000, 100000); - - this.setBackgroundColor(backgroundColor); - this.worldVisible = true; -} - -// constructor -PIXI.Stage.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Stage.prototype.constructor = PIXI.Stage; - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.Stage.prototype.updateTransform = function() -{ - this.worldAlpha = 1; - - for(var i=0,j=this.children.length; i> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; -} - -/** - * A polyfill for Function.prototype.bind - * - * @method bind - */ -if (typeof Function.prototype.bind != 'function') { - Function.prototype.bind = (function () { - var slice = Array.prototype.slice; - return function (thisArg) { - var target = this, boundArgs = slice.call(arguments, 1); - - if (typeof target != 'function') throw new TypeError(); - - function bound() { - var args = boundArgs.concat(slice.call(arguments)); - target.apply(this instanceof bound ? this : thisArg, args); - } - - bound.prototype = (function F(proto) { - proto && (F.prototype = proto); - if (!(this instanceof F)) return new F; - })(target.prototype); - - return bound; - }; - })(); -} - -/** - * A wrapper for ajax requests to be handled cross browser - * - * @class AjaxRequest - * @constructor - */ -var AjaxRequest = PIXI.AjaxRequest = function() -{ - var activexmodes = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE - - if (window.ActiveXObject) - { //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken) - for (var i=0; i>>>>>>>>") - console.log("_") - var safe = 0; - var tmp = item.first; - console.log(tmp); - - while(tmp._iNext) - { - safe++; -// console.log(tmp.childIndex + tmp); - tmp = tmp._iNext; - console.log(tmp);//.childIndex); - // console.log(tmp); - - if(safe > 100) - { - console.log("BREAK") - break - } - } -} - - - - - - -/** - * https://github.com/mrdoob/eventtarget.js/ - * THankS mr DOob! - */ - -/** - * Adds event emitter functionality to a class - * - * @class EventTarget - * @example - * function MyEmitter() { - * PIXI.EventTarget.call(this); //mixes in event target stuff - * } - * - * var em = new MyEmitter(); - * em.emit({ type: 'eventName', data: 'some data' }); - */ -PIXI.EventTarget = function () { - - var listeners = {}; - - this.addEventListener = this.on = function ( type, listener ) { - - - if ( listeners[ type ] === undefined ) { - - listeners[ type ] = []; - - } - - if ( listeners[ type ].indexOf( listener ) === - 1 ) { - - listeners[ type ].push( listener ); - } - - }; - - this.dispatchEvent = this.emit = function ( event ) { - - for ( var listener in listeners[ event.type ] ) { - - listeners[ event.type ][ listener ]( event ); - - } - - }; - - this.removeEventListener = this.off = function ( type, listener ) { - - var index = listeners[ type ].indexOf( listener ); - - if ( index !== - 1 ) { - - listeners[ type ].splice( index, 1 ); - - } - - }; - -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * This helper function will automatically detect which renderer you should be using. - * WebGL is the preferred renderer as it is a lot fastest. If webGL is not supported by - * the browser then this function will return a canvas renderer - * - * @method autoDetectRenderer - * @static - * @param width {Number} the width of the renderers view - * @param height {Number} the height of the renderers view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - */ -PIXI.autoDetectRenderer = function(width, height, view, transparent) -{ - if(!width)width = 800; - if(!height)height = 600; - - // BORROWED from Mr Doob (mrdoob.com) - var webgl = ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )(); - - //console.log(webgl); - if( webgl ) - { - return new PIXI.WebGLRenderer(width, height, view, transparent); - } - - return new PIXI.CanvasRenderer(width, height, view, transparent); -}; - - - -/* - PolyK library - url: http://polyk.ivank.net - Released under MIT licence. - - Copyright (c) 2012 Ivan Kuckir - - 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. - - This is an amazing lib! - - slightly modified by mat groves (matgroves.com); -*/ - -PIXI.PolyK = {}; - -/** - * Triangulates shapes for webGL graphic fills - * - * @method Triangulate - * @namespace PolyK - * @constructor - */ -PIXI.PolyK.Triangulate = function(p) -{ - var sign = true; - - var n = p.length>>1; - if(n<3) return []; - var tgs = []; - var avl = []; - for(var i=0; i 3) - { - var i0 = avl[(i+0)%al]; - var i1 = avl[(i+1)%al]; - var i2 = avl[(i+2)%al]; - - var ax = p[2*i0], ay = p[2*i0+1]; - var bx = p[2*i1], by = p[2*i1+1]; - var cx = p[2*i2], cy = p[2*i2+1]; - - var earFound = false; - if(PIXI.PolyK._convex(ax, ay, bx, by, cx, cy, sign)) - { - earFound = true; - for(var j=0; j 3*al) - { - // need to flip flip reverse it! - // reset! - if(sign) - { - var tgs = []; - avl = []; - for(var i=0; i= 0) && (v >= 0) && (u + v < 1); -} - -/** - * Checks if a shape is convex - * - * @class _convex - * @namespace PolyK - * @private - */ -PIXI.PolyK._convex = function(ax, ay, bx, by, cx, cy, sign) -{ - return ((ay-by)*(cx-bx) + (bx-ax)*(cy-by) >= 0) == sign; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/* - * the default suoer fast shader! - */ - -PIXI.shaderFragmentSrc = [ - "precision mediump float;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "uniform sampler2D uSampler;", - "void main(void) {", - "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));", - "gl_FragColor = gl_FragColor * vColor;", - "}" -]; - -PIXI.shaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec2 aTextureCoord;", - "attribute float aColor;", - //"uniform mat4 uMVMatrix;", - - "uniform vec2 projectionVector;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "void main(void) {", - // "gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0, 1.0);", - "gl_Position = vec4( aVertexPosition.x / projectionVector.x -1.0, aVertexPosition.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vTextureCoord = aTextureCoord;", - "vColor = aColor;", - "}" -]; - -/* - * the triangle strip shader.. - */ - -PIXI.stripShaderFragmentSrc = [ - "precision mediump float;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "uniform float alpha;", - "uniform sampler2D uSampler;", - "void main(void) {", - "gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.x, vTextureCoord.y));", - "gl_FragColor = gl_FragColor * alpha;", - "}" -]; - - -PIXI.stripShaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec2 aTextureCoord;", - "attribute float aColor;", - "uniform mat3 translationMatrix;", - "uniform vec2 projectionVector;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "void main(void) {", - "vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);", - "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vTextureCoord = aTextureCoord;", - "vColor = aColor;", - "}" -]; - - -/* - * primitive shader.. - */ - -PIXI.primitiveShaderFragmentSrc = [ - "precision mediump float;", - "varying vec4 vColor;", - "void main(void) {", - "gl_FragColor = vColor;", - "}" -]; - -PIXI.primitiveShaderVertexSrc = [ - "attribute vec2 aVertexPosition;", - "attribute vec4 aColor;", - "uniform mat3 translationMatrix;", - "uniform vec2 projectionVector;", - "uniform float alpha;", - "varying vec4 vColor;", - "void main(void) {", - "vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);", - "gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);", - "vColor = aColor * alpha;", - "}" -]; - -PIXI.initPrimitiveShader = function() -{ - var gl = PIXI.gl; - - var shaderProgram = PIXI.compileProgram(PIXI.primitiveShaderVertexSrc, PIXI.primitiveShaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, "translationMatrix"); - - shaderProgram.alpha = gl.getUniformLocation(shaderProgram, "alpha"); - - PIXI.primitiveProgram = shaderProgram; -} - -PIXI.initDefaultShader = function() -{ - var gl = this.gl; - var shaderProgram = PIXI.compileProgram(PIXI.shaderVertexSrc, PIXI.shaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord"); - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - // shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix"); - shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler"); - - PIXI.shaderProgram = shaderProgram; -} - -PIXI.initDefaultStripShader = function() -{ - var gl = this.gl; - var shaderProgram = PIXI.compileProgram(PIXI.stripShaderVertexSrc, PIXI.stripShaderFragmentSrc) - - gl.useProgram(shaderProgram); - - shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord"); - shaderProgram.translationMatrix = gl.getUniformLocation(shaderProgram, "translationMatrix"); - shaderProgram.alpha = gl.getUniformLocation(shaderProgram, "alpha"); - - shaderProgram.colorAttribute = gl.getAttribLocation(shaderProgram, "aColor"); - - shaderProgram.projectionVector = gl.getUniformLocation(shaderProgram, "projectionVector"); - - shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler"); - - PIXI.stripShaderProgram = shaderProgram; -} - -PIXI.CompileVertexShader = function(gl, shaderSrc) -{ - return PIXI._CompileShader(gl, shaderSrc, gl.VERTEX_SHADER); -} - -PIXI.CompileFragmentShader = function(gl, shaderSrc) -{ - return PIXI._CompileShader(gl, shaderSrc, gl.FRAGMENT_SHADER); -} - -PIXI._CompileShader = function(gl, shaderSrc, shaderType) -{ - var src = shaderSrc.join("\n"); - var shader = gl.createShader(shaderType); - gl.shaderSource(shader, src); - gl.compileShader(shader); - - if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) { - alert(gl.getShaderInfoLog(shader)); - return null; - } - - return shader; -} - - -PIXI.compileProgram = function(vertexSrc, fragmentSrc) -{ - var gl = PIXI.gl; - var fragmentShader = PIXI.CompileFragmentShader(gl, fragmentSrc); - var vertexShader = PIXI.CompileVertexShader(gl, vertexSrc); - - var shaderProgram = gl.createProgram(); - - gl.attachShader(shaderProgram, vertexShader); - gl.attachShader(shaderProgram, fragmentShader); - gl.linkProgram(shaderProgram); - - if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) { - alert("Could not initialise shaders"); - } - - return shaderProgram; -} - - -PIXI.activateDefaultShader = function() -{ - var gl = PIXI.gl; - var shaderProgram = PIXI.shaderProgram; - - gl.useProgram(shaderProgram); - - - gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute); - gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute); - gl.enableVertexAttribArray(shaderProgram.colorAttribute); -} - - - -PIXI.activatePrimitiveShader = function() -{ - var gl = PIXI.gl; - - gl.disableVertexAttribArray(PIXI.shaderProgram.textureCoordAttribute); - gl.disableVertexAttribArray(PIXI.shaderProgram.colorAttribute); - - gl.useProgram(PIXI.primitiveProgram); - - gl.enableVertexAttribArray(PIXI.primitiveProgram.vertexPositionAttribute); - gl.enableVertexAttribArray(PIXI.primitiveProgram.colorAttribute); -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A set of functions used by the webGL renderer to draw the primitive graphics data - * - * @class CanvasGraphics - */ -PIXI.WebGLGraphics = function() -{ - -} - -/** - * Renders the graphics object - * - * @static - * @private - * @method renderGraphics - * @param graphics {Graphics} - * @param projection {Object} - */ -PIXI.WebGLGraphics.renderGraphics = function(graphics, projection) -{ - var gl = PIXI.gl; - - if(!graphics._webGL)graphics._webGL = {points:[], indices:[], lastIndex:0, - buffer:gl.createBuffer(), - indexBuffer:gl.createBuffer()}; - - if(graphics.dirty) - { - graphics.dirty = false; - - if(graphics.clearDirty) - { - graphics.clearDirty = false; - - graphics._webGL.lastIndex = 0; - graphics._webGL.points = []; - graphics._webGL.indices = []; - - } - - PIXI.WebGLGraphics.updateGraphics(graphics); - } - - - PIXI.activatePrimitiveShader(); - - // This could be speeded up fo sure! - var m = PIXI.mat3.clone(graphics.worldTransform); - - PIXI.mat3.transpose(m); - - // set the matrix transform for the - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - - gl.uniformMatrix3fv(PIXI.primitiveProgram.translationMatrix, false, m); - - gl.uniform2f(PIXI.primitiveProgram.projectionVector, projection.x, projection.y); - - gl.uniform1f(PIXI.primitiveProgram.alpha, graphics.worldAlpha); - - gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer); - - // WHY DOES THIS LINE NEED TO BE THERE??? - gl.vertexAttribPointer(PIXI.shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - // its not even used.. but need to be set or it breaks? - // only on pc though.. - - gl.vertexAttribPointer(PIXI.primitiveProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 4 * 6, 0); - gl.vertexAttribPointer(PIXI.primitiveProgram.colorAttribute, 4, gl.FLOAT, false,4 * 6, 2 * 4); - - // set the index buffer! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer); - - gl.drawElements(gl.TRIANGLE_STRIP, graphics._webGL.indices.length, gl.UNSIGNED_SHORT, 0 ); - - // return to default shader... - PIXI.activateDefaultShader(); -} - -/** - * Updates the graphics object - * - * @static - * @private - * @method updateGraphics - * @param graphics {Graphics} - */ -PIXI.WebGLGraphics.updateGraphics = function(graphics) -{ - for (var i=graphics._webGL.lastIndex; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - - if(data.type == PIXI.Graphics.POLY) - { - if(data.fill) - { - if(data.points.length>3) - PIXI.WebGLGraphics.buildPoly(data, graphics._webGL); - } - - if(data.lineWidth > 0) - { - PIXI.WebGLGraphics.buildLine(data, graphics._webGL); - } - } - else if(data.type == PIXI.Graphics.RECT) - { - PIXI.WebGLGraphics.buildRectangle(data, graphics._webGL); - } - else if(data.type == PIXI.Graphics.CIRC || data.type == PIXI.Graphics.ELIP) - { - PIXI.WebGLGraphics.buildCircle(data, graphics._webGL); - } - }; - - graphics._webGL.lastIndex = graphics.graphicsData.length; - - var gl = PIXI.gl; - - graphics._webGL.glPoints = new Float32Array(graphics._webGL.points); - - gl.bindBuffer(gl.ARRAY_BUFFER, graphics._webGL.buffer); - gl.bufferData(gl.ARRAY_BUFFER, graphics._webGL.glPoints, gl.STATIC_DRAW); - - graphics._webGL.glIndicies = new Uint16Array(graphics._webGL.indices); - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, graphics._webGL.glIndicies, gl.STATIC_DRAW); -} - -/** - * Builds a rectangle to draw - * - * @static - * @private - * @method buildRectangle - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData) -{ - // --- // - // need to convert points to a nice regular data - // - var rectData = graphicsData.points; - var x = rectData[0]; - var y = rectData[1]; - var width = rectData[2]; - var height = rectData[3]; - - - if(graphicsData.fill) - { - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vertPos = verts.length/6; - - // start - verts.push(x, y); - verts.push(r, g, b, alpha); - - verts.push(x + width, y); - verts.push(r, g, b, alpha); - - verts.push(x , y + height); - verts.push(r, g, b, alpha); - - verts.push(x + width, y + height); - verts.push(r, g, b, alpha); - - // insert 2 dead triangles.. - indices.push(vertPos, vertPos, vertPos+1, vertPos+2, vertPos+3, vertPos+3) - } - - if(graphicsData.lineWidth) - { - graphicsData.points = [x, y, - x + width, y, - x + width, y + height, - x, y + height, - x, y]; - - PIXI.WebGLGraphics.buildLine(graphicsData, webGLData); - } - -} - -/** - * Builds a circle to draw - * - * @static - * @private - * @method buildCircle - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildCircle = function(graphicsData, webGLData) -{ - // --- // - // need to convert points to a nice regular data - // - var rectData = graphicsData.points; - var x = rectData[0]; - var y = rectData[1]; - var width = rectData[2]; - var height = rectData[3]; - - var totalSegs = 40; - var seg = (Math.PI * 2) / totalSegs ; - - if(graphicsData.fill) - { - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var verts = webGLData.points; - var indices = webGLData.indices; - - var vecPos = verts.length/6; - - indices.push(vecPos); - - for (var i=0; i < totalSegs + 1 ; i++) - { - verts.push(x,y, r, g, b, alpha); - - verts.push(x + Math.sin(seg * i) * width, - y + Math.cos(seg * i) * height, - r, g, b, alpha); - - indices.push(vecPos++, vecPos++); - }; - - indices.push(vecPos-1); - } - - if(graphicsData.lineWidth) - { - graphicsData.points = []; - - for (var i=0; i < totalSegs + 1; i++) - { - graphicsData.points.push(x + Math.sin(seg * i) * width, - y + Math.cos(seg * i) * height) - }; - - PIXI.WebGLGraphics.buildLine(graphicsData, webGLData); - } - -} - -/** - * Builds a line to draw - * - * @static - * @private - * @method buildLine - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData) -{ - // TODO OPTIMISE! - - var wrap = true; - var points = graphicsData.points; - if(points.length == 0)return; - - // get first and last point.. figure out the middle! - var firstPoint = new PIXI.Point( points[0], points[1] ); - var lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] ); - - // if the first point is the last point - goona have issues :) - if(firstPoint.x == lastPoint.x && firstPoint.y == lastPoint.y) - { - points.pop(); - points.pop(); - - lastPoint = new PIXI.Point( points[points.length - 2], points[points.length - 1] ); - - var midPointX = lastPoint.x + (firstPoint.x - lastPoint.x) *0.5; - var midPointY = lastPoint.y + (firstPoint.y - lastPoint.y) *0.5; - - points.unshift(midPointX, midPointY); - points.push(midPointX, midPointY) - } - - var verts = webGLData.points; - var indices = webGLData.indices; - var length = points.length / 2; - var indexCount = points.length; - var indexStart = verts.length/6; - - // DRAW the Line - var width = graphicsData.lineWidth / 2; - - // sort color - var color = HEXtoRGB(graphicsData.lineColor); - var alpha = graphicsData.lineAlpha; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var p1x, p1y, p2x, p2y, p3x, p3y; - var perpx, perpy, perp2x, perp2y, perp3x, perp3y; - var ipx, ipy; - var a1, b1, c1, a2, b2, c2; - var denom, pdist, dist; - - p1x = points[0]; - p1y = points[1]; - - p2x = points[2]; - p2y = points[3]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - // start - verts.push(p1x - perpx , p1y - perpy, - r, g, b, alpha); - - verts.push(p1x + perpx , p1y + perpy, - r, g, b, alpha); - - for (var i = 1; i < length-1; i++) - { - p1x = points[(i-1)*2]; - p1y = points[(i-1)*2 + 1]; - - p2x = points[(i)*2] - p2y = points[(i)*2 + 1] - - p3x = points[(i+1)*2]; - p3y = points[(i+1)*2 + 1]; - - perpx = -(p1y - p2y); - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - perp2x = -(p2y - p3y); - perp2y = p2x - p3x; - - dist = Math.sqrt(perp2x*perp2x + perp2y*perp2y); - perp2x /= dist; - perp2y /= dist; - perp2x *= width; - perp2y *= width; - - a1 = (-perpy + p1y) - (-perpy + p2y); - b1 = (-perpx + p2x) - (-perpx + p1x); - c1 = (-perpx + p1x) * (-perpy + p2y) - (-perpx + p2x) * (-perpy + p1y); - a2 = (-perp2y + p3y) - (-perp2y + p2y); - b2 = (-perp2x + p2x) - (-perp2x + p3x); - c2 = (-perp2x + p3x) * (-perp2y + p2y) - (-perp2x + p2x) * (-perp2y + p3y); - - denom = a1*b2 - a2*b1; - - if (denom == 0) { - denom+=1; - } - - px = (b1*c2 - b2*c1)/denom; - py = (a2*c1 - a1*c2)/denom; - - pdist = (px -p2x) * (px -p2x) + (py -p2y) + (py -p2y); - - if(pdist > 140 * 140) - { - perp3x = perpx - perp2x; - perp3y = perpy - perp2y; - - dist = Math.sqrt(perp3x*perp3x + perp3y*perp3y); - perp3x /= dist; - perp3y /= dist; - perp3x *= width; - perp3y *= width; - - verts.push(p2x - perp3x, p2y -perp3y); - verts.push(r, g, b, alpha); - - verts.push(p2x + perp3x, p2y +perp3y); - verts.push(r, g, b, alpha); - - verts.push(p2x - perp3x, p2y -perp3y); - verts.push(r, g, b, alpha); - - indexCount++; - } - else - { - verts.push(px , py); - verts.push(r, g, b, alpha); - - verts.push(p2x - (px-p2x), p2y - (py - p2y));//, 4); - verts.push(r, g, b, alpha); - } - } - - p1x = points[(length-2)*2] - p1y = points[(length-2)*2 + 1] - - p2x = points[(length-1)*2] - p2y = points[(length-1)*2 + 1] - - perpx = -(p1y - p2y) - perpy = p1x - p2x; - - dist = Math.sqrt(perpx*perpx + perpy*perpy); - perpx /= dist; - perpy /= dist; - perpx *= width; - perpy *= width; - - verts.push(p2x - perpx , p2y - perpy) - verts.push(r, g, b, alpha); - - verts.push(p2x + perpx , p2y + perpy) - verts.push(r, g, b, alpha); - - indices.push(indexStart); - - for (var i=0; i < indexCount; i++) - { - indices.push(indexStart++); - }; - - indices.push(indexStart-1); -} - -/** - * Builds a polygon to draw - * - * @static - * @private - * @method buildPoly - * @param graphics {Graphics} - * @param webGLData {Object} - */ -PIXI.WebGLGraphics.buildPoly = function(graphicsData, webGLData) -{ - var points = graphicsData.points; - if(points.length < 6)return; - - // get first and last point.. figure out the middle! - var verts = webGLData.points; - var indices = webGLData.indices; - - var length = points.length / 2; - - // sort color - var color = HEXtoRGB(graphicsData.fillColor); - var alpha = graphicsData.fillAlpha; - var r = color[0] * alpha; - var g = color[1] * alpha; - var b = color[2] * alpha; - - var triangles = PIXI.PolyK.Triangulate(points); - - var vertPos = verts.length / 6; - - for (var i=0; i < triangles.length; i+=3) - { - indices.push(triangles[i] + vertPos); - indices.push(triangles[i] + vertPos); - indices.push(triangles[i+1] + vertPos); - indices.push(triangles[i+2] +vertPos); - indices.push(triangles[i+2] + vertPos); - }; - - for (var i = 0; i < length; i++) - { - verts.push(points[i * 2], points[i * 2 + 1], - r, g, b, alpha); - }; -} - -function HEXtoRGB(hex) { - return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; -} - - - - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI._defaultFrame = new PIXI.Rectangle(0,0,1,1); - -// an instance of the gl context.. -// only one at the moment :/ -PIXI.gl; - -/** - * the WebGLRenderer is draws the stage and all its content onto a webGL enabled canvas. This renderer - * should be used for browsers support webGL. This Render works by automatically managing webGLBatchs. - * So no need for Sprite Batch's or Sprite Cloud's - * Dont forget to add the view to your DOM or you will not see anything :) - * - * @class WebGLRenderer - * @constructor - * @param width=0 {Number} the width of the canvas view - * @param height=0 {Number} the height of the canvas view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - * - */ -PIXI.WebGLRenderer = function(width, height, view, transparent) -{ - // do a catch.. only 1 webGL renderer.. - - this.transparent = !!transparent; - - this.width = width || 800; - this.height = height || 600; - - this.view = view || document.createElement( 'canvas' ); - this.view.width = this.width; - this.view.height = this.height; - - // deal with losing context.. - var scope = this; - this.view.addEventListener('webglcontextlost', function(event) { scope.handleContextLost(event); }, false) - this.view.addEventListener('webglcontextrestored', function(event) { scope.handleContextRestored(event); }, false) - - this.batchs = []; - - try - { - PIXI.gl = this.gl = this.view.getContext("experimental-webgl", { - alpha: this.transparent, - antialias:true, // SPEED UP?? - premultipliedAlpha:false, - stencil:true - }); - } - catch (e) - { - throw new Error(" This browser does not support webGL. Try using the canvas renderer" + this); - } - - PIXI.initPrimitiveShader(); - PIXI.initDefaultShader(); - PIXI.initDefaultStripShader(); - - PIXI.activateDefaultShader(); - - var gl = this.gl; - PIXI.WebGLRenderer.gl = gl; - - this.batch = new PIXI.WebGLBatch(gl); - gl.disable(gl.DEPTH_TEST); - gl.disable(gl.CULL_FACE); - - gl.enable(gl.BLEND); - gl.colorMask(true, true, true, this.transparent); - - PIXI.projection = new PIXI.Point(400, 300); - - this.resize(this.width, this.height); - this.contextLost = false; - - this.stageRenderGroup = new PIXI.WebGLRenderGroup(this.gl); -} - -// constructor -PIXI.WebGLRenderer.prototype.constructor = PIXI.WebGLRenderer; - -/** - * Gets a new WebGLBatch from the pool - * - * @static - * @method getBatch - * @return {WebGLBatch} - * @private - */ -PIXI.WebGLRenderer.getBatch = function() -{ - if(PIXI._batchs.length == 0) - { - return new PIXI.WebGLBatch(PIXI.WebGLRenderer.gl); - } - else - { - return PIXI._batchs.pop(); - } -} - -/** - * Puts a batch back into the pool - * - * @static - * @method returnBatch - * @param batch {WebGLBatch} The batch to return - * @private - */ -PIXI.WebGLRenderer.returnBatch = function(batch) -{ - batch.clean(); - PIXI._batchs.push(batch); -} - -/** - * Renders the stage to its webGL view - * - * @method render - * @param stage {Stage} the Stage element to be rendered - */ -PIXI.WebGLRenderer.prototype.render = function(stage) -{ - if(this.contextLost)return; - - - // if rendering a new stage clear the batchs.. - if(this.__stage !== stage) - { - // TODO make this work - // dont think this is needed any more? - //if(this.__stage)this.checkVisibility(this.__stage, false) - - this.__stage = stage; - this.stageRenderGroup.setRenderable(stage); - } - - // TODO not needed now... - // update children if need be - // best to remove first! - /*for (var i=0; i < stage.__childrenRemoved.length; i++) - { - var group = stage.__childrenRemoved[i].__renderGroup - if(group)group.removeDisplayObject(stage.__childrenRemoved[i]); - }*/ - - // update any textures - PIXI.WebGLRenderer.updateTextures(); - - // recursivly loop through all items! - //this.checkVisibility(stage, true); - - // update the scene graph - stage.updateTransform(); - - var gl = this.gl; - - // -- Does this need to be set every frame? -- // - gl.colorMask(true, true, true, this.transparent); - gl.viewport(0, 0, this.width, this.height); - - // set the correct matrix.. - // gl.uniformMatrix4fv(this.shaderProgram.mvMatrixUniform, false, this.projectionMatrix); - - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - - gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], !this.transparent); - gl.clear(gl.COLOR_BUFFER_BIT); - - // HACK TO TEST - //PIXI.projectionMatrix = this.projectionMatrix; - - this.stageRenderGroup.backgroundColor = stage.backgroundColorSplit; - this.stageRenderGroup.render(PIXI.projection); - - // interaction - // run interaction! - if(stage.interactive) - { - //need to add some events! - if(!stage._interactiveEventsAdded) - { - stage._interactiveEventsAdded = true; - stage.interactionManager.setTarget(this); - } - } - - // after rendering lets confirm all frames that have been uodated.. - if(PIXI.Texture.frameUpdates.length > 0) - { - for (var i=0; i < PIXI.Texture.frameUpdates.length; i++) - { - PIXI.Texture.frameUpdates[i].updateFrame = false; - }; - - PIXI.Texture.frameUpdates = []; - } -} - -/** - * Updates the textures loaded into this webgl renderer - * - * @static - * @method updateTextures - * @private - */ -PIXI.WebGLRenderer.updateTextures = function() -{ - for (var i=0; i < PIXI.texturesToUpdate.length; i++) this.updateTexture(PIXI.texturesToUpdate[i]); - for (var i=0; i < PIXI.texturesToDestroy.length; i++) this.destroyTexture(PIXI.texturesToDestroy[i]); - PIXI.texturesToUpdate = []; - PIXI.texturesToDestroy = []; -} - -/** - * Updates a loaded webgl texture - * - * @static - * @method updateTexture - * @param texture {Texture} The texture to update - * @private - */ -PIXI.WebGLRenderer.updateTexture = function(texture) -{ - var gl = PIXI.gl; - - if(!texture._glTexture) - { - texture._glTexture = gl.createTexture(); - } - - if(texture.hasLoaded) - { - gl.bindTexture(gl.TEXTURE_2D, texture._glTexture); - gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true); - - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - - // reguler... - - if(!texture._powerOf2) - { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - } - else - { - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); - } - - gl.bindTexture(gl.TEXTURE_2D, null); - } -} - -/** - * Destroys a loaded webgl texture - * - * @method destroyTexture - * @param texture {Texture} The texture to update - * @private - */ -PIXI.WebGLRenderer.prototype.destroyTexture = function(texture) -{ - var gl = this.gl; - - if(texture._glTexture) - { - texture._glTexture = gl.createTexture(); - gl.deleteTexture(gl.TEXTURE_2D, texture._glTexture); - } -} - -/** - * resizes the webGL view to the specified width and height - * - * @method resize - * @param width {Number} the new width of the webGL view - * @param height {Number} the new height of the webGL view - */ -PIXI.WebGLRenderer.prototype.resize = function(width, height) -{ - this.width = width; - this.height = height; - - this.view.width = width; - this.view.height = height; - - this.gl.viewport(0, 0, this.width, this.height); - - //var projectionMatrix = this.projectionMatrix; - - PIXI.projection.x = this.width/2; - PIXI.projection.y = this.height/2; - -// projectionMatrix[0] = 2/this.width; -// projectionMatrix[5] = -2/this.height; -// projectionMatrix[12] = -1; -// projectionMatrix[13] = 1; -} - -/** - * Handles a lost webgl context - * - * @method handleContextLost - * @param event {Event} - * @private - */ -PIXI.WebGLRenderer.prototype.handleContextLost = function(event) -{ - event.preventDefault(); - this.contextLost = true; -} - -/** - * Handles a restored webgl context - * - * @method handleContextRestored - * @param event {Event} - * @private - */ -PIXI.WebGLRenderer.prototype.handleContextRestored = function(event) -{ - this.gl = this.view.getContext("experimental-webgl", { - alpha: true - }); - - this.initShaders(); - - for(var key in PIXI.TextureCache) - { - var texture = PIXI.TextureCache[key].baseTexture; - texture._glTexture = null; - PIXI.WebGLRenderer.updateTexture(texture); - }; - - for (var i=0; i < this.batchs.length; i++) - { - this.batchs[i].restoreLostContext(this.gl)// - this.batchs[i].dirty = true; - }; - - PIXI._restoreBatchs(this.gl); - - this.contextLost = false; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI._batchs = []; - -/** - * @private - */ -PIXI._getBatch = function(gl) -{ - if(PIXI._batchs.length == 0) - { - return new PIXI.WebGLBatch(gl); - } - else - { - return PIXI._batchs.pop(); - } -} - -/** - * @private - */ -PIXI._returnBatch = function(batch) -{ - batch.clean(); - PIXI._batchs.push(batch); -} - -/** - * @private - */ -PIXI._restoreBatchs = function(gl) -{ - for (var i=0; i < PIXI._batchs.length; i++) - { - PIXI._batchs[i].restoreLostContext(gl); - }; -} - -/** - * A WebGLBatch Enables a group of sprites to be drawn using the same settings. - * if a group of sprites all have the same baseTexture and blendMode then they can be grouped into a batch. - * All the sprites in a batch can then be drawn in one go by the GPU which is hugely efficient. ALL sprites - * in the webGL renderer are added to a batch even if the batch only contains one sprite. Batching is handled - * automatically by the webGL renderer. A good tip is: the smaller the number of batchs there are, the faster - * the webGL renderer will run. - * - * @class WebGLBatch - * @constructor - * @param gl {WebGLContext} an instance of the webGL context - */ -PIXI.WebGLBatch = function(gl) -{ - this.gl = gl; - - this.size = 0; - - this.vertexBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - this.uvBuffer = gl.createBuffer(); - this.colorBuffer = gl.createBuffer(); - this.blendMode = PIXI.blendModes.NORMAL; - this.dynamicSize = 1; -} - -// constructor -PIXI.WebGLBatch.prototype.constructor = PIXI.WebGLBatch; - -/** - * Cleans the batch so that is can be returned to an object pool and reused - * - * @method clean - */ -PIXI.WebGLBatch.prototype.clean = function() -{ - this.verticies = []; - this.uvs = []; - this.indices = []; - this.colors = []; - //this.sprites = []; - this.dynamicSize = 1; - this.texture = null; - this.last = null; - this.size = 0; - this.head; - this.tail; -} - -/** - * Recreates the buffers in the event of a context loss - * - * @method restoreLostContext - * @param gl {WebGLContext} - */ -PIXI.WebGLBatch.prototype.restoreLostContext = function(gl) -{ - this.gl = gl; - this.vertexBuffer = gl.createBuffer(); - this.indexBuffer = gl.createBuffer(); - this.uvBuffer = gl.createBuffer(); - this.colorBuffer = gl.createBuffer(); -} - -/** - * inits the batch's texture and blend mode based if the supplied sprite - * - * @method init - * @param sprite {Sprite} the first sprite to be added to the batch. Only sprites with - * the same base texture and blend mode will be allowed to be added to this batch - */ -PIXI.WebGLBatch.prototype.init = function(sprite) -{ - sprite.batch = this; - this.dirty = true; - this.blendMode = sprite.blendMode; - this.texture = sprite.texture.baseTexture; -// this.sprites.push(sprite); - this.head = sprite; - this.tail = sprite; - this.size = 1; - - this.growBatch(); -} - -/** - * inserts a sprite before the specified sprite - * - * @method insertBefore - * @param sprite {Sprite} the sprite to be added - * @param nextSprite {nextSprite} the first sprite will be inserted before this sprite - */ -PIXI.WebGLBatch.prototype.insertBefore = function(sprite, nextSprite) -{ - this.size++; - - sprite.batch = this; - this.dirty = true; - var tempPrev = nextSprite.__prev; - nextSprite.__prev = sprite; - sprite.__next = nextSprite; - - if(tempPrev) - { - sprite.__prev = tempPrev; - tempPrev.__next = sprite; - } - else - { - this.head = sprite; - //this.head.__prev = null - } -} - -/** - * inserts a sprite after the specified sprite - * - * @method insertAfter - * @param sprite {Sprite} the sprite to be added - * @param previousSprite {Sprite} the first sprite will be inserted after this sprite - */ -PIXI.WebGLBatch.prototype.insertAfter = function(sprite, previousSprite) -{ - this.size++; - - sprite.batch = this; - this.dirty = true; - - var tempNext = previousSprite.__next; - previousSprite.__next = sprite; - sprite.__prev = previousSprite; - - if(tempNext) - { - sprite.__next = tempNext; - tempNext.__prev = sprite; - } - else - { - this.tail = sprite - } -} - -/** - * removes a sprite from the batch - * - * @method remove - * @param sprite {Sprite} the sprite to be removed - */ -PIXI.WebGLBatch.prototype.remove = function(sprite) -{ - this.size--; - - if(this.size == 0) - { - sprite.batch = null; - sprite.__prev = null; - sprite.__next = null; - return; - } - - if(sprite.__prev) - { - sprite.__prev.__next = sprite.__next; - } - else - { - this.head = sprite.__next; - this.head.__prev = null; - } - - if(sprite.__next) - { - sprite.__next.__prev = sprite.__prev; - } - else - { - this.tail = sprite.__prev; - this.tail.__next = null - } - - sprite.batch = null; - sprite.__next = null; - sprite.__prev = null; - this.dirty = true; -} - -/** - * Splits the batch into two with the specified sprite being the start of the new batch. - * - * @method split - * @param sprite {Sprite} the sprite that indicates where the batch should be split - * @return {WebGLBatch} the new batch - */ -PIXI.WebGLBatch.prototype.split = function(sprite) -{ - this.dirty = true; - - var batch = new PIXI.WebGLBatch(this.gl);//PIXI._getBatch(this.gl); - batch.init(sprite); - batch.texture = this.texture; - batch.tail = this.tail; - - this.tail = sprite.__prev; - this.tail.__next = null; - - sprite.__prev = null; - // return a splite batch! - //sprite.__prev.__next = null; - //sprite.__prev = null; - - // TODO this size is wrong! - // need to recalculate :/ problem with a linked list! - // unless it gets calculated in the "clean"? - - // need to loop through items as there is no way to know the length on a linked list :/ - var tempSize = 0; - while(sprite) - { - tempSize++; - sprite.batch = batch; - sprite = sprite.__next; - } - - batch.size = tempSize; - this.size -= tempSize; - - return batch; -} - -/** - * Merges two batchs together - * - * @method merge - * @param batch {WebGLBatch} the batch that will be merged - */ -PIXI.WebGLBatch.prototype.merge = function(batch) -{ - this.dirty = true; - - this.tail.__next = batch.head; - batch.head.__prev = this.tail; - - this.size += batch.size; - - this.tail = batch.tail; - - var sprite = batch.head; - while(sprite) - { - sprite.batch = this; - sprite = sprite.__next; - } -} - -/** - * Grows the size of the batch. As the elements in the batch cannot have a dynamic size this - * function is used to increase the size of the batch. It also creates a little extra room so - * that the batch does not need to be resized every time a sprite is added - * - * @method growBatch - */ -PIXI.WebGLBatch.prototype.growBatch = function() -{ - var gl = this.gl; - if( this.size == 1) - { - this.dynamicSize = 1; - } - else - { - this.dynamicSize = this.size * 1.5 - } - // grow verts - this.verticies = new Float32Array(this.dynamicSize * 8); - - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER,this.verticies , gl.DYNAMIC_DRAW); - - this.uvs = new Float32Array( this.dynamicSize * 8 ) - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, this.uvs , gl.DYNAMIC_DRAW); - - this.dirtyUVS = true; - - this.colors = new Float32Array( this.dynamicSize * 4 ) - gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, this.colors , gl.DYNAMIC_DRAW); - - this.dirtyColors = true; - - this.indices = new Uint16Array(this.dynamicSize * 6); - var length = this.indices.length/6; - - for (var i=0; i < length; i++) - { - var index2 = i * 6; - var index3 = i * 4; - this.indices[index2 + 0] = index3 + 0; - this.indices[index2 + 1] = index3 + 1; - this.indices[index2 + 2] = index3 + 2; - this.indices[index2 + 3] = index3 + 0; - this.indices[index2 + 4] = index3 + 2; - this.indices[index2 + 5] = index3 + 3; - }; - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW); -} - -/** - * Refresh's all the data in the batch and sync's it with the webGL buffers - * - * @method refresh - */ -PIXI.WebGLBatch.prototype.refresh = function() -{ - var gl = this.gl; - - if (this.dynamicSize < this.size) - { - this.growBatch(); - } - - var indexRun = 0; - var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index; - var a, b, c, d, tx, ty; - - var displayObject = this.head; - - while(displayObject) - { - index = indexRun * 8; - - var texture = displayObject.texture; - - var frame = texture.frame; - var tw = texture.baseTexture.width; - var th = texture.baseTexture.height; - - this.uvs[index + 0] = frame.x / tw; - this.uvs[index +1] = frame.y / th; - - this.uvs[index +2] = (frame.x + frame.width) / tw; - this.uvs[index +3] = frame.y / th; - - this.uvs[index +4] = (frame.x + frame.width) / tw; - this.uvs[index +5] = (frame.y + frame.height) / th; - - this.uvs[index +6] = frame.x / tw; - this.uvs[index +7] = (frame.y + frame.height) / th; - - displayObject.updateFrame = false; - - colorIndex = indexRun * 4; - this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha; - - displayObject = displayObject.__next; - - indexRun ++; - } - - this.dirtyUVS = true; - this.dirtyColors = true; -} - -/** - * Updates all the relevant geometry and uploads the data to the GPU - * - * @method update - */ -PIXI.WebGLBatch.prototype.update = function() -{ - var gl = this.gl; - var worldTransform, width, height, aX, aY, w0, w1, h0, h1, index, index2, index3 - - var a, b, c, d, tx, ty; - - var indexRun = 0; - - var displayObject = this.head; - - while(displayObject) - { - if(displayObject.worldVisible) - { - width = displayObject.texture.frame.width; - height = displayObject.texture.frame.height; - - // TODO trim?? - aX = displayObject.anchor.x;// - displayObject.texture.trim.x - aY = displayObject.anchor.y; //- displayObject.texture.trim.y - w0 = width * (1-aX); - w1 = width * -aX; - - h0 = height * (1-aY); - h1 = height * -aY; - - index = indexRun * 8; - - worldTransform = displayObject.worldTransform; - - a = worldTransform[0]; - b = worldTransform[3]; - c = worldTransform[1]; - d = worldTransform[4]; - tx = worldTransform[2]; - ty = worldTransform[5]; - - this.verticies[index + 0 ] = a * w1 + c * h1 + tx; - this.verticies[index + 1 ] = d * h1 + b * w1 + ty; - - this.verticies[index + 2 ] = a * w0 + c * h1 + tx; - this.verticies[index + 3 ] = d * h1 + b * w0 + ty; - - this.verticies[index + 4 ] = a * w0 + c * h0 + tx; - this.verticies[index + 5 ] = d * h0 + b * w0 + ty; - - this.verticies[index + 6] = a * w1 + c * h0 + tx; - this.verticies[index + 7] = d * h0 + b * w1 + ty; - - if(displayObject.updateFrame || displayObject.texture.updateFrame) - { - this.dirtyUVS = true; - - var texture = displayObject.texture; - - var frame = texture.frame; - var tw = texture.baseTexture.width; - var th = texture.baseTexture.height; - - this.uvs[index + 0] = frame.x / tw; - this.uvs[index +1] = frame.y / th; - - this.uvs[index +2] = (frame.x + frame.width) / tw; - this.uvs[index +3] = frame.y / th; - - this.uvs[index +4] = (frame.x + frame.width) / tw; - this.uvs[index +5] = (frame.y + frame.height) / th; - - this.uvs[index +6] = frame.x / tw; - this.uvs[index +7] = (frame.y + frame.height) / th; - - displayObject.updateFrame = false; - } - - // TODO this probably could do with some optimisation.... - if(displayObject.cacheAlpha != displayObject.worldAlpha) - { - displayObject.cacheAlpha = displayObject.worldAlpha; - - var colorIndex = indexRun * 4; - this.colors[colorIndex] = this.colors[colorIndex + 1] = this.colors[colorIndex + 2] = this.colors[colorIndex + 3] = displayObject.worldAlpha; - this.dirtyColors = true; - } - } - else - { - index = indexRun * 8; - - this.verticies[index + 0 ] = 0; - this.verticies[index + 1 ] = 0; - - this.verticies[index + 2 ] = 0; - this.verticies[index + 3 ] = 0; - - this.verticies[index + 4 ] = 0; - this.verticies[index + 5 ] = 0; - - this.verticies[index + 6] = 0; - this.verticies[index + 7] = 0; - } - - indexRun++; - displayObject = displayObject.__next; - } -} - -/** - * Draws the batch to the frame buffer - * - * @method render - */ -PIXI.WebGLBatch.prototype.render = function(start, end) -{ - start = start || 0; - //end = end || this.size; - if(end == undefined)end = this.size; - - if(this.dirty) - { - this.refresh(); - this.dirty = false; - } - - if (this.size == 0)return; - - this.update(); - var gl = this.gl; - - //TODO optimize this! - - var shaderProgram = PIXI.shaderProgram; - gl.useProgram(shaderProgram); - - // update the verts.. - gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer); - // ok.. - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.verticies) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, this.uvBuffer); - - if(this.dirtyUVS) - { - this.dirtyUVS = false; - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.uvs); - } - - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, this.texture._glTexture); - - // update color! - gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer); - - if(this.dirtyColors) - { - this.dirtyColors = false; - gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.colors); - } - - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer); - - //var startIndex = 0//1; - var len = end - start; - // console.log(this.size) - // DRAW THAT this! - gl.drawElements(gl.TRIANGLES, len * 6, gl.UNSIGNED_SHORT, start * 2 * 6 ); -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * A WebGLBatch Enables a group of sprites to be drawn using the same settings. - * if a group of sprites all have the same baseTexture and blendMode then they can be - * grouped into a batch. All the sprites in a batch can then be drawn in one go by the - * GPU which is hugely efficient. ALL sprites in the webGL renderer are added to a batch - * even if the batch only contains one sprite. Batching is handled automatically by the - * webGL renderer. A good tip is: the smaller the number of batchs there are, the faster - * the webGL renderer will run. - * - * @class WebGLBatch - * @contructor - * @param gl {WebGLContext} An instance of the webGL context - */ -PIXI.WebGLRenderGroup = function(gl) -{ - this.gl = gl; - this.root; - - this.backgroundColor; - this.batchs = []; - this.toRemove = []; -} - -// constructor -PIXI.WebGLRenderGroup.prototype.constructor = PIXI.WebGLRenderGroup; - -/** - * Add a display object to the webgl renderer - * - * @method setRenderable - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.setRenderable = function(displayObject) -{ - // has this changed?? - if(this.root)this.removeDisplayObjectAndChildren(this.root); - - displayObject.worldVisible = displayObject.visible; - - // soooooo // - // to check if any batchs exist already?? - - // TODO what if its already has an object? should remove it - this.root = displayObject; - this.addDisplayObjectAndChildren(displayObject); -} - -/** - * Renders the stage to its webgl view - * - * @method render - * @param projection {Object} - */ -PIXI.WebGLRenderGroup.prototype.render = function(projection) -{ - PIXI.WebGLRenderer.updateTextures(); - - var gl = this.gl; - - - gl.uniform2f(PIXI.shaderProgram.projectionVector, projection.x, projection.y); - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - - // TODO remove this by replacing visible with getter setters.. - this.checkVisibility(this.root, this.root.visible); - - // will render all the elements in the group - var renderable; - - - for (var i=0; i < this.batchs.length; i++) - { - renderable = this.batchs[i]; - if(renderable instanceof PIXI.WebGLBatch) - { - this.batchs[i].render(); - } - else if(renderable instanceof PIXI.TilingSprite) - { - if(renderable.visible)this.renderTilingSprite(renderable, projection); - } - else if(renderable instanceof PIXI.Strip) - { - if(renderable.visible)this.renderStrip(renderable, projection); - } - else if(renderable instanceof PIXI.Graphics) - { - if(renderable.visible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable, projection);//, projectionMatrix); - } - else if(renderable instanceof PIXI.FilterBlock) - { - /* - * for now only masks are supported.. - */ - if(renderable.open) - { - gl.enable(gl.STENCIL_TEST); - - gl.colorMask(false, false, false, false); - gl.stencilFunc(gl.ALWAYS,1,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE); - - PIXI.WebGLGraphics.renderGraphics(renderable.mask, projection); - - gl.colorMask(true, true, true, false); - gl.stencilFunc(gl.NOTEQUAL,0,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); - } - else - { - gl.disable(gl.STENCIL_TEST); - } - } - } - -} - -/** - * Renders the stage to its webgl view - * - * @method handleFilter - * @param filter {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.handleFilter = function(filter, projection) -{ - -} - -/** - * Renders a specific displayObject - * - * @method renderSpecific - * @param displayObject {DisplayObject} - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderSpecific = function(displayObject, projection) -{ - PIXI.WebGLRenderer.updateTextures(); - - var gl = this.gl; - this.checkVisibility(displayObject, displayObject.visible); - -// gl.uniformMatrix4fv(PIXI.shaderProgram.mvMatrixUniform, false, projectionMatrix); - gl.uniform2f(PIXI.shaderProgram.projectionVector, projection.x, projection.y); - - // to do! - // render part of the scene... - - var startIndex; - var startBatchIndex; - - var endIndex; - var endBatchIndex; - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.first; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - var startBatch = nextRenderable.batch; - - if(nextRenderable instanceof PIXI.Sprite) - { - startBatch = nextRenderable.batch; - - var head = startBatch.head; - var next = head; - - // ok now we have the batch.. need to find the start index! - if(head == nextRenderable) - { - startIndex = 0; - } - else - { - startIndex = 1; - - while(head.__next != nextRenderable) - { - startIndex++; - head = head.__next; - } - } - } - else - { - startBatch = nextRenderable; - } - - // Get the LAST renderable object - var lastRenderable = displayObject; - var endBatch; - var lastItem = displayObject; - while(lastItem.children.length > 0) - { - lastItem = lastItem.children[lastItem.children.length-1]; - if(lastItem.renderable)lastRenderable = lastItem; - } - - if(lastRenderable instanceof PIXI.Sprite) - { - endBatch = lastRenderable.batch; - - var head = endBatch.head; - - if(head == lastRenderable) - { - endIndex = 0; - } - else - { - endIndex = 1; - - while(head.__next != lastRenderable) - { - endIndex++; - head = head.__next; - } - } - } - else - { - endBatch = lastRenderable; - } - - // TODO - need to fold this up a bit! - - if(startBatch == endBatch) - { - if(startBatch instanceof PIXI.WebGLBatch) - { - startBatch.render(startIndex, endIndex+1); - } - else - { - this.renderSpecial(startBatch, projection); - } - return; - } - - // now we have first and last! - startBatchIndex = this.batchs.indexOf(startBatch); - endBatchIndex = this.batchs.indexOf(endBatch); - - // DO the first batch - if(startBatch instanceof PIXI.WebGLBatch) - { - startBatch.render(startIndex); - } - else - { - this.renderSpecial(startBatch, projection); - } - - // DO the middle batchs.. - for (var i=startBatchIndex+1; i < endBatchIndex; i++) - { - renderable = this.batchs[i]; - - if(renderable instanceof PIXI.WebGLBatch) - { - this.batchs[i].render(); - } - else - { - this.renderSpecial(renderable, projection); - } - } - - // DO the last batch.. - if(endBatch instanceof PIXI.WebGLBatch) - { - endBatch.render(0, endIndex+1); - } - else - { - this.renderSpecial(endBatch, projection); - } -} - -/** - * Renders a specific renderable - * - * @method renderSpecial - * @param renderable {DisplayObject} - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderSpecial = function(renderable, projection) -{ - if(renderable instanceof PIXI.TilingSprite) - { - if(renderable.visible)this.renderTilingSprite(renderable, projection); - } - else if(renderable instanceof PIXI.Strip) - { - if(renderable.visible)this.renderStrip(renderable, projection); - } - else if(renderable instanceof PIXI.CustomRenderable) - { - if(renderable.visible) renderable.renderWebGL(this, projection); - } - else if(renderable instanceof PIXI.Graphics) - { - if(renderable.visible && renderable.renderable) PIXI.WebGLGraphics.renderGraphics(renderable, projection); - } - else if(renderable instanceof PIXI.FilterBlock) - { - /* - * for now only masks are supported.. - */ - - var gl = PIXI.gl; - - if(renderable.open) - { - gl.enable(gl.STENCIL_TEST); - - gl.colorMask(false, false, false, false); - gl.stencilFunc(gl.ALWAYS,1,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.REPLACE); - - PIXI.WebGLGraphics.renderGraphics(renderable.mask, projection); - - // we know this is a render texture so enable alpha too.. - gl.colorMask(true, true, true, true); - gl.stencilFunc(gl.NOTEQUAL,0,0xff); - gl.stencilOp(gl.KEEP,gl.KEEP,gl.KEEP); - } - else - { - gl.disable(gl.STENCIL_TEST); - } - } -} - -/** - * Checks the visibility of a displayObject - * - * @method checkVisibility - * @param displayObject {DisplayObject} - * @param globalVisible {Boolean} - * @private - */ -PIXI.WebGLRenderGroup.prototype.checkVisibility = function(displayObject, globalVisible) -{ - // give the dp a reference to its renderGroup... - var children = displayObject.children; - //displayObject.worldVisible = globalVisible; - for (var i=0; i < children.length; i++) - { - var child = children[i]; - - // TODO optimize... should'nt need to loop through everything all the time - child.worldVisible = child.visible && globalVisible; - - // everything should have a batch! - // time to see whats new! - if(child.textureChange) - { - child.textureChange = false; - if(child.worldVisible)this.updateTexture(child); - // update texture!! - } - - if(child.children.length > 0) - { - this.checkVisibility(child, child.worldVisible); - } - }; -} - -/** - * Updates a webgl texture - * - * @method updateTexture - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.updateTexture = function(displayObject) -{ - - // TODO definitely can optimse this function.. - - this.removeObject(displayObject); - - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - var previousRenderable = displayObject.first; - while(previousRenderable != this.root) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.last; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - - this.insertObject(displayObject, previousRenderable, nextRenderable); -} - -/** - * Adds filter blocks - * - * @method addFilterBlocks - * @param start {FilterBlock} - * @param end {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.addFilterBlocks = function(start, end) -{ - start.__renderGroup = this; - end.__renderGroup = this; - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - var previousRenderable = start; - while(previousRenderable != this.root) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - this.insertAfter(start, previousRenderable); - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var previousRenderable2 = end; - while(previousRenderable2 != this.root) - { - previousRenderable2 = previousRenderable2._iPrev; - if(previousRenderable2.renderable && previousRenderable2.__renderGroup)break; - } - this.insertAfter(end, previousRenderable2); -} - -/** - * Remove filter blocks - * - * @method removeFilterBlocks - * @param start {FilterBlock} - * @param end {FilterBlock} - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeFilterBlocks = function(start, end) -{ - this.removeObject(start); - this.removeObject(end); -} - -/** - * Adds a display object and children to the webgl context - * - * @method addDisplayObjectAndChildren - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.addDisplayObjectAndChildren = function(displayObject) -{ - if(displayObject.__renderGroup)displayObject.__renderGroup.removeDisplayObjectAndChildren(displayObject); - - /* - * LOOK FOR THE PREVIOUS RENDERABLE - * This part looks for the closest previous sprite that can go into a batch - * It keeps going back until it finds a sprite or the stage - */ - - var previousRenderable = displayObject.first; - while(previousRenderable != this.root.first) - { - previousRenderable = previousRenderable._iPrev; - if(previousRenderable.renderable && previousRenderable.__renderGroup)break; - } - - /* - * LOOK FOR THE NEXT SPRITE - * This part looks for the closest next sprite that can go into a batch - * it keeps looking until it finds a sprite or gets to the end of the display - * scene graph - */ - var nextRenderable = displayObject.last; - while(nextRenderable._iNext) - { - nextRenderable = nextRenderable._iNext; - if(nextRenderable.renderable && nextRenderable.__renderGroup)break; - } - - // one the display object hits this. we can break the loop - - var tempObject = displayObject.first; - var testObject = displayObject.last._iNext; - do - { - tempObject.__renderGroup = this; - - if(tempObject.renderable) - { - - this.insertObject(tempObject, previousRenderable, nextRenderable); - previousRenderable = tempObject; - } - - tempObject = tempObject._iNext; - } - while(tempObject != testObject) -} - -/** - * Removes a display object and children to the webgl context - * - * @method removeDisplayObjectAndChildren - * @param displayObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeDisplayObjectAndChildren = function(displayObject) -{ - if(displayObject.__renderGroup != this)return; - -// var displayObject = displayObject.first; - var lastObject = displayObject.last; - do - { - displayObject.__renderGroup = null; - if(displayObject.renderable)this.removeObject(displayObject); - displayObject = displayObject._iNext; - } - while(displayObject) -} - -/** - * Inserts a displayObject into the linked list - * - * @method insertObject - * @param displayObject {DisplayObject} - * @param previousObject {DisplayObject} - * @param nextObject {DisplayObject} - * @private - */ -PIXI.WebGLRenderGroup.prototype.insertObject = function(displayObject, previousObject, nextObject) -{ - // while looping below THE OBJECT MAY NOT HAVE BEEN ADDED - var previousSprite = previousObject; - var nextSprite = nextObject; - - /* - * so now we have the next renderable and the previous renderable - * - */ - if(displayObject instanceof PIXI.Sprite) - { - var previousBatch - var nextBatch - - if(previousSprite instanceof PIXI.Sprite) - { - previousBatch = previousSprite.batch; - if(previousBatch) - { - if(previousBatch.texture == displayObject.texture.baseTexture && previousBatch.blendMode == displayObject.blendMode) - { - previousBatch.insertAfter(displayObject, previousSprite); - return; - } - } - } - else - { - // TODO reword! - previousBatch = previousSprite; - } - - if(nextSprite) - { - if(nextSprite instanceof PIXI.Sprite) - { - nextBatch = nextSprite.batch; - - //batch may not exist if item was added to the display list but not to the webGL - if(nextBatch) - { - if(nextBatch.texture == displayObject.texture.baseTexture && nextBatch.blendMode == displayObject.blendMode) - { - nextBatch.insertBefore(displayObject, nextSprite); - return; - } - else - { - if(nextBatch == previousBatch) - { - // THERE IS A SPLIT IN THIS BATCH! // - var splitBatch = previousBatch.split(nextSprite); - // COOL! - // add it back into the array - /* - * OOPS! - * seems the new sprite is in the middle of a batch - * lets split it.. - */ - var batch = PIXI.WebGLRenderer.getBatch(); - - var index = this.batchs.indexOf( previousBatch ); - batch.init(displayObject); - this.batchs.splice(index+1, 0, batch, splitBatch); - - return; - } - } - } - } - else - { - // TODO re-word! - - nextBatch = nextSprite; - } - } - - /* - * looks like it does not belong to any batch! - * but is also not intersecting one.. - * time to create anew one! - */ - - var batch = PIXI.WebGLRenderer.getBatch(); - batch.init(displayObject); - - if(previousBatch) // if this is invalid it means - { - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, batch); - } - else - { - this.batchs.push(batch); - } - - return; - } - else if(displayObject instanceof PIXI.TilingSprite) - { - - // add to a batch!! - this.initTilingSprite(displayObject); - // this.batchs.push(displayObject); - - } - else if(displayObject instanceof PIXI.Strip) - { - // add to a batch!! - this.initStrip(displayObject); - // this.batchs.push(displayObject); - } - else if(displayObject)// instanceof PIXI.Graphics) - { - //displayObject.initWebGL(this); - - // add to a batch!! - //this.initStrip(displayObject); - //this.batchs.push(displayObject); - } - - this.insertAfter(displayObject, previousSprite); - - // insert and SPLIT! - -} - -/** - * Inserts a displayObject into the linked list - * - * @method insertAfter - * @param item {DisplayObject} - * @param displayObject {DisplayObject} The object to insert - * @private - */ -PIXI.WebGLRenderGroup.prototype.insertAfter = function(item, displayObject) -{ - if(displayObject instanceof PIXI.Sprite) - { - var previousBatch = displayObject.batch; - - if(previousBatch) - { - // so this object is in a batch! - - // is it not? need to split the batch - if(previousBatch.tail == displayObject) - { - // is it tail? insert in to batchs - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, item); - } - else - { - // TODO MODIFY ADD / REMOVE CHILD TO ACCOUNT FOR FILTERS (also get prev and next) // - - // THERE IS A SPLIT IN THIS BATCH! // - var splitBatch = previousBatch.split(displayObject.__next); - - // COOL! - // add it back into the array - /* - * OOPS! - * seems the new sprite is in the middle of a batch - * lets split it.. - */ - var index = this.batchs.indexOf( previousBatch ); - this.batchs.splice(index+1, 0, item, splitBatch); - } - } - else - { - this.batchs.push(item); - } - } - else - { - var index = this.batchs.indexOf( displayObject ); - this.batchs.splice(index+1, 0, item); - } -} - -/** - * Removes a displayObject from the linked list - * - * @method removeObject - * @param displayObject {DisplayObject} The object to remove - * @private - */ -PIXI.WebGLRenderGroup.prototype.removeObject = function(displayObject) -{ - // loop through children.. - // display object // - - // add a child from the render group.. - // remove it and all its children! - //displayObject.cacheVisible = false;//displayObject.visible; - - /* - * removing is a lot quicker.. - * - */ - var batchToRemove; - - if(displayObject instanceof PIXI.Sprite) - { - // should always have a batch! - var batch = displayObject.batch; - if(!batch)return; // this means the display list has been altered befre rendering - - batch.remove(displayObject); - - if(batch.size==0) - { - batchToRemove = batch; - } - } - else - { - batchToRemove = displayObject; - } - - /* - * Looks like there is somthing that needs removing! - */ - if(batchToRemove) - { - var index = this.batchs.indexOf( batchToRemove ); - if(index == -1)return;// this means it was added then removed before rendered - - // ok so.. check to see if you adjacent batchs should be joined. - // TODO may optimise? - if(index == 0 || index == this.batchs.length-1) - { - // wha - eva! just get of the empty batch! - this.batchs.splice(index, 1); - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - - return; - } - - if(this.batchs[index-1] instanceof PIXI.WebGLBatch && this.batchs[index+1] instanceof PIXI.WebGLBatch) - { - if(this.batchs[index-1].texture == this.batchs[index+1].texture && this.batchs[index-1].blendMode == this.batchs[index+1].blendMode) - { - //console.log("MERGE") - this.batchs[index-1].merge(this.batchs[index+1]); - - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - PIXI.WebGLRenderer.returnBatch(this.batchs[index+1]); - this.batchs.splice(index, 2); - return; - } - } - - this.batchs.splice(index, 1); - if(batchToRemove instanceof PIXI.WebGLBatch)PIXI.WebGLRenderer.returnBatch(batchToRemove); - } -} - -/** - * Initializes a tiling sprite - * - * @method initTilingSprite - * @param sprite {TilingSprite} The tiling sprite to initialize - * @private - */ -PIXI.WebGLRenderGroup.prototype.initTilingSprite = function(sprite) -{ - var gl = this.gl; - - // make the texture tilable.. - - sprite.verticies = new Float32Array([0, 0, - sprite.width, 0, - sprite.width, sprite.height, - 0, sprite.height]); - - sprite.uvs = new Float32Array([0, 0, - 1, 0, - 1, 1, - 0, 1]); - - sprite.colors = new Float32Array([1,1,1,1]); - - sprite.indices = new Uint16Array([0, 1, 3,2])//, 2]); - - sprite._vertexBuffer = gl.createBuffer(); - sprite._indexBuffer = gl.createBuffer(); - sprite._uvBuffer = gl.createBuffer(); - sprite._colorBuffer = gl.createBuffer(); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.verticies, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.uvs, gl.DYNAMIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, sprite.colors, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, sprite._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, sprite.indices, gl.STATIC_DRAW); - -// return ( (x > 0) && ((x & (x - 1)) == 0) ); - - if(sprite.texture.baseTexture._glTexture) - { - gl.bindTexture(gl.TEXTURE_2D, sprite.texture.baseTexture._glTexture); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); - sprite.texture.baseTexture._powerOf2 = true; - } - else - { - sprite.texture.baseTexture._powerOf2 = true; - } -} - -/** - * Renders a Strip - * - * @method renderStrip - * @param strip {Strip} The strip to render - * @param projection {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderStrip = function(strip, projection) -{ - var gl = this.gl; - var shaderProgram = PIXI.shaderProgram; -// mat - //var mat4Real = PIXI.mat3.toMat4(strip.worldTransform); - //PIXI.mat4.transpose(mat4Real); - //PIXI.mat4.multiply(projectionMatrix, mat4Real, mat4Real ) - - - gl.useProgram(PIXI.stripShaderProgram); - - var m = PIXI.mat3.clone(strip.worldTransform); - - PIXI.mat3.transpose(m); - - // set the matrix transform for the - gl.uniformMatrix3fv(PIXI.stripShaderProgram.translationMatrix, false, m); - gl.uniform2f(PIXI.stripShaderProgram.projectionVector, projection.x, projection.y); - gl.uniform1f(PIXI.stripShaderProgram.alpha, strip.worldAlpha); - -/* - if(strip.blendMode == PIXI.blendModes.NORMAL) - { - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - } - else - { - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR); - } - */ - - - if(!strip.dirty) - { - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferSubData(gl.ARRAY_BUFFER, 0, strip.verticies) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - } - else - { - strip.dirty = false; - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 2, gl.FLOAT, false, 0, 0); - - // update the uvs - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0); - - gl.activeTexture(gl.TEXTURE0); - gl.bindTexture(gl.TEXTURE_2D, strip.texture.baseTexture._glTexture); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW) - gl.vertexAttribPointer(shaderProgram.colorAttribute, 1, gl.FLOAT, false, 0, 0); - - // dont need to upload! - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW); - - } - //console.log(gl.TRIANGLE_STRIP); - - gl.drawElements(gl.TRIANGLE_STRIP, strip.indices.length, gl.UNSIGNED_SHORT, 0); - - gl.useProgram(PIXI.shaderProgram); -} - -/** - * Renders a TilingSprite - * - * @method renderTilingSprite - * @param sprite {TilingSprite} The tiling sprite to render - * @param projectionMatrix {Object} - * @private - */ -PIXI.WebGLRenderGroup.prototype.renderTilingSprite = function(sprite, projectionMatrix) -{ - var gl = this.gl; - var shaderProgram = PIXI.shaderProgram; - - var tilePosition = sprite.tilePosition; - var tileScale = sprite.tileScale; - - var offsetX = tilePosition.x/sprite.texture.baseTexture.width; - var offsetY = tilePosition.y/sprite.texture.baseTexture.height; - - var scaleX = (sprite.width / sprite.texture.baseTexture.width) / tileScale.x; - var scaleY = (sprite.height / sprite.texture.baseTexture.height) / tileScale.y; - - sprite.uvs[0] = 0 - offsetX; - sprite.uvs[1] = 0 - offsetY; - - sprite.uvs[2] = (1 * scaleX) -offsetX; - sprite.uvs[3] = 0 - offsetY; - - sprite.uvs[4] = (1 *scaleX) - offsetX; - sprite.uvs[5] = (1 *scaleY) - offsetY; - - sprite.uvs[6] = 0 - offsetX; - sprite.uvs[7] = (1 *scaleY) - offsetY; - - gl.bindBuffer(gl.ARRAY_BUFFER, sprite._uvBuffer); - gl.bufferSubData(gl.ARRAY_BUFFER, 0, sprite.uvs) - - this.renderStrip(sprite, projectionMatrix); -} - -/** - * Initializes a strip to be rendered - * - * @method initStrip - * @param strip {Strip} The strip to initialize - * @private - */ -PIXI.WebGLRenderGroup.prototype.initStrip = function(strip) -{ - // build the strip! - var gl = this.gl; - var shaderProgram = this.shaderProgram; - - strip._vertexBuffer = gl.createBuffer(); - strip._indexBuffer = gl.createBuffer(); - strip._uvBuffer = gl.createBuffer(); - strip._colorBuffer = gl.createBuffer(); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._vertexBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.verticies, gl.DYNAMIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._uvBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.uvs, gl.STATIC_DRAW); - - gl.bindBuffer(gl.ARRAY_BUFFER, strip._colorBuffer); - gl.bufferData(gl.ARRAY_BUFFER, strip.colors, gl.STATIC_DRAW); - - - gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, strip._indexBuffer); - gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, strip.indices, gl.STATIC_DRAW); -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * the CanvasRenderer draws the stage and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. - * Dont forget to add the view to your DOM or you will not see anything :) - * - * @class CanvasRenderer - * @constructor - * @param width=0 {Number} the width of the canvas view - * @param height=0 {Number} the height of the canvas view - * @param view {Canvas} the canvas to use as a view, optional - * @param transparent=false {Boolean} the transparency of the render view, default false - */ -PIXI.CanvasRenderer = function(width, height, view, transparent) -{ - this.transparent = transparent; - - /** - * The width of the canvas view - * - * @property width - * @type Number - * @default 800 - */ - this.width = width || 800; - - /** - * The height of the canvas view - * - * @property height - * @type Number - * @default 600 - */ - this.height = height || 600; - - /** - * The canvas element that the everything is drawn to - * - * @property view - * @type Canvas - */ - this.view = view || document.createElement( 'canvas' ); - - /** - * The canvas context that the everything is drawn to - * @property context - * @type Canvas 2d Context - */ - this.context = this.view.getContext("2d"); - - this.refresh = true; - // hack to enable some hardware acceleration! - //this.view.style["transform"] = "translatez(0)"; - - this.view.width = this.width; - this.view.height = this.height; - this.count = 0; -} - -// constructor -PIXI.CanvasRenderer.prototype.constructor = PIXI.CanvasRenderer; - -/** - * Renders the stage to its canvas view - * - * @method render - * @param stage {Stage} the Stage element to be rendered - */ -PIXI.CanvasRenderer.prototype.render = function(stage) -{ - // update children if need be - - //stage.__childrenAdded = []; - //stage.__childrenRemoved = []; - - // update textures if need be - PIXI.texturesToUpdate = []; - PIXI.texturesToDestroy = []; - - stage.updateTransform(); - - // update the background color - if(this.view.style.backgroundColor!=stage.backgroundColorString && !this.transparent)this.view.style.backgroundColor = stage.backgroundColorString; - - this.context.setTransform(1,0,0,1,0,0); - this.context.clearRect(0, 0, this.width, this.height) - this.renderDisplayObject(stage); - //as - - // run interaction! - if(stage.interactive) - { - //need to add some events! - if(!stage._interactiveEventsAdded) - { - stage._interactiveEventsAdded = true; - stage.interactionManager.setTarget(this); - } - } - - // remove frame updates.. - if(PIXI.Texture.frameUpdates.length > 0) - { - PIXI.Texture.frameUpdates = []; - } - - -} - -/** - * resizes the canvas view to the specified width and height - * - * @method resize - * @param width {Number} the new width of the canvas view - * @param height {Number} the new height of the canvas view - */ -PIXI.CanvasRenderer.prototype.resize = function(width, height) -{ - this.width = width; - this.height = height; - - this.view.width = width; - this.view.height = height; -} - -/** - * Renders a display object - * - * @method renderDisplayObject - * @param displayObject {DisplayObject} The displayObject to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject) -{ - // no loger recurrsive! - var transform; - var context = this.context; - - context.globalCompositeOperation = 'source-over'; - - // one the display object hits this. we can break the loop - var testObject = displayObject.last._iNext; - displayObject = displayObject.first; - - do - { - transform = displayObject.worldTransform; - - if(!displayObject.visible) - { - displayObject = displayObject.last._iNext; - continue; - } - - if(!displayObject.renderable) - { - displayObject = displayObject._iNext; - continue; - } - - if(displayObject instanceof PIXI.Sprite) - { - - var frame = displayObject.texture.frame; - - if(frame) - { - context.globalAlpha = displayObject.worldAlpha; - - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]); - - context.drawImage(displayObject.texture.baseTexture.source, - frame.x, - frame.y, - frame.width, - frame.height, - (displayObject.anchor.x) * -frame.width, - (displayObject.anchor.y) * -frame.height, - frame.width, - frame.height); - } - } - else if(displayObject instanceof PIXI.Strip) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - this.renderStrip(displayObject); - } - else if(displayObject instanceof PIXI.TilingSprite) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - this.renderTilingSprite(displayObject); - } - else if(displayObject instanceof PIXI.CustomRenderable) - { - displayObject.renderCanvas(this); - } - else if(displayObject instanceof PIXI.Graphics) - { - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) - PIXI.CanvasGraphics.renderGraphics(displayObject, context); - } - else if(displayObject instanceof PIXI.FilterBlock) - { - if(displayObject.open) - { - context.save(); - - var cacheAlpha = displayObject.mask.alpha; - var maskTransform = displayObject.mask.worldTransform; - - context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5]) - - displayObject.mask.worldAlpha = 0.5; - - context.worldAlpha = 0; - - PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, context); - // context.fillStyle = 0xFF0000; - // context.fillRect(0, 0, 200, 200); - context.clip(); - - displayObject.mask.worldAlpha = cacheAlpha; - //context.globalCompositeOperation = 'lighter'; - } - else - { - //context.globalCompositeOperation = 'source-over'; - context.restore(); - } - } - // count++ - displayObject = displayObject._iNext; - - - } - while(displayObject != testObject) - - -} - -/** - * Renders a flat strip - * - * @method renderStripFlat - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStripFlat = function(strip) -{ - var context = this.context; - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - - context.beginPath(); - for (var i=1; i < length-2; i++) - { - - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - - }; - - context.fillStyle = "#FF0000"; - context.fill(); - context.closePath(); -} - -/** - * Renders a tiling sprite - * - * @method renderTilingSprite - * @param sprite {TilingSprite} The tilingsprite to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderTilingSprite = function(sprite) -{ - var context = this.context; - - context.globalAlpha = sprite.worldAlpha; - - if(!sprite.__tilePattern) sprite.__tilePattern = context.createPattern(sprite.texture.baseTexture.source, "repeat"); - - context.beginPath(); - - var tilePosition = sprite.tilePosition; - var tileScale = sprite.tileScale; - - // offset - context.scale(tileScale.x,tileScale.y); - context.translate(tilePosition.x, tilePosition.y); - - context.fillStyle = sprite.__tilePattern; - context.fillRect(-tilePosition.x,-tilePosition.y,sprite.width / tileScale.x, sprite.height / tileScale.y); - - context.scale(1/tileScale.x, 1/tileScale.y); - context.translate(-tilePosition.x, -tilePosition.y); - - context.closePath(); -} - -/** - * Renders a strip - * - * @method renderStrip - * @param strip {Strip} The Strip to render - * @private - */ -PIXI.CanvasRenderer.prototype.renderStrip = function(strip) -{ - var context = this.context; - //context.globalCompositeOperation = 'lighter'; - // draw triangles!! - var verticies = strip.verticies; - var uvs = strip.uvs; - - var length = verticies.length/2; - this.count++; - for (var i=1; i < length-2; i++) - { - - // draw some triangles! - var index = i*2; - - var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; - var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; - - var u0 = uvs[index] * strip.texture.width, u1 = uvs[index+2] * strip.texture.width, u2 = uvs[index+4]* strip.texture.width; - var v0 = uvs[index+1]* strip.texture.height, v1 = uvs[index+3] * strip.texture.height, v2 = uvs[index+5]* strip.texture.height; - - - context.save(); - context.beginPath(); - context.moveTo(x0, y0); - context.lineTo(x1, y1); - context.lineTo(x2, y2); - context.closePath(); - - // context.fillStyle = "white"//rgb(1, 1, 1,1)); - // context.fill(); - context.clip(); - - - // Compute matrix transform - var delta = u0*v1 + v0*u2 + u1*v2 - v1*u2 - v0*u1 - u0*v2; - var delta_a = x0*v1 + v0*x2 + x1*v2 - v1*x2 - v0*x1 - x0*v2; - var delta_b = u0*x1 + x0*u2 + u1*x2 - x1*u2 - x0*u1 - u0*x2; - var delta_c = u0*v1*x2 + v0*x1*u2 + x0*u1*v2 - x0*v1*u2 - v0*u1*x2 - u0*x1*v2; - var delta_d = y0*v1 + v0*y2 + y1*v2 - v1*y2 - v0*y1 - y0*v2; - var delta_e = u0*y1 + y0*u2 + u1*y2 - y1*u2 - y0*u1 - u0*y2; - var delta_f = u0*v1*y2 + v0*y1*u2 + y0*u1*v2 - y0*v1*u2 - v0*u1*y2 - u0*y1*v2; - - - - - context.transform(delta_a/delta, delta_d/delta, - delta_b/delta, delta_e/delta, - delta_c/delta, delta_f/delta); - - context.drawImage(strip.texture.baseTexture.source, 0, 0); - context.restore(); - }; - -// context.globalCompositeOperation = 'source-over'; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * A set of functions used by the canvas renderer to draw the primitive graphics data - * - * @class CanvasGraphics - */ -PIXI.CanvasGraphics = function() -{ - -} - - -/* - * Renders the graphics object - * - * @static - * @private - * @method renderGraphics - * @param graphics {Graphics} - * @param context {Context2D} - */ -PIXI.CanvasGraphics.renderGraphics = function(graphics, context) -{ - var worldAlpha = graphics.worldAlpha; - - for (var i=0; i < graphics.graphicsData.length; i++) - { - var data = graphics.graphicsData[i]; - var points = data.points; - - context.strokeStyle = color = '#' + ('00000' + ( data.lineColor | 0).toString(16)).substr(-6); - - context.lineWidth = data.lineWidth; - - if(data.type == PIXI.Graphics.POLY) - { - //if(data.lineWidth <= 0)continue; - - context.beginPath(); - - context.moveTo(points[0], points[1]); - - for (var j=1; j < points.length/2; j++) - { - context.lineTo(points[j * 2], points[j * 2 + 1]); - } - - // if the first and last point are the same close the path - much neater :) - if(points[0] == points[points.length-2] && points[1] == points[points.length-1]) - { - context.closePath(); - } - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - else if(data.type == PIXI.Graphics.RECT) - { - - // TODO - need to be Undefined! - if(data.fillColor) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fillRect(points[0], points[1], points[2], points[3]); - - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.strokeRect(points[0], points[1], points[2], points[3]); - } - - } - else if(data.type == PIXI.Graphics.CIRC) - { - // TODO - need to be Undefined! - context.beginPath(); - context.arc(points[0], points[1], points[2],0,2*Math.PI); - context.closePath(); - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - else if(data.type == PIXI.Graphics.ELIP) - { - - // elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - - var elipseData = data.points; - - var w = elipseData[2] * 2; - var h = elipseData[3] * 2; - - var x = elipseData[0] - w/2; - var y = elipseData[1] - h/2; - - context.beginPath(); - - var kappa = .5522848, - ox = (w / 2) * kappa, // control point offset horizontal - oy = (h / 2) * kappa, // control point offset vertical - xe = x + w, // x-end - ye = y + h, // y-end - xm = x + w / 2, // x-middle - ym = y + h / 2; // y-middle - - context.moveTo(x, ym); - context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - - context.closePath(); - - if(data.fill) - { - context.globalAlpha = data.fillAlpha * worldAlpha; - context.fillStyle = color = '#' + ('00000' + ( data.fillColor | 0).toString(16)).substr(-6); - context.fill(); - } - if(data.lineWidth) - { - context.globalAlpha = data.lineAlpha * worldAlpha; - context.stroke(); - } - } - - }; -} - -/* - * Renders a graphics mask - * - * @static - * @private - * @method renderGraphicsMask - * @param graphics {Graphics} - * @param context {Context2D} - */ -PIXI.CanvasGraphics.renderGraphicsMask = function(graphics, context) -{ - var worldAlpha = graphics.worldAlpha; - - var len = graphics.graphicsData.length; - if(len > 1) - { - len = 1; - console.log("Pixi.js warning: masks in canvas can only mask using the first path in the graphics object") - } - - for (var i=0; i < 1; i++) - { - var data = graphics.graphicsData[i]; - var points = data.points; - - if(data.type == PIXI.Graphics.POLY) - { - //if(data.lineWidth <= 0)continue; - - context.beginPath(); - context.moveTo(points[0], points[1]); - - for (var j=1; j < points.length/2; j++) - { - context.lineTo(points[j * 2], points[j * 2 + 1]); - } - - // if the first and last point are the same close the path - much neater :) - if(points[0] == points[points.length-2] && points[1] == points[points.length-1]) - { - context.closePath(); - } - - } - else if(data.type == PIXI.Graphics.RECT) - { - context.beginPath(); - context.rect(points[0], points[1], points[2], points[3]); - context.closePath(); - } - else if(data.type == PIXI.Graphics.CIRC) - { - // TODO - need to be Undefined! - context.beginPath(); - context.arc(points[0], points[1], points[2],0,2*Math.PI); - context.closePath(); - } - else if(data.type == PIXI.Graphics.ELIP) - { - - // elipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas - var elipseData = data.points; - - var w = elipseData[2] * 2; - var h = elipseData[3] * 2; - - var x = elipseData[0] - w/2; - var y = elipseData[1] - h/2; - - context.beginPath(); - - var kappa = .5522848, - ox = (w / 2) * kappa, // control point offset horizontal - oy = (h / 2) * kappa, // control point offset vertical - xe = x + w, // x-end - ye = y + h, // y-end - xm = x + w / 2, // x-middle - ym = y + h / 2; // y-middle - - context.moveTo(x, ym); - context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - context.closePath(); - } - - - }; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * The Graphics class contains a set of methods that you can use to create primitive shapes and lines. - * It is important to know that with the webGL renderer only simple polys can be filled at this stage - * Complex polys will not be filled. Heres an example of a complex poly: http://www.goodboydigital.com/wp-content/uploads/2013/06/complexPolygon.png - * - * @class Graphics - * @extends DisplayObjectContainer - * @constructor - */ -PIXI.Graphics = function() -{ - PIXI.DisplayObjectContainer.call( this ); - - this.renderable = true; - - /** - * The alpha of the fill of this graphics object - * - * @property fillAlpha - * @type Number - */ - this.fillAlpha = 1; - - /** - * The width of any lines drawn - * - * @property lineWidth - * @type Number - */ - this.lineWidth = 0; - - /** - * The color of any lines drawn - * - * @property lineColor - * @type String - */ - this.lineColor = "black"; - - /** - * Graphics data - * - * @property graphicsData - * @type Array - * @private - */ - this.graphicsData = []; - - /** - * Current path - * - * @property currentPath - * @type Object - * @private - */ - this.currentPath = {points:[]}; -} - -// constructor -PIXI.Graphics.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Graphics.prototype.constructor = PIXI.Graphics; - -/** - * Specifies a line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method. - * - * @method lineStyle - * @param lineWidth {Number} width of the line to draw, will update the object's stored style - * @param color {Number} color of the line to draw, will update the object's stored style - * @param alpha {Number} alpha of the line to draw, will update the object's stored style - */ -PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.lineWidth = lineWidth || 0; - this.lineColor = color || 0; - this.lineAlpha = (alpha == undefined) ? 1 : alpha; - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; - - this.graphicsData.push(this.currentPath); -} - -/** - * Moves the current drawing position to (x, y). - * - * @method moveTo - * @param x {Number} the X coord to move to - * @param y {Number} the Y coord to move to - */ -PIXI.Graphics.prototype.moveTo = function(x, y) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; - - this.currentPath.points.push(x, y); - - this.graphicsData.push(this.currentPath); -} - -/** - * Draws a line using the current line style from the current drawing position to (x, y); - * the current drawing position is then set to (x, y). - * - * @method lineTo - * @param x {Number} the X coord to draw to - * @param y {Number} the Y coord to draw to - */ -PIXI.Graphics.prototype.lineTo = function(x, y) -{ - this.currentPath.points.push(x, y); - this.dirty = true; -} - -/** - * Specifies a simple one-color fill that subsequent calls to other Graphics methods - * (such as lineTo() or drawCircle()) use when drawing. - * - * @method beginFill - * @param color {uint} the color of the fill - * @param alpha {Number} the alpha - */ -PIXI.Graphics.prototype.beginFill = function(color, alpha) -{ - this.filling = true; - this.fillColor = color || 0; - this.fillAlpha = alpha || 1; -} - -/** - * Applies a fill to the lines and shapes that were added since the last call to the beginFill() method. - * - * @method endFill - */ -PIXI.Graphics.prototype.endFill = function() -{ - this.filling = false; - this.fillColor = null; - this.fillAlpha = 1; -} - -/** - * @method drawRect - * - * @param x {Number} The X coord of the top-left of the rectangle - * @param y {Number} The Y coord of the top-left of the rectangle - * @param width {Number} The width of the rectangle - * @param height {Number} The height of the rectangle - */ -PIXI.Graphics.prototype.drawRect = function( x, y, width, height ) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, width, height], type:PIXI.Graphics.RECT}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Draws a circle. - * - * @method drawCircle - * @param x {Number} The X coord of the center of the circle - * @param y {Number} The Y coord of the center of the circle - * @param radius {Number} The radius of the circle - */ -PIXI.Graphics.prototype.drawCircle = function( x, y, radius) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, radius, radius], type:PIXI.Graphics.CIRC}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Draws an elipse. - * - * @method drawElipse - * @param x {Number} - * @param y {Number} - * @param width {Number} - * @param height {Number} - */ -PIXI.Graphics.prototype.drawElipse = function( x, y, width, height) -{ - if(this.currentPath.points.length == 0)this.graphicsData.pop(); - - this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, - fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, - points:[x, y, width, height], type:PIXI.Graphics.ELIP}; - - this.graphicsData.push(this.currentPath); - this.dirty = true; -} - -/** - * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings. - * - * @method clear - */ -PIXI.Graphics.prototype.clear = function() -{ - this.lineWidth = 0; - this.filling = false; - - this.dirty = true; - this.clearDirty = true; - this.graphicsData = []; -} - -// SOME TYPES: -PIXI.Graphics.POLY = 0; -PIXI.Graphics.RECT = 1; -PIXI.Graphics.CIRC = 2; -PIXI.Graphics.ELIP = 3; - -/** - * @author Mat Groves http://matgroves.com/ - */ - -PIXI.Strip = function(texture, width, height) -{ - PIXI.DisplayObjectContainer.call( this ); - this.texture = texture; - this.blendMode = PIXI.blendModes.NORMAL; - - try - { - this.uvs = new Float32Array([0, 1, - 1, 1, - 1, 0, 0,1]); - - this.verticies = new Float32Array([0, 0, - 0,0, - 0,0, 0, - 0, 0]); - - this.colors = new Float32Array([1, 1, 1, 1]); - - this.indices = new Uint16Array([0, 1, 2, 3]); - } - catch(error) - { - this.uvs = [0, 1, - 1, 1, - 1, 0, 0,1]; - - this.verticies = [0, 0, - 0,0, - 0,0, 0, - 0, 0]; - - this.colors = [1, 1, 1, 1]; - - this.indices = [0, 1, 2, 3]; - } - - - /* - this.uvs = new Float32Array() - this.verticies = new Float32Array() - this.colors = new Float32Array() - this.indices = new Uint16Array() -*/ - this.width = width; - this.height = height; - - // load the texture! - if(texture.baseTexture.hasLoaded) - { - this.width = this.texture.frame.width; - this.height = this.texture.frame.height; - this.updateFrame = true; - } - else - { - this.onTextureUpdateBind = this.onTextureUpdate.bind(this); - this.texture.addEventListener( 'update', this.onTextureUpdateBind ); - } - - this.renderable = true; -} - -// constructor -PIXI.Strip.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Strip.prototype.constructor = PIXI.Strip; - -PIXI.Strip.prototype.setTexture = function(texture) -{ - //TODO SET THE TEXTURES - //TODO VISIBILITY - - // stop current texture - this.texture = texture; - this.width = texture.frame.width; - this.height = texture.frame.height; - this.updateFrame = true; -} - -PIXI.Strip.prototype.onTextureUpdate = function(event) -{ - this.updateFrame = true; -} -// some helper functions.. - - -/** - * @author Mat Groves http://matgroves.com/ - */ - - -PIXI.Rope = function(texture, points) -{ - PIXI.Strip.call( this, texture ); - this.points = points; - - try - { - this.verticies = new Float32Array( points.length * 4); - this.uvs = new Float32Array( points.length * 4); - this.colors = new Float32Array( points.length * 2); - this.indices = new Uint16Array( points.length * 2); - } - catch(error) - { - this.verticies = verticies - - this.uvs = uvs - this.colors = colors - this.indices = indices - } - - this.refresh(); -} - - -// constructor -PIXI.Rope.prototype = Object.create( PIXI.Strip.prototype ); -PIXI.Rope.prototype.constructor = PIXI.Rope; - -PIXI.Rope.prototype.refresh = function() -{ - var points = this.points; - if(points.length < 1)return; - - var uvs = this.uvs - var indices = this.indices; - var colors = this.colors; - - var lastPoint = points[0]; - var nextPoint; - var perp = {x:0, y:0}; - var point = points[0]; - - this.count-=0.2; - - - uvs[0] = 0 - uvs[1] = 1 - uvs[2] = 0 - uvs[3] = 1 - - colors[0] = 1; - colors[1] = 1; - - indices[0] = 0; - indices[1] = 1; - - var total = points.length; - - for (var i = 1; i < total; i++) - { - - var point = points[i]; - var index = i * 4; - // time to do some smart drawing! - var amount = i/(total-1) - - if(i%2) - { - uvs[index] = amount; - uvs[index+1] = 0; - - uvs[index+2] = amount - uvs[index+3] = 1 - - } - else - { - uvs[index] = amount - uvs[index+1] = 0 - - uvs[index+2] = amount - uvs[index+3] = 1 - } - - index = i * 2; - colors[index] = 1; - colors[index+1] = 1; - - index = i * 2; - indices[index] = index; - indices[index + 1] = index + 1; - - lastPoint = point; - } -} - -PIXI.Rope.prototype.updateTransform = function() -{ - - var points = this.points; - if(points.length < 1)return; - - var verticies = this.verticies - - var lastPoint = points[0]; - var nextPoint; - var perp = {x:0, y:0}; - var point = points[0]; - - this.count-=0.2; - - verticies[0] = point.x + perp.x - verticies[1] = point.y + perp.y //+ 200 - verticies[2] = point.x - perp.x - verticies[3] = point.y - perp.y//+200 - // time to do some smart drawing! - - var total = points.length; - - for (var i = 1; i < total; i++) - { - - var point = points[i]; - var index = i * 4; - - if(i < points.length-1) - { - nextPoint = points[i+1]; - } - else - { - nextPoint = point - } - - perp.y = -(nextPoint.x - lastPoint.x); - perp.x = nextPoint.y - lastPoint.y; - - var ratio = (1 - (i / (total-1))) * 10; - if(ratio > 1)ratio = 1; - - var perpLength = Math.sqrt(perp.x * perp.x + perp.y * perp.y); - var num = this.texture.height/2//(20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio; - perp.x /= perpLength; - perp.y /= perpLength; - - perp.x *= num; - perp.y *= num; - - verticies[index] = point.x + perp.x - verticies[index+1] = point.y + perp.y - verticies[index+2] = point.x - perp.x - verticies[index+3] = point.y - perp.y - - lastPoint = point; - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call( this ); -} - -PIXI.Rope.prototype.setTexture = function(texture) -{ - // stop current texture - this.texture = texture; - this.updateFrame = true; -} - - - - - -/** - * @author Mat Groves http://matgroves.com/ - */ - -/** - * A tiling sprite is a fast way of rendering a tiling image - * - * @class TilingSprite - * @extends DisplayObjectContainer - * @constructor - * @param texture {Texture} the texture of the tiling sprite - * @param width {Number} the width of the tiling sprite - * @param height {Number} the height of the tiling sprite - */ -PIXI.TilingSprite = function(texture, width, height) -{ - PIXI.DisplayObjectContainer.call( this ); - - /** - * The texture that the sprite is using - * - * @property texture - * @type Texture - */ - this.texture = texture; - - /** - * The width of the tiling sprite - * - * @property width - * @type Number - */ - this.width = width; - - /** - * The height of the tiling sprite - * - * @property height - * @type Number - */ - this.height = height; - - /** - * The scaling of the image that is being tiled - * - * @property tileScale - * @type Point - */ - this.tileScale = new PIXI.Point(1,1); - - /** - * The offset position of the image that is being tiled - * - * @property tilePosition - * @type Point - */ - this.tilePosition = new PIXI.Point(0,0); - - this.renderable = true; - - this.blendMode = PIXI.blendModes.NORMAL -} - -// constructor -PIXI.TilingSprite.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.TilingSprite.prototype.constructor = PIXI.TilingSprite; - -/** - * Sets the texture of the tiling sprite - * - * @method setTexture - * @param texture {Texture} The PIXI texture that is displayed by the sprite - */ -PIXI.TilingSprite.prototype.setTexture = function(texture) -{ - //TODO SET THE TEXTURES - //TODO VISIBILITY - - // stop current texture - this.texture = texture; - this.updateFrame = true; -} - -/** - * When the texture is updated, this event will fire to update the frame - * - * @method onTextureUpdate - * @param event - * @private - */ -PIXI.TilingSprite.prototype.onTextureUpdate = function(event) -{ - this.updateFrame = true; -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - * based on pixi impact spine implementation made by Eemeli Kelokorpi (@ekelokorpi) https://github.com/ekelokorpi - * - * Awesome JS run time provided by EsotericSoftware - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -/** - * A class that enables the you to import and run your spine animations in pixi. - * Spine animation data needs to be loaded using the PIXI.AssetLoader or PIXI.SpineLoader before it can be used by this class - * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source - * - * @class Spine - * @extends DisplayObjectContainer - * @constructor - * @param url {String} The url of the spine anim file to be used - */ -PIXI.Spine = function(url) -{ - PIXI.DisplayObjectContainer.call(this); - - this.spineData = PIXI.AnimCache[url]; - - if(!this.spineData) - { - throw new Error("Spine data must be preloaded using PIXI.SpineLoader or PIXI.AssetLoader: " + url); - return; - } - - this.count = 0; - - this.sprites = []; - - this.skeleton = new spine.Skeleton(this.spineData); - this.skeleton.updateWorldTransform(); - - this.stateData = new spine.AnimationStateData(this.spineData); - this.state = new spine.AnimationState(this.stateData); - - // add the sprites.. - for (var i = 0; i < this.skeleton.drawOrder.length; i++) { - - var attachmentName = this.skeleton.drawOrder[i].data.attachmentName; - - // kind of an assumtion here. that its a png - if(!PIXI.TextureCache[attachmentName]) - { - attachmentName += ".png"; - } - - - var sprite = new PIXI.Sprite(PIXI.Texture.fromFrame(attachmentName)); - sprite.anchor.x = sprite.anchor.y = 0.5; - this.addChild(sprite); - this.sprites.push(sprite); - }; -} - -PIXI.Spine.prototype = Object.create( PIXI.DisplayObjectContainer.prototype ); -PIXI.Spine.prototype.constructor = PIXI.Spine; - -/* - * Updates the object transform for rendering - * - * @method updateTransform - * @private - */ -PIXI.Spine.prototype.updateTransform = function() -{ - // TODO should make this time based really.. - this.state.update(1/60); - this.state.apply(this.skeleton); - this.skeleton.updateWorldTransform(); - - - for (var i = 0; i < this.skeleton.drawOrder.length; i++) - { - var slot = this.skeleton.drawOrder[i]; - - var x = slot.bone.worldX + slot.attachment.x * slot.bone.m00 + slot.attachment.y * slot.bone.m01 + slot.attachment.width * 0.5; - var y = slot.bone.worldY + slot.attachment.x * slot.bone.m10 + slot.attachment.y * slot.bone.m11 + slot.attachment.height * 0.5; - //console.log(x + ' : ' + y); - - - //console.log(slot.attachment.name) - if(slot.cacheName != slot.attachment.name) - { - var attachmentName = slot.attachment.name; - - if(!PIXI.TextureCache[attachmentName]) - { - attachmentName += ".png"; - } - - this.sprites[i].setTexture(PIXI.TextureCache[attachmentName]); - - slot.cacheName = slot.attachment.name; - } - - x += -((slot.attachment.width * (slot.bone.worldScaleX + slot.attachment.scaleX - 1))>>1); - y += -((slot.attachment.height * (slot.bone.worldScaleY + slot.attachment.scaleY - 1))>>1); - - - this.sprites[i].position.x = x; - this.sprites[i].position.y = y; - this.sprites[i].rotation = (-(slot.bone.worldRotation + slot.attachment.rotation)) * (Math.PI/180); - } - - PIXI.DisplayObjectContainer.prototype.updateTransform.call(this); -} - -/* - * Awesome JS run time provided by EsotericSoftware - * - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -var spine = {}; - -spine.BoneData = function (name, parent) { - this.name = name; - this.parent = parent; -}; -spine.BoneData.prototype = { - length: 0, - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1 -}; - -spine.SlotData = function (name, boneData) { - this.name = name; - this.boneData = boneData; -}; -spine.SlotData.prototype = { - r: 1, g: 1, b: 1, a: 1, - attachmentName: null -}; - -spine.Bone = function (boneData, parent) { - this.data = boneData; - this.parent = parent; - this.setToSetupPose(); -}; -spine.Bone.yDown = false; -spine.Bone.prototype = { - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1, - m00: 0, m01: 0, worldX: 0, // a b x - m10: 0, m11: 0, worldY: 0, // c d y - worldRotation: 0, - worldScaleX: 1, worldScaleY: 1, - updateWorldTransform: function (flipX, flipY) { - var parent = this.parent; - if (parent != null) { - this.worldX = this.x * parent.m00 + this.y * parent.m01 + parent.worldX; - this.worldY = this.x * parent.m10 + this.y * parent.m11 + parent.worldY; - this.worldScaleX = parent.worldScaleX * this.scaleX; - this.worldScaleY = parent.worldScaleY * this.scaleY; - this.worldRotation = parent.worldRotation + this.rotation; - } else { - this.worldX = this.x; - this.worldY = this.y; - this.worldScaleX = this.scaleX; - this.worldScaleY = this.scaleY; - this.worldRotation = this.rotation; - } - var radians = this.worldRotation * Math.PI / 180; - var cos = Math.cos(radians); - var sin = Math.sin(radians); - this.m00 = cos * this.worldScaleX; - this.m10 = sin * this.worldScaleX; - this.m01 = -sin * this.worldScaleY; - this.m11 = cos * this.worldScaleY; - if (flipX) { - this.m00 = -this.m00; - this.m01 = -this.m01; - } - if (flipY) { - this.m10 = -this.m10; - this.m11 = -this.m11; - } - if (spine.Bone.yDown) { - this.m10 = -this.m10; - this.m11 = -this.m11; - } - }, - setToSetupPose: function () { - var data = this.data; - this.x = data.x; - this.y = data.y; - this.rotation = data.rotation; - this.scaleX = data.scaleX; - this.scaleY = data.scaleY; - } -}; - -spine.Slot = function (slotData, skeleton, bone) { - this.data = slotData; - this.skeleton = skeleton; - this.bone = bone; - this.setToSetupPose(); -}; -spine.Slot.prototype = { - r: 1, g: 1, b: 1, a: 1, - _attachmentTime: 0, - attachment: null, - setAttachment: function (attachment) { - this.attachment = attachment; - this._attachmentTime = this.skeleton.time; - }, - setAttachmentTime: function (time) { - this._attachmentTime = this.skeleton.time - time; - }, - getAttachmentTime: function () { - return this.skeleton.time - this._attachmentTime; - }, - setToSetupPose: function () { - var data = this.data; - this.r = data.r; - this.g = data.g; - this.b = data.b; - this.a = data.a; - - var slotDatas = this.skeleton.data.slots; - for (var i = 0, n = slotDatas.length; i < n; i++) { - if (slotDatas[i] == data) { - this.setAttachment(!data.attachmentName ? null : this.skeleton.getAttachmentBySlotIndex(i, data.attachmentName)); - break; - } - } - } -}; - -spine.Skin = function (name) { - this.name = name; - this.attachments = {}; -}; -spine.Skin.prototype = { - addAttachment: function (slotIndex, name, attachment) { - this.attachments[slotIndex + ":" + name] = attachment; - }, - getAttachment: function (slotIndex, name) { - return this.attachments[slotIndex + ":" + name]; - }, - _attachAll: function (skeleton, oldSkin) { - for (var key in oldSkin.attachments) { - var colon = key.indexOf(":"); - var slotIndex = parseInt(key.substring(0, colon)); - var name = key.substring(colon + 1); - var slot = skeleton.slots[slotIndex]; - if (slot.attachment && slot.attachment.name == name) { - var attachment = this.getAttachment(slotIndex, name); - if (attachment) slot.setAttachment(attachment); - } - } - } -}; - -spine.Animation = function (name, timelines, duration) { - this.name = name; - this.timelines = timelines; - this.duration = duration; -}; -spine.Animation.prototype = { - apply: function (skeleton, time, loop) { - if (loop && this.duration != 0) time %= this.duration; - var timelines = this.timelines; - for (var i = 0, n = timelines.length; i < n; i++) - timelines[i].apply(skeleton, time, 1); - }, - mix: function (skeleton, time, loop, alpha) { - if (loop && this.duration != 0) time %= this.duration; - var timelines = this.timelines; - for (var i = 0, n = timelines.length; i < n; i++) - timelines[i].apply(skeleton, time, alpha); - } -}; - -spine.binarySearch = function (values, target, step) { - var low = 0; - var high = Math.floor(values.length / step) - 2; - if (high == 0) return step; - var current = high >>> 1; - while (true) { - if (values[(current + 1) * step] <= target) - low = current + 1; - else - high = current; - if (low == high) return (low + 1) * step; - current = (low + high) >>> 1; - } -}; -spine.linearSearch = function (values, target, step) { - for (var i = 0, last = values.length - step; i <= last; i += step) - if (values[i] > target) return i; - return -1; -}; - -spine.Curves = function (frameCount) { - this.curves = []; // dfx, dfy, ddfx, ddfy, dddfx, dddfy, ... - this.curves.length = (frameCount - 1) * 6; -}; -spine.Curves.prototype = { - setLinear: function (frameIndex) { - this.curves[frameIndex * 6] = 0/*LINEAR*/; - }, - setStepped: function (frameIndex) { - this.curves[frameIndex * 6] = -1/*STEPPED*/; - }, - /** Sets the control handle positions for an interpolation bezier curve used to transition from this keyframe to the next. - * cx1 and cx2 are from 0 to 1, representing the percent of time between the two keyframes. cy1 and cy2 are the percent of - * the difference between the keyframe's values. */ - setCurve: function (frameIndex, cx1, cy1, cx2, cy2) { - var subdiv_step = 1 / 10/*BEZIER_SEGMENTS*/; - var subdiv_step2 = subdiv_step * subdiv_step; - var subdiv_step3 = subdiv_step2 * subdiv_step; - var pre1 = 3 * subdiv_step; - var pre2 = 3 * subdiv_step2; - var pre4 = 6 * subdiv_step2; - var pre5 = 6 * subdiv_step3; - var tmp1x = -cx1 * 2 + cx2; - var tmp1y = -cy1 * 2 + cy2; - var tmp2x = (cx1 - cx2) * 3 + 1; - var tmp2y = (cy1 - cy2) * 3 + 1; - var i = frameIndex * 6; - var curves = this.curves; - curves[i] = cx1 * pre1 + tmp1x * pre2 + tmp2x * subdiv_step3; - curves[i + 1] = cy1 * pre1 + tmp1y * pre2 + tmp2y * subdiv_step3; - curves[i + 2] = tmp1x * pre4 + tmp2x * pre5; - curves[i + 3] = tmp1y * pre4 + tmp2y * pre5; - curves[i + 4] = tmp2x * pre5; - curves[i + 5] = tmp2y * pre5; - }, - getCurvePercent: function (frameIndex, percent) { - percent = percent < 0 ? 0 : (percent > 1 ? 1 : percent); - var curveIndex = frameIndex * 6; - var curves = this.curves; - var dfx = curves[curveIndex]; - if (!dfx/*LINEAR*/) return percent; - if (dfx == -1/*STEPPED*/) return 0; - var dfy = curves[curveIndex + 1]; - var ddfx = curves[curveIndex + 2]; - var ddfy = curves[curveIndex + 3]; - var dddfx = curves[curveIndex + 4]; - var dddfy = curves[curveIndex + 5]; - var x = dfx, y = dfy; - var i = 10/*BEZIER_SEGMENTS*/ - 2; - while (true) { - if (x >= percent) { - var lastX = x - dfx; - var lastY = y - dfy; - return lastY + (y - lastY) * (percent - lastX) / (x - lastX); - } - if (i == 0) break; - i--; - dfx += ddfx; - dfy += ddfy; - ddfx += dddfx; - ddfy += dddfy; - x += dfx; - y += dfy; - } - return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1. - } -}; - -spine.RotateTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, angle, ... - this.frames.length = frameCount * 2; -}; -spine.RotateTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, angle) { - frameIndex *= 2; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = angle; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 2]) { // Time is after last frame. - var amount = bone.data.rotation + frames[frames.length - 1] - bone.rotation; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - bone.rotation += amount * alpha; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 2); - var lastFrameValue = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex - 2/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 2 - 1, percent); - - var amount = frames[frameIndex + 1/*FRAME_VALUE*/] - lastFrameValue; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - amount = bone.data.rotation + (lastFrameValue + amount * percent) - bone.rotation; - while (amount > 180) - amount -= 360; - while (amount < -180) - amount += 360; - bone.rotation += amount * alpha; - } -}; - -spine.TranslateTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, x, y, ... - this.frames.length = frameCount * 3; -}; -spine.TranslateTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 3; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 3; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = x; - this.frames[frameIndex + 2] = y; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 3]) { // Time is after last frame. - bone.x += (bone.data.x + frames[frames.length - 2] - bone.x) * alpha; - bone.y += (bone.data.y + frames[frames.length - 1] - bone.y) * alpha; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 3); - var lastFrameX = frames[frameIndex - 2]; - var lastFrameY = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent); - bone.x += (bone.data.x + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.x) * alpha; - bone.y += (bone.data.y + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.y) * alpha; - } -}; - -spine.ScaleTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, x, y, ... - this.frames.length = frameCount * 3; -}; -spine.ScaleTimeline.prototype = { - boneIndex: 0, - getFrameCount: function () { - return this.frames.length / 3; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 3; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = x; - this.frames[frameIndex + 2] = y; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var bone = skeleton.bones[this.boneIndex]; - - if (time >= frames[frames.length - 3]) { // Time is after last frame. - bone.scaleX += (bone.data.scaleX - 1 + frames[frames.length - 2] - bone.scaleX) * alpha; - bone.scaleY += (bone.data.scaleY - 1 + frames[frames.length - 1] - bone.scaleY) * alpha; - - - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 3); - var lastFrameX = frames[frameIndex - 2]; - var lastFrameY = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex + -3/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 3 - 1, percent); - - bone.scaleX += (bone.data.scaleX - 1 + lastFrameX + (frames[frameIndex + 1/*FRAME_X*/] - lastFrameX) * percent - bone.scaleX) * alpha; - bone.scaleY += (bone.data.scaleY - 1 + lastFrameY + (frames[frameIndex + 2/*FRAME_Y*/] - lastFrameY) * percent - bone.scaleY) * alpha; - } -}; - -spine.ColorTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, r, g, b, a, ... - this.frames.length = frameCount * 5; -}; -spine.ColorTimeline.prototype = { - slotIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, x, y) { - frameIndex *= 5; - this.frames[frameIndex] = time; - this.frames[frameIndex + 1] = r; - this.frames[frameIndex + 2] = g; - this.frames[frameIndex + 3] = b; - this.frames[frameIndex + 4] = a; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - var slot = skeleton.slots[this.slotIndex]; - - if (time >= frames[frames.length - 5]) { // Time is after last frame. - var i = frames.length - 1; - slot.r = frames[i - 3]; - slot.g = frames[i - 2]; - slot.b = frames[i - 1]; - slot.a = frames[i]; - return; - } - - // Interpolate between the last frame and the current frame. - var frameIndex = spine.binarySearch(frames, time, 5); - var lastFrameR = frames[frameIndex - 4]; - var lastFrameG = frames[frameIndex - 3]; - var lastFrameB = frames[frameIndex - 2]; - var lastFrameA = frames[frameIndex - 1]; - var frameTime = frames[frameIndex]; - var percent = 1 - (time - frameTime) / (frames[frameIndex - 5/*LAST_FRAME_TIME*/] - frameTime); - percent = this.curves.getCurvePercent(frameIndex / 5 - 1, percent); - - var r = lastFrameR + (frames[frameIndex + 1/*FRAME_R*/] - lastFrameR) * percent; - var g = lastFrameG + (frames[frameIndex + 2/*FRAME_G*/] - lastFrameG) * percent; - var b = lastFrameB + (frames[frameIndex + 3/*FRAME_B*/] - lastFrameB) * percent; - var a = lastFrameA + (frames[frameIndex + 4/*FRAME_A*/] - lastFrameA) * percent; - if (alpha < 1) { - slot.r += (r - slot.r) * alpha; - slot.g += (g - slot.g) * alpha; - slot.b += (b - slot.b) * alpha; - slot.a += (a - slot.a) * alpha; - } else { - slot.r = r; - slot.g = g; - slot.b = b; - slot.a = a; - } - } -}; - -spine.AttachmentTimeline = function (frameCount) { - this.curves = new spine.Curves(frameCount); - this.frames = []; // time, ... - this.frames.length = frameCount; - this.attachmentNames = []; // time, ... - this.attachmentNames.length = frameCount; -}; -spine.AttachmentTimeline.prototype = { - slotIndex: 0, - getFrameCount: function () { - return this.frames.length / 2; - }, - setFrame: function (frameIndex, time, attachmentName) { - this.frames[frameIndex] = time; - this.attachmentNames[frameIndex] = attachmentName; - }, - apply: function (skeleton, time, alpha) { - var frames = this.frames; - if (time < frames[0]) return; // Time is before first frame. - - var frameIndex; - if (time >= frames[frames.length - 1]) // Time is after last frame. - frameIndex = frames.length - 1; - else - frameIndex = spine.binarySearch(frames, time, 1) - 1; - - var attachmentName = this.attachmentNames[frameIndex]; - //console.log(skeleton.slots[this.slotIndex]) - - // change the name! - // skeleton.slots[this.slotIndex].attachmentName = attachmentName; - - skeleton.slots[this.slotIndex].setAttachment(!attachmentName ? null : skeleton.getAttachmentBySlotIndex(this.slotIndex, attachmentName)); - } -}; - -spine.SkeletonData = function () { - this.bones = []; - this.slots = []; - this.skins = []; - this.animations = []; -}; -spine.SkeletonData.prototype = { - defaultSkin: null, - /** @return May be null. */ - findBone: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].name == boneName) return bones[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findBoneIndex: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].name == boneName) return i; - return -1; - }, - /** @return May be null. */ - findSlot: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) { - if (slots[i].name == slotName) return slot[i]; - } - return null; - }, - /** @return -1 if the bone was not found. */ - findSlotIndex: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].name == slotName) return i; - return -1; - }, - /** @return May be null. */ - findSkin: function (skinName) { - var skins = this.skins; - for (var i = 0, n = skins.length; i < n; i++) - if (skins[i].name == skinName) return skins[i]; - return null; - }, - /** @return May be null. */ - findAnimation: function (animationName) { - var animations = this.animations; - for (var i = 0, n = animations.length; i < n; i++) - if (animations[i].name == animationName) return animations[i]; - return null; - } -}; - -spine.Skeleton = function (skeletonData) { - this.data = skeletonData; - - this.bones = []; - for (var i = 0, n = skeletonData.bones.length; i < n; i++) { - var boneData = skeletonData.bones[i]; - var parent = !boneData.parent ? null : this.bones[skeletonData.bones.indexOf(boneData.parent)]; - this.bones.push(new spine.Bone(boneData, parent)); - } - - this.slots = []; - this.drawOrder = []; - for (var i = 0, n = skeletonData.slots.length; i < n; i++) { - var slotData = skeletonData.slots[i]; - var bone = this.bones[skeletonData.bones.indexOf(slotData.boneData)]; - var slot = new spine.Slot(slotData, this, bone); - this.slots.push(slot); - this.drawOrder.push(slot); - } -}; -spine.Skeleton.prototype = { - x: 0, y: 0, - skin: null, - r: 1, g: 1, b: 1, a: 1, - time: 0, - flipX: false, flipY: false, - /** Updates the world transform for each bone. */ - updateWorldTransform: function () { - var flipX = this.flipX; - var flipY = this.flipY; - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - bones[i].updateWorldTransform(flipX, flipY); - }, - /** Sets the bones and slots to their setup pose values. */ - setToSetupPose: function () { - this.setBonesToSetupPose(); - this.setSlotsToSetupPose(); - }, - setBonesToSetupPose: function () { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - bones[i].setToSetupPose(); - }, - setSlotsToSetupPose: function () { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - slots[i].setToSetupPose(i); - }, - /** @return May return null. */ - getRootBone: function () { - return this.bones.length == 0 ? null : this.bones[0]; - }, - /** @return May be null. */ - findBone: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].data.name == boneName) return bones[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findBoneIndex: function (boneName) { - var bones = this.bones; - for (var i = 0, n = bones.length; i < n; i++) - if (bones[i].data.name == boneName) return i; - return -1; - }, - /** @return May be null. */ - findSlot: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].data.name == slotName) return slots[i]; - return null; - }, - /** @return -1 if the bone was not found. */ - findSlotIndex: function (slotName) { - var slots = this.slots; - for (var i = 0, n = slots.length; i < n; i++) - if (slots[i].data.name == slotName) return i; - return -1; - }, - setSkinByName: function (skinName) { - var skin = this.data.findSkin(skinName); - if (!skin) throw "Skin not found: " + skinName; - this.setSkin(skin); - }, - /** Sets the skin used to look up attachments not found in the {@link SkeletonData#getDefaultSkin() default skin}. Attachments - * from the new skin are attached if the corresponding attachment from the old skin was attached. - * @param newSkin May be null. */ - setSkin: function (newSkin) { - if (this.skin && newSkin) newSkin._attachAll(this, this.skin); - this.skin = newSkin; - }, - /** @return May be null. */ - getAttachmentBySlotName: function (slotName, attachmentName) { - return this.getAttachmentBySlotIndex(this.data.findSlotIndex(slotName), attachmentName); - }, - /** @return May be null. */ - getAttachmentBySlotIndex: function (slotIndex, attachmentName) { - if (this.skin) { - var attachment = this.skin.getAttachment(slotIndex, attachmentName); - if (attachment) return attachment; - } - if (this.data.defaultSkin) return this.data.defaultSkin.getAttachment(slotIndex, attachmentName); - return null; - }, - /** @param attachmentName May be null. */ - setAttachment: function (slotName, attachmentName) { - var slots = this.slots; - for (var i = 0, n = slots.size; i < n; i++) { - var slot = slots[i]; - if (slot.data.name == slotName) { - var attachment = null; - if (attachmentName) { - - attachment = this.getAttachment(i, attachmentName); - if (attachment == null) throw "Attachment not found: " + attachmentName + ", for slot: " + slotName; - } - - slot.setAttachment(attachment); - return; - } - } - throw "Slot not found: " + slotName; - }, - update: function (delta) { - time += delta; - } -}; - -spine.AttachmentType = { - region: 0 -}; - -spine.RegionAttachment = function () { - this.offset = []; - this.offset.length = 8; - this.uvs = []; - this.uvs.length = 8; -}; -spine.RegionAttachment.prototype = { - x: 0, y: 0, - rotation: 0, - scaleX: 1, scaleY: 1, - width: 0, height: 0, - rendererObject: null, - regionOffsetX: 0, regionOffsetY: 0, - regionWidth: 0, regionHeight: 0, - regionOriginalWidth: 0, regionOriginalHeight: 0, - setUVs: function (u, v, u2, v2, rotate) { - var uvs = this.uvs; - if (rotate) { - uvs[2/*X2*/] = u; - uvs[3/*Y2*/] = v2; - uvs[4/*X3*/] = u; - uvs[5/*Y3*/] = v; - uvs[6/*X4*/] = u2; - uvs[7/*Y4*/] = v; - uvs[0/*X1*/] = u2; - uvs[1/*Y1*/] = v2; - } else { - uvs[0/*X1*/] = u; - uvs[1/*Y1*/] = v2; - uvs[2/*X2*/] = u; - uvs[3/*Y2*/] = v; - uvs[4/*X3*/] = u2; - uvs[5/*Y3*/] = v; - uvs[6/*X4*/] = u2; - uvs[7/*Y4*/] = v2; - } - }, - updateOffset: function () { - var regionScaleX = this.width / this.regionOriginalWidth * this.scaleX; - var regionScaleY = this.height / this.regionOriginalHeight * this.scaleY; - var localX = -this.width / 2 * this.scaleX + this.regionOffsetX * regionScaleX; - var localY = -this.height / 2 * this.scaleY + this.regionOffsetY * regionScaleY; - var localX2 = localX + this.regionWidth * regionScaleX; - var localY2 = localY + this.regionHeight * regionScaleY; - var radians = this.rotation * Math.PI / 180; - var cos = Math.cos(radians); - var sin = Math.sin(radians); - var localXCos = localX * cos + this.x; - var localXSin = localX * sin; - var localYCos = localY * cos + this.y; - var localYSin = localY * sin; - var localX2Cos = localX2 * cos + this.x; - var localX2Sin = localX2 * sin; - var localY2Cos = localY2 * cos + this.y; - var localY2Sin = localY2 * sin; - var offset = this.offset; - offset[0/*X1*/] = localXCos - localYSin; - offset[1/*Y1*/] = localYCos + localXSin; - offset[2/*X2*/] = localXCos - localY2Sin; - offset[3/*Y2*/] = localY2Cos + localXSin; - offset[4/*X3*/] = localX2Cos - localY2Sin; - offset[5/*Y3*/] = localY2Cos + localX2Sin; - offset[6/*X4*/] = localX2Cos - localYSin; - offset[7/*Y4*/] = localYCos + localX2Sin; - }, - computeVertices: function (x, y, bone, vertices) { - - x += bone.worldX; - y += bone.worldY; - var m00 = bone.m00; - var m01 = bone.m01; - var m10 = bone.m10; - var m11 = bone.m11; - var offset = this.offset; - vertices[0/*X1*/] = offset[0/*X1*/] * m00 + offset[1/*Y1*/] * m01 + x; - vertices[1/*Y1*/] = offset[0/*X1*/] * m10 + offset[1/*Y1*/] * m11 + y; - vertices[2/*X2*/] = offset[2/*X2*/] * m00 + offset[3/*Y2*/] * m01 + x; - vertices[3/*Y2*/] = offset[2/*X2*/] * m10 + offset[3/*Y2*/] * m11 + y; - vertices[4/*X3*/] = offset[4/*X3*/] * m00 + offset[5/*X3*/] * m01 + x; - vertices[5/*X3*/] = offset[4/*X3*/] * m10 + offset[5/*X3*/] * m11 + y; - vertices[6/*X4*/] = offset[6/*X4*/] * m00 + offset[7/*Y4*/] * m01 + x; - vertices[7/*Y4*/] = offset[6/*X4*/] * m10 + offset[7/*Y4*/] * m11 + y; - } -} - -spine.AnimationStateData = function (skeletonData) { - this.skeletonData = skeletonData; - this.animationToMixTime = {}; -}; -spine.AnimationStateData.prototype = { - setMixByName: function (fromName, toName, duration) { - var from = this.skeletonData.findAnimation(fromName); - if (!from) throw "Animation not found: " + fromName; - var to = this.skeletonData.findAnimation(toName); - if (!to) throw "Animation not found: " + toName; - this.setMix(from, to, duration); - }, - setMix: function (from, to, duration) { - this.animationToMixTime[from.name + ":" + to.name] = duration; - }, - getMix: function (from, to) { - var time = this.animationToMixTime[from.name + ":" + to.name]; - return time ? time : 0; - } -}; - -spine.AnimationState = function (stateData) { - this.data = stateData; - this.queue = []; -}; -spine.AnimationState.prototype = { - current: null, - previous: null, - currentTime: 0, - previousTime: 0, - currentLoop: false, - previousLoop: false, - mixTime: 0, - mixDuration: 0, - update: function (delta) { - this.currentTime += delta; - this.previousTime += delta; - this.mixTime += delta; - - if (this.queue.length > 0) { - var entry = this.queue[0]; - if (this.currentTime >= entry.delay) { - this._setAnimation(entry.animation, entry.loop); - this.queue.shift(); - } - } - }, - apply: function (skeleton) { - if (!this.current) return; - if (this.previous) { - this.previous.apply(skeleton, this.previousTime, this.previousLoop); - var alpha = this.mixTime / this.mixDuration; - if (alpha >= 1) { - alpha = 1; - this.previous = null; - } - this.current.mix(skeleton, this.currentTime, this.currentLoop, alpha); - } else - this.current.apply(skeleton, this.currentTime, this.currentLoop); - }, - clearAnimation: function () { - this.previous = null; - this.current = null; - this.queue.length = 0; - }, - _setAnimation: function (animation, loop) { - this.previous = null; - if (animation && this.current) { - this.mixDuration = this.data.getMix(this.current, animation); - if (this.mixDuration > 0) { - this.mixTime = 0; - this.previous = this.current; - this.previousTime = this.currentTime; - this.previousLoop = this.currentLoop; - } - } - this.current = animation; - this.currentLoop = loop; - this.currentTime = 0; - }, - /** @see #setAnimation(Animation, Boolean) */ - setAnimationByName: function (animationName, loop) { - var animation = this.data.skeletonData.findAnimation(animationName); - if (!animation) throw "Animation not found: " + animationName; - this.setAnimation(animation, loop); - }, - /** Set the current animation. Any queued animations are cleared and the current animation time is set to 0. - * @param animation May be null. */ - setAnimation: function (animation, loop) { - this.queue.length = 0; - this._setAnimation(animation, loop); - }, - /** @see #addAnimation(Animation, Boolean, Number) */ - addAnimationByName: function (animationName, loop, delay) { - var animation = this.data.skeletonData.findAnimation(animationName); - if (!animation) throw "Animation not found: " + animationName; - this.addAnimation(animation, loop, delay); - }, - /** Adds an animation to be played delay seconds after the current or last queued animation. - * @param delay May be <= 0 to use duration of previous animation minus any mix duration plus the negative delay. */ - addAnimation: function (animation, loop, delay) { - var entry = {}; - entry.animation = animation; - entry.loop = loop; - - if (!delay || delay <= 0) { - var previousAnimation = this.queue.length == 0 ? this.current : this.queue[this.queue.length - 1].animation; - if (previousAnimation != null) - delay = previousAnimation.duration - this.data.getMix(previousAnimation, animation) + (delay || 0); - else - delay = 0; - } - entry.delay = delay; - - this.queue.push(entry); - }, - /** Returns true if no animation is set or if the current time is greater than the animation duration, regardless of looping. */ - isComplete: function () { - return !this.current || this.currentTime >= this.current.duration; - } -}; - -spine.SkeletonJson = function (attachmentLoader) { - this.attachmentLoader = attachmentLoader; -}; -spine.SkeletonJson.prototype = { - scale: 1, - readSkeletonData: function (root) { - var skeletonData = new spine.SkeletonData(); - - // Bones. - var bones = root["bones"]; - for (var i = 0, n = bones.length; i < n; i++) { - var boneMap = bones[i]; - var parent = null; - if (boneMap["parent"]) { - parent = skeletonData.findBone(boneMap["parent"]); - if (!parent) throw "Parent bone not found: " + boneMap["parent"]; - } - var boneData = new spine.BoneData(boneMap["name"], parent); - boneData.length = (boneMap["length"] || 0) * this.scale; - boneData.x = (boneMap["x"] || 0) * this.scale; - boneData.y = (boneMap["y"] || 0) * this.scale; - boneData.rotation = (boneMap["rotation"] || 0); - boneData.scaleX = boneMap["scaleX"] || 1; - boneData.scaleY = boneMap["scaleY"] || 1; - skeletonData.bones.push(boneData); - } - - // Slots. - var slots = root["slots"]; - for (var i = 0, n = slots.length; i < n; i++) { - var slotMap = slots[i]; - var boneData = skeletonData.findBone(slotMap["bone"]); - if (!boneData) throw "Slot bone not found: " + slotMap["bone"]; - var slotData = new spine.SlotData(slotMap["name"], boneData); - - var color = slotMap["color"]; - if (color) { - slotData.r = spine.SkeletonJson.toColor(color, 0); - slotData.g = spine.SkeletonJson.toColor(color, 1); - slotData.b = spine.SkeletonJson.toColor(color, 2); - slotData.a = spine.SkeletonJson.toColor(color, 3); - } - - slotData.attachmentName = slotMap["attachment"]; - - skeletonData.slots.push(slotData); - } - - // Skins. - var skins = root["skins"]; - for (var skinName in skins) { - if (!skins.hasOwnProperty(skinName)) continue; - var skinMap = skins[skinName]; - var skin = new spine.Skin(skinName); - for (var slotName in skinMap) { - if (!skinMap.hasOwnProperty(slotName)) continue; - var slotIndex = skeletonData.findSlotIndex(slotName); - var slotEntry = skinMap[slotName]; - for (var attachmentName in slotEntry) { - if (!slotEntry.hasOwnProperty(attachmentName)) continue; - var attachment = this.readAttachment(skin, attachmentName, slotEntry[attachmentName]); - if (attachment != null) skin.addAttachment(slotIndex, attachmentName, attachment); - } - } - skeletonData.skins.push(skin); - if (skin.name == "default") skeletonData.defaultSkin = skin; - } - - // Animations. - var animations = root["animations"]; - for (var animationName in animations) { - if (!animations.hasOwnProperty(animationName)) continue; - this.readAnimation(animationName, animations[animationName], skeletonData); - } - - return skeletonData; - }, - readAttachment: function (skin, name, map) { - name = map["name"] || name; - - var type = spine.AttachmentType[map["type"] || "region"]; - - // @ekelokorpi - // var attachment = this.attachmentLoader.newAttachment(skin, type, name); - var attachment = new spine.RegionAttachment(); - - // @Doormat23 - // add the name of the attachment - attachment.name = name; - - if (type == spine.AttachmentType.region) { - attachment.x = (map["x"] || 0) * this.scale; - attachment.y = (map["y"] || 0) * this.scale; - attachment.scaleX = map["scaleX"] || 1; - attachment.scaleY = map["scaleY"] || 1; - attachment.rotation = map["rotation"] || 0; - attachment.width = (map["width"] || 32) * this.scale; - attachment.height = (map["height"] || 32) * this.scale; - attachment.updateOffset(); - } - - return attachment; - }, - readAnimation: function (name, map, skeletonData) { - var timelines = []; - var duration = 0; - - var bones = map["bones"]; - for (var boneName in bones) { - if (!bones.hasOwnProperty(boneName)) continue; - var boneIndex = skeletonData.findBoneIndex(boneName); - if (boneIndex == -1) throw "Bone not found: " + boneName; - var boneMap = bones[boneName]; - - for (var timelineName in boneMap) { - if (!boneMap.hasOwnProperty(timelineName)) continue; - var values = boneMap[timelineName]; - if (timelineName == "rotate") { - var timeline = new spine.RotateTimeline(values.length); - timeline.boneIndex = boneIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - timeline.setFrame(frameIndex, valueMap["time"], valueMap["angle"]); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 2 - 2]); - - } else if (timelineName == "translate" || timelineName == "scale") { - var timeline; - var timelineScale = 1; - if (timelineName == "scale") - timeline = new spine.ScaleTimeline(values.length); - else { - timeline = new spine.TranslateTimeline(values.length); - timelineScale = this.scale; - } - timeline.boneIndex = boneIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - var x = (valueMap["x"] || 0) * timelineScale; - var y = (valueMap["y"] || 0) * timelineScale; - timeline.setFrame(frameIndex, valueMap["time"], x, y); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 3 - 3]); - - } else - throw "Invalid timeline type for a bone: " + timelineName + " (" + boneName + ")"; - } - } - var slots = map["slots"]; - for (var slotName in slots) { - if (!slots.hasOwnProperty(slotName)) continue; - var slotMap = slots[slotName]; - var slotIndex = skeletonData.findSlotIndex(slotName); - - for (var timelineName in slotMap) { - if (!slotMap.hasOwnProperty(timelineName)) continue; - var values = slotMap[timelineName]; - if (timelineName == "color") { - var timeline = new spine.ColorTimeline(values.length); - timeline.slotIndex = slotIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - var color = valueMap["color"]; - var r = spine.SkeletonJson.toColor(color, 0); - var g = spine.SkeletonJson.toColor(color, 1); - var b = spine.SkeletonJson.toColor(color, 2); - var a = spine.SkeletonJson.toColor(color, 3); - timeline.setFrame(frameIndex, valueMap["time"], r, g, b, a); - spine.SkeletonJson.readCurve(timeline, frameIndex, valueMap); - frameIndex++; - } - timelines.push(timeline); - duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 5 - 5]); - - } else if (timelineName == "attachment") { - var timeline = new spine.AttachmentTimeline(values.length); - timeline.slotIndex = slotIndex; - - var frameIndex = 0; - for (var i = 0, n = values.length; i < n; i++) { - var valueMap = values[i]; - timeline.setFrame(frameIndex++, valueMap["time"], valueMap["name"]); - } - timelines.push(timeline); - // PIXI FIX - duration = Math.max(duration, timeline.frames[Math.floor(timeline.getFrameCount()) - 1]); - } else - throw "Invalid timeline type for a slot: " + timelineName + " (" + slotName + ")"; - } - } - skeletonData.animations.push(new spine.Animation(name, timelines, duration)); - } -}; -spine.SkeletonJson.readCurve = function (timeline, frameIndex, valueMap) { - var curve = valueMap["curve"]; - if (!curve) return; - if (curve == "stepped") - timeline.curves.setStepped(frameIndex); - else if (curve instanceof Array) - timeline.curves.setCurve(frameIndex, curve[0], curve[1], curve[2], curve[3]); -}; -spine.SkeletonJson.toColor = function (hexString, colorIndex) { - if (hexString.length != 8) throw "Color hexidecimal length must be 8, recieved: " + hexString; - return parseInt(hexString.substring(colorIndex * 2, 2), 16) / 255; -}; - -spine.Atlas = function (atlasText, textureLoader) { - this.textureLoader = textureLoader; - this.pages = []; - this.regions = []; - - var reader = new spine.AtlasReader(atlasText); - var tuple = []; - tuple.length = 4; - var page = null; - while (true) { - var line = reader.readLine(); - if (line == null) break; - line = reader.trim(line); - if (line.length == 0) - page = null; - else if (!page) { - page = new spine.AtlasPage(); - page.name = line; - - page.format = spine.Atlas.Format[reader.readValue()]; - - reader.readTuple(tuple); - page.minFilter = spine.Atlas.TextureFilter[tuple[0]]; - page.magFilter = spine.Atlas.TextureFilter[tuple[1]]; - - var direction = reader.readValue(); - page.uWrap = spine.Atlas.TextureWrap.clampToEdge; - page.vWrap = spine.Atlas.TextureWrap.clampToEdge; - if (direction == "x") - page.uWrap = spine.Atlas.TextureWrap.repeat; - else if (direction == "y") - page.vWrap = spine.Atlas.TextureWrap.repeat; - else if (direction == "xy") - page.uWrap = page.vWrap = spine.Atlas.TextureWrap.repeat; - - textureLoader.load(page, line); - - this.pages.push(page); - - } else { - var region = new spine.AtlasRegion(); - region.name = line; - region.page = page; - - region.rotate = reader.readValue() == "true"; - - reader.readTuple(tuple); - var x = parseInt(tuple[0]); - var y = parseInt(tuple[1]); - - reader.readTuple(tuple); - var width = parseInt(tuple[0]); - var height = parseInt(tuple[1]); - - region.u = x / page.width; - region.v = y / page.height; - if (region.rotate) { - region.u2 = (x + height) / page.width; - region.v2 = (y + width) / page.height; - } else { - region.u2 = (x + width) / page.width; - region.v2 = (y + height) / page.height; - } - region.x = x; - region.y = y; - region.width = Math.abs(width); - region.height = Math.abs(height); - - if (reader.readTuple(tuple) == 4) { // split is optional - region.splits = [parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])]; - - if (reader.readTuple(tuple) == 4) { // pad is optional, but only present with splits - region.pads = [parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])]; - - reader.readTuple(tuple); - } - } - - region.originalWidth = parseInt(tuple[0]); - region.originalHeight = parseInt(tuple[1]); - - reader.readTuple(tuple); - region.offsetX = parseInt(tuple[0]); - region.offsetY = parseInt(tuple[1]); - - region.index = parseInt(reader.readValue()); - - this.regions.push(region); - } - } -}; -spine.Atlas.prototype = { - findRegion: function (name) { - var regions = this.regions; - for (var i = 0, n = regions.length; i < n; i++) - if (regions[i].name == name) return regions[i]; - return null; - }, - dispose: function () { - var pages = this.pages; - for (var i = 0, n = pages.length; i < n; i++) - this.textureLoader.unload(pages[i].rendererObject); - }, - updateUVs: function (page) { - var regions = this.regions; - for (var i = 0, n = regions.length; i < n; i++) { - var region = regions[i]; - if (region.page != page) continue; - region.u = region.x / page.width; - region.v = region.y / page.height; - if (region.rotate) { - region.u2 = (region.x + region.height) / page.width; - region.v2 = (region.y + region.width) / page.height; - } else { - region.u2 = (region.x + region.width) / page.width; - region.v2 = (region.y + region.height) / page.height; - } - } - } -}; - -spine.Atlas.Format = { - alpha: 0, - intensity: 1, - luminanceAlpha: 2, - rgb565: 3, - rgba4444: 4, - rgb888: 5, - rgba8888: 6 -}; - -spine.Atlas.TextureFilter = { - nearest: 0, - linear: 1, - mipMap: 2, - mipMapNearestNearest: 3, - mipMapLinearNearest: 4, - mipMapNearestLinear: 5, - mipMapLinearLinear: 6 -}; - -spine.Atlas.TextureWrap = { - mirroredRepeat: 0, - clampToEdge: 1, - repeat: 2 -}; - -spine.AtlasPage = function () {}; -spine.AtlasPage.prototype = { - name: null, - format: null, - minFilter: null, - magFilter: null, - uWrap: null, - vWrap: null, - rendererObject: null, - width: 0, - height: 0 -}; - -spine.AtlasRegion = function () {}; -spine.AtlasRegion.prototype = { - page: null, - name: null, - x: 0, y: 0, - width: 0, height: 0, - u: 0, v: 0, u2: 0, v2: 0, - offsetX: 0, offsetY: 0, - originalWidth: 0, originalHeight: 0, - index: 0, - rotate: false, - splits: null, - pads: null, -}; - -spine.AtlasReader = function (text) { - this.lines = text.split(/\r\n|\r|\n/); -}; -spine.AtlasReader.prototype = { - index: 0, - trim: function (value) { - return value.replace(/^\s+|\s+$/g, ""); - }, - readLine: function () { - if (this.index >= this.lines.length) return null; - return this.lines[this.index++]; - }, - readValue: function () { - var line = this.readLine(); - var colon = line.indexOf(":"); - if (colon == -1) throw "Invalid line: " + line; - return this.trim(line.substring(colon + 1)); - }, - /** Returns the number of tuple values read (2 or 4). */ - readTuple: function (tuple) { - var line = this.readLine(); - var colon = line.indexOf(":"); - if (colon == -1) throw "Invalid line: " + line; - var i = 0, lastMatch= colon + 1; - for (; i < 3; i++) { - var comma = line.indexOf(",", lastMatch); - if (comma == -1) { - if (i == 0) throw "Invalid line: " + line; - break; - } - tuple[i] = this.trim(line.substr(lastMatch, comma - lastMatch)); - lastMatch = comma + 1; - } - tuple[i] = this.trim(line.substring(lastMatch)); - return i + 1; - } -} - -spine.AtlasAttachmentLoader = function (atlas) { - this.atlas = atlas; -} -spine.AtlasAttachmentLoader.prototype = { - newAttachment: function (skin, type, name) { - switch (type) { - case spine.AttachmentType.region: - var region = this.atlas.findRegion(name); - if (!region) throw "Region not found in atlas: " + name + " (" + type + ")"; - var attachment = new spine.RegionAttachment(name); - attachment.rendererObject = region; - attachment.setUVs(region.u, region.v, region.u2, region.v2, region.rotate); - attachment.regionOffsetX = region.offsetX; - attachment.regionOffsetY = region.offsetY; - attachment.regionWidth = region.width; - attachment.regionHeight = region.height; - attachment.regionOriginalWidth = region.originalWidth; - attachment.regionOriginalHeight = region.originalHeight; - return attachment; - } - throw "Unknown attachment type: " + type; - } -} - -PIXI.AnimCache = {}; -spine.Bone.yDown = true; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - -/** - * This object is one that will allow you to specify custom rendering functions based on render type - * - * @class CustomRenderable - * @extends DisplayObject - * @constructor - */ -PIXI.CustomRenderable = function() -{ - PIXI.DisplayObject.call( this ); - -} - -// constructor -PIXI.CustomRenderable.prototype = Object.create( PIXI.DisplayObject.prototype ); -PIXI.CustomRenderable.prototype.constructor = PIXI.CustomRenderable; - -/** - * If this object is being rendered by a CanvasRenderer it will call this callback - * - * @method renderCanvas - * @param renderer {CanvasRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.renderCanvas = function(renderer) -{ - // override! -} - -/** - * If this object is being rendered by a WebGLRenderer it will call this callback to initialize - * - * @method initWebGL - * @param renderer {WebGLRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.initWebGL = function(renderer) -{ - // override! -} - -/** - * If this object is being rendered by a WebGLRenderer it will call this callback - * - * @method renderWebGL - * @param renderer {WebGLRenderer} The renderer instance - */ -PIXI.CustomRenderable.prototype.renderWebGL = function(renderGroup, projectionMatrix) -{ - // not sure if both needed? but ya have for now! - // override! -} - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI.BaseTextureCache = {}; -PIXI.texturesToUpdate = []; -PIXI.texturesToDestroy = []; - -/** - * A texture stores the information that represents an image. All textures have a base texture - * - * @class BaseTexture - * @uses EventTarget - * @constructor - * @param source {String} the source object (image or canvas) - */ -PIXI.BaseTexture = function(source) -{ - PIXI.EventTarget.call( this ); - - /** - * [read-only] The width of the base texture set when the image has loaded - * - * @property width - * @type Number - * @readOnly - */ - this.width = 100; - - /** - * [read-only] The height of the base texture set when the image has loaded - * - * @property height - * @type Number - * @readOnly - */ - this.height = 100; - - /** - * [read-only] Describes if the base texture has loaded or not - * - * @property hasLoaded - * @type Boolean - * @readOnly - */ - this.hasLoaded = false; - - /** - * The source that is loaded to create the texture - * - * @property source - * @type Image - */ - this.source = source; - - if(!source)return; - - if(this.source instanceof Image || this.source instanceof HTMLImageElement) - { - if(this.source.complete) - { - this.hasLoaded = true; - this.width = this.source.width; - this.height = this.source.height; - - PIXI.texturesToUpdate.push(this); - } - else - { - - var scope = this; - this.source.onload = function(){ - - scope.hasLoaded = true; - scope.width = scope.source.width; - scope.height = scope.source.height; - - // add it to somewhere... - PIXI.texturesToUpdate.push(scope); - scope.dispatchEvent( { type: 'loaded', content: scope } ); - } - // this.image.src = imageUrl; - } - } - else - { - this.hasLoaded = true; - this.width = this.source.width; - this.height = this.source.height; - - PIXI.texturesToUpdate.push(this); - } - - this._powerOf2 = false; -} - -PIXI.BaseTexture.prototype.constructor = PIXI.BaseTexture; - -/** - * Destroys this base texture - * - * @method destroy - */ -PIXI.BaseTexture.prototype.destroy = function() -{ - if(this.source instanceof Image) - { - this.source.src = null; - } - this.source = null; - PIXI.texturesToDestroy.push(this); -} - -/** - * Helper function that returns a base texture based on an image url - * If the image is not in the base texture cache it will be created and loaded - * - * @static - * @method fromImage - * @param imageUrl {String} The image url of the texture - * @return BaseTexture - */ -PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin) -{ - var baseTexture = PIXI.BaseTextureCache[imageUrl]; - if(!baseTexture) - { - // new Image() breaks tex loading in some versions of Chrome. - // See https://code.google.com/p/chromium/issues/detail?id=238071 - var image = new Image();//document.createElement('img'); - if (crossorigin) - { - image.crossOrigin = ''; - } - image.src = imageUrl; - baseTexture = new PIXI.BaseTexture(image); - PIXI.BaseTextureCache[imageUrl] = baseTexture; - } - - return baseTexture; -} - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -PIXI.TextureCache = {}; -PIXI.FrameCache = {}; - -/** - * A texture stores the information that represents an image or part of an image. It cannot be added - * to the display list directly. To do this use PIXI.Sprite. If no frame is provided then the whole image is used - * - * @class Texture - * @uses EventTarget - * @constructor - * @param baseTexture {BaseTexture} The base texture source to create the texture from - * @param frmae {Rectangle} The rectangle frame of the texture to show - */ -PIXI.Texture = function(baseTexture, frame) -{ - PIXI.EventTarget.call( this ); - - if(!frame) - { - this.noFrame = true; - frame = new PIXI.Rectangle(0,0,1,1); - } - - if(baseTexture instanceof PIXI.Texture) - baseTexture = baseTexture.baseTexture; - - /** - * The base texture of this texture - * - * @property baseTexture - * @type BaseTexture - */ - this.baseTexture = baseTexture; - - /** - * The frame specifies the region of the base texture that this texture uses - * - * @property frame - * @type Rectangle - */ - this.frame = frame; - - /** - * The trim point - * - * @property trim - * @type Point - */ - this.trim = new PIXI.Point(); - - this.scope = this; - - if(baseTexture.hasLoaded) - { - if(this.noFrame)frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); - //console.log(frame) - - this.setFrame(frame); - } - else - { - var scope = this; - baseTexture.addEventListener( 'loaded', function(){ scope.onBaseTextureLoaded()} ); - } -} - -PIXI.Texture.prototype.constructor = PIXI.Texture; - -/** - * Called when the base texture is loaded - * - * @method onBaseTextureLoaded - * @param event - * @private - */ -PIXI.Texture.prototype.onBaseTextureLoaded = function(event) -{ - var baseTexture = this.baseTexture; - baseTexture.removeEventListener( 'loaded', this.onLoaded ); - - if(this.noFrame)this.frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height); - this.noFrame = false; - this.width = this.frame.width; - this.height = this.frame.height; - - this.scope.dispatchEvent( { type: 'update', content: this } ); -} - -/** - * Destroys this texture - * - * @method destroy - * @param destroyBase {Boolean} Whether to destroy the base texture as well - */ -PIXI.Texture.prototype.destroy = function(destroyBase) -{ - if(destroyBase)this.baseTexture.destroy(); -} - -/** - * Specifies the rectangle region of the baseTexture - * - * @method setFrame - * @param frame {Rectangle} The frame of the texture to set it to - */ -PIXI.Texture.prototype.setFrame = function(frame) -{ - this.frame = frame; - this.width = frame.width; - this.height = frame.height; - - if(frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error("Texture Error: frame does not fit inside the base Texture dimensions " + this); - } - - this.updateFrame = true; - - PIXI.Texture.frameUpdates.push(this); - //this.dispatchEvent( { type: 'update', content: this } ); -} - -/** - * Helper function that returns a texture based on an image url - * If the image is not in the texture cache it will be created and loaded - * - * @static - * @method fromImage - * @param imageUrl {String} The image url of the texture - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - * @return Texture - */ -PIXI.Texture.fromImage = function(imageUrl, crossorigin) -{ - var texture = PIXI.TextureCache[imageUrl]; - - if(!texture) - { - texture = new PIXI.Texture(PIXI.BaseTexture.fromImage(imageUrl, crossorigin)); - PIXI.TextureCache[imageUrl] = texture; - } - - return texture; -} - -/** - * Helper function that returns a texture based on a frame id - * If the frame id is not in the texture cache an error will be thrown - * - * @static - * @method fromFrame - * @param frameId {String} The frame id of the texture - * @return Texture - */ -PIXI.Texture.fromFrame = function(frameId) -{ - var texture = PIXI.TextureCache[frameId]; - if(!texture)throw new Error("The frameId '"+ frameId +"' does not exist in the texture cache " + this); - return texture; -} - -/** - * Helper function that returns a texture based on a canvas element - * If the canvas is not in the texture cache it will be created and loaded - * - * @static - * @method fromCanvas - * @param canvas {Canvas} The canvas element source of the texture - * @return Texture - */ -PIXI.Texture.fromCanvas = function(canvas) -{ - var baseTexture = new PIXI.BaseTexture(canvas); - return new PIXI.Texture(baseTexture); -} - - -/** - * Adds a texture to the textureCache. - * - * @static - * @method addTextureToCache - * @param texture {Texture} - * @param id {String} the id that the texture will be stored against. - */ -PIXI.Texture.addTextureToCache = function(texture, id) -{ - PIXI.TextureCache[id] = texture; -} - -/** - * Remove a texture from the textureCache. - * - * @static - * @method removeTextureFromCache - * @param id {String} the id of the texture to be removed - * @return {Texture} the texture that was removed - */ -PIXI.Texture.removeTextureFromCache = function(id) -{ - var texture = PIXI.TextureCache[id] - PIXI.TextureCache[id] = null; - return texture; -} - -// this is more for webGL.. it contains updated frames.. -PIXI.Texture.frameUpdates = []; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - A RenderTexture is a special texture that allows any pixi displayObject to be rendered to it. - - __Hint__: All DisplayObjects (exmpl. Sprites) that renders on RenderTexture should be preloaded. - Otherwise black rectangles will be drawn instead. - - RenderTexture takes snapshot of DisplayObject passed to render method. If DisplayObject is passed to render method, position and rotation of it will be ignored. For example: - - var renderTexture = new PIXI.RenderTexture(800, 600); - var sprite = PIXI.Sprite.fromImage("spinObj_01.png"); - sprite.position.x = 800/2; - sprite.position.y = 600/2; - sprite.anchor.x = 0.5; - sprite.anchor.y = 0.5; - renderTexture.render(sprite); - - Sprite in this case will be rendered to 0,0 position. To render this sprite at center DisplayObjectContainer should be used: - - var doc = new PIXI.DisplayObjectContainer(); - doc.addChild(sprite); - renderTexture.render(doc); // Renders to center of renderTexture - - @class RenderTexture - @extends Texture - @constructor - @param width {Number} The width of the render texture - @param height {Number} The height of the render texture - */ -PIXI.RenderTexture = function(width, height) -{ - PIXI.EventTarget.call( this ); - - this.width = width || 100; - this.height = height || 100; - - this.indetityMatrix = PIXI.mat3.create(); - - this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); - - if(PIXI.gl) - { - this.initWebGL(); - } - else - { - this.initCanvas(); - } -} - -PIXI.RenderTexture.prototype = Object.create( PIXI.Texture.prototype ); -PIXI.RenderTexture.prototype.constructor = PIXI.RenderTexture; - -/** - * Initializes the webgl data for this texture - * - * @method initWebGL - * @private - */ -PIXI.RenderTexture.prototype.initWebGL = function() -{ - var gl = PIXI.gl; - this.glFramebuffer = gl.createFramebuffer(); - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - - this.glFramebuffer.width = this.width; - this.glFramebuffer.height = this.height; - - this.baseTexture = new PIXI.BaseTexture(); - - this.baseTexture.width = this.width; - this.baseTexture.height = this.height; - - this.baseTexture._glTexture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); - - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - - this.baseTexture.isRender = true; - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0); - - // create a projection matrix.. - this.projection = new PIXI.Point(this.width/2 , this.height/2); -/* - this.projectionMatrix = PIXI.mat4.create(); - - this.projectionMatrix[5] = 2/this.height// * 0.5; - this.projectionMatrix[13] = -1; - - this.projectionMatrix[0] = 2/this.width; - this.projectionMatrix[12] = -1; -*/ - // set the correct render function.. - this.render = this.renderWebGL; - - -} - - -PIXI.RenderTexture.prototype.resize = function(width, height) -{ - - this.width = width; - this.height = height; - - //this.frame.width = this.width - //this.frame.height = this.height; - - - if(PIXI.gl) - { - this.projection.x = this.width/2 - this.projection.y = this.height/2; - - var gl = PIXI.gl; - gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - } - else - { - - this.frame.width = this.width - this.frame.height = this.height; - this.renderer.resize(this.width, this.height); - } -} - -/** - * Initializes the canvas data for this texture - * - * @method initCanvas - * @private - */ -PIXI.RenderTexture.prototype.initCanvas = function() -{ - this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, 0); - - this.baseTexture = new PIXI.BaseTexture(this.renderer.view); - this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); - - this.render = this.renderCanvas; -} - -/** - * This function will draw the display object to the texture. - * - * @method renderWebGL - * @param displayObject {DisplayObject} The display object to render this texture on - * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn - * @private - */ -PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear) -{ - var gl = PIXI.gl; - - // enable the alpha color mask.. - gl.colorMask(true, true, true, true); - - gl.viewport(0, 0, this.width, this.height); - - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - - if(clear) - { - gl.clearColor(0,0,0, 0); - gl.clear(gl.COLOR_BUFFER_BIT); - } - - // THIS WILL MESS WITH HIT TESTING! - var children = displayObject.children; - - //TODO -? create a new one??? dont think so! - displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix; - // modify to flip... - displayObject.worldTransform[4] = -1; - displayObject.worldTransform[5] = this.projection.y * 2; - - - if(position) - { - displayObject.worldTransform[2] = position.x; - displayObject.worldTransform[5] -= position.y; - } - - - - for(var i=0,j=children.length; i} assetURLs an array of image/sprite sheet urls that you would like loaded - * supported. Supported image formats include "jpeg", "jpg", "png", "gif". Supported - * sprite sheet data formats only include "JSON" at this time. Supported bitmap font - * data formats include "xml" and "fnt". - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.AssetLoader = function(assetURLs, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The array of asset URLs that are going to be loaded - * - * @property assetURLs - * @type Array - */ - this.assetURLs = assetURLs; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * Maps file extension to loader types - * - * @property loadersByType - * @type Object - */ - this.loadersByType = { - "jpg": PIXI.ImageLoader, - "jpeg": PIXI.ImageLoader, - "png": PIXI.ImageLoader, - "gif": PIXI.ImageLoader, - "json": PIXI.JsonLoader, - "anim": PIXI.SpineLoader, - "xml": PIXI.BitmapFontLoader, - "fnt": PIXI.BitmapFontLoader - }; - - -}; - -/** - * Fired when an item has loaded - * @event onProgress - */ - -/** - * Fired when all the assets have loaded - * @event onComplete - */ - -// constructor -PIXI.AssetLoader.prototype.constructor = PIXI.AssetLoader; - -/** - * Starts loading the assets sequentially - * - * @method load - */ -PIXI.AssetLoader.prototype.load = function() -{ - var scope = this; - - this.loadCount = this.assetURLs.length; - - for (var i=0; i < this.assetURLs.length; i++) - { - var fileName = this.assetURLs[i]; - var fileType = fileName.split(".").pop().toLowerCase(); - - var loaderClass = this.loadersByType[fileType]; - if(!loaderClass) - throw new Error(fileType + " is an unsupported file type"); - - var loader = new loaderClass(fileName, this.crossorigin); - - loader.addEventListener("loaded", function() - { - scope.onAssetLoaded(); - }); - loader.load(); - } -}; - -/** - * Invoked after each file is loaded - * - * @method onAssetLoaded - * @private - */ -PIXI.AssetLoader.prototype.onAssetLoaded = function() -{ - this.loadCount--; - this.dispatchEvent({type: "onProgress", content: this}); - if(this.onProgress) this.onProgress(); - - if(this.loadCount == 0) - { - this.dispatchEvent({type: "onComplete", content: this}); - if(this.onComplete) this.onComplete(); - } -}; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The json file loader is used to load in JSON data and parsing it - * When loaded this class will dispatch a "loaded" event - * If load failed this class will dispatch a "error" event - * - * @class JsonLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.JsonLoader = function (url, crossorigin) { - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * [read-only] Whether the data has loaded yet - * - * @property loaded - * @type Boolean - * @readOnly - */ - this.loaded = false; - -}; - -// constructor -PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader; - -/** - * Loads the JSON data - * - * @method load - */ -PIXI.JsonLoader.prototype.load = function () { - this.ajaxRequest = new AjaxRequest(); - var scope = this; - this.ajaxRequest.onreadystatechange = function () { - scope.onJSONLoaded(); - }; - - this.ajaxRequest.open("GET", this.url, true); - if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json"); - this.ajaxRequest.send(null); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.JsonLoader.prototype.onJSONLoaded = function () { - if (this.ajaxRequest.readyState == 4) { - if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) { - this.json = JSON.parse(this.ajaxRequest.responseText); - - if(this.json.frames) - { - // sprite sheet - var scope = this; - var textureUrl = this.baseUrl + this.json.meta.image; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - var frameData = this.json.frames; - - this.texture = image.texture.baseTexture; - image.addEventListener("loaded", function (event) { - scope.onLoaded(); - }); - - for (var i in frameData) { - var rect = frameData[i].frame; - if (rect) { - PIXI.TextureCache[i] = new PIXI.Texture(this.texture, { - x: rect.x, - y: rect.y, - width: rect.w, - height: rect.h - }); - if (frameData[i].trimmed) { - //var realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w) - // calculate the offset! - } - } - } - - image.load(); - - } - else if(this.json.bones) - { - // spine animation - var spineJsonParser = new spine.SkeletonJson(); - var skeletonData = spineJsonParser.readSkeletonData(this.json); - PIXI.AnimCache[this.url] = skeletonData; - this.onLoaded(); - } - else - { - this.onLoaded(); - } - } - else - { - this.onError(); - } - } -}; - -/** - * Invoke when json file loaded - * - * @method onLoaded - * @private - */ -PIXI.JsonLoader.prototype.onLoaded = function () { - this.loaded = true; - this.dispatchEvent({ - type: "loaded", - content: this - }); -}; - -/** - * Invoke when error occured - * - * @method onError - * @private - */ -PIXI.JsonLoader.prototype.onError = function () { - this.dispatchEvent({ - type: "error", - content: this - }); -}; -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The sprite sheet loader is used to load in JSON sprite sheet data - * To generate the data you can use http://www.codeandweb.com/texturepacker and publish the "JSON" format - * There is a free version so thats nice, although the paid version is great value for money. - * It is highly recommended to use Sprite sheets (also know as texture atlas") as it means sprite"s can be batched and drawn together for highly increased rendering speed. - * Once the data has been loaded the frames are stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId() - * This loader will also load the image file that the Spritesheet points to as well as the data. - * When loaded this class will dispatch a "loaded" event - * - * @class SpriteSheetLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the sprite sheet JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ - -PIXI.SpriteSheetLoader = function (url, crossorigin) { - /* - * i use texture packer to load the assets.. - * http://www.codeandweb.com/texturepacker - * make sure to set the format as "JSON" - */ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * The texture being loaded - * - * @property texture - * @type Texture - */ - this.texture = null; - - /** - * The frames of the sprite sheet - * - * @property frames - * @type Object - */ - this.frames = {}; -}; - -// constructor -PIXI.SpriteSheetLoader.prototype.constructor = PIXI.SpriteSheetLoader; - -/** - * This will begin loading the JSON file - * - * @method load - */ -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; - scope.onJSONLoaded(); - }); - jsonLoader.load(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () { - var scope = this; - var textureUrl = this.baseUrl + this.json.meta.image; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - var frameData = this.json.frames; - - this.texture = image.texture.baseTexture; - image.addEventListener("loaded", function (event) { - scope.onLoaded(); - }); - - for (var i in frameData) { - var rect = frameData[i].frame; - if (rect) { - PIXI.TextureCache[i] = new PIXI.Texture(this.texture, { - x: rect.x, - y: rect.y, - width: rect.w, - height: rect.h - }); - if (frameData[i].trimmed) { - //var realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; - PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w) - // calculate the offset! - } - } - } - - image.load(); -}; -/** - * Invoke when all files are loaded (json and texture) - * - * @method onLoaded - * @private - */ -PIXI.SpriteSheetLoader.prototype.onLoaded = function () { - this.dispatchEvent({ - type: "loaded", - content: this - }); -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The image loader class is responsible for loading images file formats ("jpeg", "jpg", "png" and "gif") - * Once the image has been loaded it is stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId() - * When loaded this class will dispatch a 'loaded' event - * - * @class ImageLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the image - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.ImageLoader = function(url, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The texture being loaded - * - * @property texture - * @type Texture - */ - this.texture = PIXI.Texture.fromImage(url, crossorigin); -}; - -// constructor -PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader; - -/** - * Loads image or takes it from cache - * - * @method load - */ -PIXI.ImageLoader.prototype.load = function() -{ - if(!this.texture.baseTexture.hasLoaded) - { - var scope = this; - this.texture.baseTexture.addEventListener("loaded", function() - { - scope.onLoaded(); - }); - } - else - { - this.onLoaded(); - } -}; - -/** - * Invoked when image file is loaded or it is already cached and ready to use - * - * @method onLoaded - * @private - */ -PIXI.ImageLoader.prototype.onLoaded = function() -{ - this.dispatchEvent({type: "loaded", content: this}); -}; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - -/** - * The xml loader is used to load in XML bitmap font data ("xml" or "fnt") - * To generate the data you can use http://www.angelcode.com/products/bmfont/ - * This loader will also load the image file as the data. - * When loaded this class will dispatch a "loaded" event - * - * @class BitmapFontLoader - * @uses EventTarget - * @constructor - * @param url {String} The url of the sprite sheet JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.BitmapFontLoader = function(url, crossorigin) -{ - /* - * i use texture packer to load the assets.. - * http://www.codeandweb.com/texturepacker - * make sure to set the format as "JSON" - */ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] The base url of the bitmap font data - * - * @property baseUrl - * @type String - * @readOnly - */ - this.baseUrl = url.replace(/[^\/]*$/, ""); - - /** - * [read-only] The texture of the bitmap font - * - * @property baseUrl - * @type String - */ - this.texture = null; -}; - -// constructor -PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader; - -/** - * Loads the XML font data - * - * @method load - */ -PIXI.BitmapFontLoader.prototype.load = function() -{ - this.ajaxRequest = new XMLHttpRequest(); - var scope = this; - this.ajaxRequest.onreadystatechange = function() - { - scope.onXMLLoaded(); - }; - - this.ajaxRequest.open("GET", this.url, true); - if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/xml"); - this.ajaxRequest.send(null) -}; - -/** - * Invoked when XML file is loaded, parses the data - * - * @method onXMLLoaded - * @private - */ -PIXI.BitmapFontLoader.prototype.onXMLLoaded = function() -{ - if (this.ajaxRequest.readyState == 4) - { - if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) - { - var textureUrl = this.baseUrl + this.ajaxRequest.responseXML.getElementsByTagName("page")[0].attributes.getNamedItem("file").nodeValue; - var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); - this.texture = image.texture.baseTexture; - - var data = {}; - var info = this.ajaxRequest.responseXML.getElementsByTagName("info")[0]; - var common = this.ajaxRequest.responseXML.getElementsByTagName("common")[0]; - data.font = info.attributes.getNamedItem("face").nodeValue; - data.size = parseInt(info.attributes.getNamedItem("size").nodeValue, 10); - data.lineHeight = parseInt(common.attributes.getNamedItem("lineHeight").nodeValue, 10); - data.chars = {}; - - //parse letters - var letters = this.ajaxRequest.responseXML.getElementsByTagName("char"); - - for (var i = 0; i < letters.length; i++) - { - var charCode = parseInt(letters[i].attributes.getNamedItem("id").nodeValue, 10); - - var textureRect = { - x: parseInt(letters[i].attributes.getNamedItem("x").nodeValue, 10), - y: parseInt(letters[i].attributes.getNamedItem("y").nodeValue, 10), - width: parseInt(letters[i].attributes.getNamedItem("width").nodeValue, 10), - height: parseInt(letters[i].attributes.getNamedItem("height").nodeValue, 10) - }; - PIXI.TextureCache[charCode] = new PIXI.Texture(this.texture, textureRect); - - data.chars[charCode] = { - xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), - yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), - xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), - kerning: {}, - texture:new PIXI.Texture(this.texture, textureRect) - - }; - } - - //parse kernings - var kernings = this.ajaxRequest.responseXML.getElementsByTagName("kerning"); - for (i = 0; i < kernings.length; i++) - { - var first = parseInt(kernings[i].attributes.getNamedItem("first").nodeValue, 10); - var second = parseInt(kernings[i].attributes.getNamedItem("second").nodeValue, 10); - var amount = parseInt(kernings[i].attributes.getNamedItem("amount").nodeValue, 10); - - data.chars[second].kerning[first] = amount; - - } - - PIXI.BitmapText.fonts[data.font] = data; - - var scope = this; - image.addEventListener("loaded", function() { - scope.onLoaded(); - }); - image.load(); - } - } -}; - -/** - * Invoked when all files are loaded (xml/fnt and texture) - * - * @method onLoaded - * @private - */ -PIXI.BitmapFontLoader.prototype.onLoaded = function() -{ - this.dispatchEvent({type: "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 - * - * Awesome JS run time provided by EsotericSoftware - * https://github.com/EsotericSoftware/spine-runtimes - * - */ - -/** - * The Spine loader is used to load in JSON spine data - * To generate the data you need to use http://esotericsoftware.com/ and export the "JSON" format - * Due to a clash of names You will need to change the extension of the spine file from *.json to *.anim for it to load - * See example 12 (http://www.goodboydigital.com/pixijs/examples/12/) to see a working example and check out the source - * You will need to generate a sprite sheet to accompany the spine data - * When loaded this class will dispatch a "loaded" event - * - * @class Spine - * @uses EventTarget - * @constructor - * @param url {String} The url of the JSON file - * @param crossorigin {Boolean} Whether requests should be treated as crossorigin - */ -PIXI.SpineLoader = function(url, crossorigin) -{ - PIXI.EventTarget.call(this); - - /** - * The url of the bitmap font data - * - * @property url - * @type String - */ - this.url = url; - - /** - * Whether the requests should be treated as cross origin - * - * @property crossorigin - * @type Boolean - */ - this.crossorigin = crossorigin; - - /** - * [read-only] Whether the data has loaded yet - * - * @property loaded - * @type Boolean - * @readOnly - */ - this.loaded = false; -} - -PIXI.SpineLoader.prototype.constructor = PIXI.SpineLoader; - -/** - * Loads the JSON data - * - * @method load - */ -PIXI.SpineLoader.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; - scope.onJSONLoaded(); - }); - jsonLoader.load(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onJSONLoaded - * @private - */ -PIXI.SpineLoader.prototype.onJSONLoaded = function (event) { - var spineJsonParser = new spine.SkeletonJson(); - var skeletonData = spineJsonParser.readSkeletonData(this.json); - - PIXI.AnimCache[this.url] = skeletonData; - - this.onLoaded(); -}; - -/** - * Invoke when JSON file is loaded - * - * @method onLoaded - * @private - */ -PIXI.SpineLoader.prototype.onLoaded = function () { - this.loaded = true; - this.dispatchEvent({type: "loaded", content: this}); -}; - - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ - - if (typeof exports !== 'undefined') { - if (typeof module !== 'undefined' && module.exports) { - exports = module.exports = PIXI; - } - exports.PIXI = PIXI; - } else { - root.PIXI = PIXI; - } - - -}).call(this); \ No newline at end of file diff --git a/examples/example 7 - Transparent Background/index.html b/examples/example 7 - Transparent Background/index.html index 5fbdf00..f573de6 100644 --- a/examples/example 7 - Transparent Background/index.html +++ b/examples/example 7 - Transparent Background/index.html @@ -8,12 +8,12 @@ padding: 0; background-color: #FFFFFF; } - + .textHolder{ width: 400px; } - + @@ -27,43 +27,43 @@ blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
    + +