Skip to content

Commit 172ebef

Browse files
committed
More docs added
1 parent 9486487 commit 172ebef

1 file changed

Lines changed: 69 additions & 56 deletions

File tree

plugins/spine/src/SpinePlugin.js

Lines changed: 69 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ var SpineGameObject = require('./gameobject/SpineGameObject');
1717
* @classdesc
1818
* The Spine Plugin is a Scene based plugin that handles the creation and rendering of Spine Game objects.
1919
*
20+
* All rendering and object creation is handled via the official Spine Runtimes. This version of the plugin
21+
* uses the Spine 3.7 runtimes. Files created in a more recent version of Spine may not work as a result.
22+
*
2023
* Assuming a default environment you access it from within a Scene by using the `this.spine` reference.
2124
*
2225
* When this plugin is installed into a Scene it will add a Loader File Type, allowing you to load
@@ -36,6 +39,11 @@ var SpineGameObject = require('./gameobject/SpineGameObject');
3639
* things you can specify, such as the animation name, skeleton, slot attachments and more. Please
3740
* see the respective documentation and examples for further details.
3841
*
42+
* Phaser expects the Spine data to be exported from the Spine application in a JSON format, not binary.
43+
* The associated atlas files are scanned for any texture files present in them, which are then loaded.
44+
* If you have exported your Spine data with preMultipiedAlpha set, then you should enable this in the
45+
* load arguments, or you may see black outlines around skeleton textures.
46+
*
3947
* The Spine plugin is local to the Scene in which it is installed. This means a change to something,
4048
* such as the Skeleton Debug Renderer, in this Scene, will not impact the renderer in any other Scene.
4149
* The only exception to this is with the caches this plugin creates. Spine atlas and texture data are
@@ -408,14 +416,14 @@ var SpinePlugin = new Class({
408416
},
409417

410418
/**
411-
* Adds a JSON based Texture Atlas, or array of atlases, to the current load queue.
419+
* Adds a Spine Skeleton and Atlas file, or array of files, to the current load queue.
412420
*
413421
* You can call this method from within your Scene's `preload`, along with any other files you wish to load:
414422
*
415423
* ```javascript
416424
* function preload ()
417425
* {
418-
* this.load.atlas('mainmenu', 'images/MainMenu.png', 'images/MainMenu.json');
426+
* this.load.spine('spineBoy', 'boy.json', 'boy.atlas', true);
419427
* }
420428
* ```
421429
*
@@ -429,86 +437,60 @@ var SpinePlugin = new Class({
429437
*
430438
* If you call this from outside of `preload` then you are responsible for starting the Loader afterwards and monitoring
431439
* its events to know when it's safe to use the asset. Please see the Phaser.Loader.LoaderPlugin class for more details.
432-
*
433-
* Phaser expects the atlas data to be provided in a JSON file, using either the JSON Hash or JSON Array format.
434-
* These files are created by software such as Texture Packer, Shoebox and Adobe Flash / Animate.
435-
* If you are using Texture Packer and have enabled multi-atlas support, then please use the Phaser Multi Atlas loader
436-
* instead of this one.
437440
*
438-
* Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle.
439-
*
440-
* The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load.
441-
* The key should be unique both in terms of files being loaded and files already present in the Texture Manager.
442-
* Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file
443-
* then remove it from the Texture Manager first, before loading a new one.
441+
* Phaser expects the Spine data to be exported from the Spine application in a JSON format, not binary. The associated
442+
* atlas files are scanned for any texture files present in them, which are then loaded. If you have exported
443+
* your Spine data with preMultipiedAlpha set, then you should enable this in the arguments, or you may see black
444+
* outlines around skeleton textures.
445+
*
446+
* The key must be a unique String. It is used to add the file to the global Spine cache upon a successful load.
447+
* The key should be unique both in terms of files being loaded and files already present in the Spine cache.
448+
* Loading a file using a key that is already taken will result in a warning.
444449
*
445450
* Instead of passing arguments you can pass a configuration object, such as:
446451
*
447452
* ```javascript
448-
* this.load.atlas({
453+
* this.load.spine({
449454
* key: 'mainmenu',
450-
* textureURL: 'images/MainMenu.png',
451-
* atlasURL: 'images/MainMenu.json'
455+
* jsonURL: 'boy.json',
456+
* atlasURL: 'boy.atlas',
457+
* preMultipliedAlpha: true
452458
* });
453459
* ```
454-
*
455-
* See the documentation for `Phaser.Types.Loader.FileTypes.AtlasJSONFileConfig` for more details.
456-
*
457-
* Instead of passing a URL for the atlas JSON data you can also pass in a well formed JSON object instead.
458-
*
459-
* Once the atlas has finished loading you can use frames from it as textures for a Game Object by referencing its key:
460+
*
461+
* If you need to load multiple Spine atlas files, provide them as an array:
460462
*
461463
* ```javascript
462-
* this.load.atlas('mainmenu', 'images/MainMenu.png', 'images/MainMenu.json');
463-
* // and later in your game ...
464-
* this.add.image(x, y, 'mainmenu', 'background');
464+
* function preload ()
465+
* {
466+
* this.load.spine('demos', 'demos.json', [ 'atlas1.atlas', 'atlas2.atlas' ], true);
467+
* }
465468
* ```
466469
*
467-
* To get a list of all available frames within an atlas please consult your Texture Atlas software.
470+
* See the documentation for `Phaser.Types.Loader.FileTypes.SpineFileConfig` for more details.
468471
*
469472
* If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files
470473
* key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and
471-
* this is what you would use to retrieve the image from the Texture Manager.
474+
* this is what you would use to retrieve the data from the Spine plugin.
472475
*
473476
* The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it.
474477
*
475478
* If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien"
476-
* and no URL is given then the Loader will set the URL to be "alien.png". It will always add `.png` as the extension, although
479+
* and no URL is given then the Loader will set the URL to be "alien.json". It will always add `.json` as the extension, although
477480
* this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL.
478481
*
479-
* Phaser also supports the automatic loading of associated normal maps. If you have a normal map to go with this image,
480-
* then you can specify it by providing an array as the `url` where the second element is the normal map:
481-
*
482-
* ```javascript
483-
* this.load.atlas('mainmenu', [ 'images/MainMenu.png', 'images/MainMenu-n.png' ], 'images/MainMenu.json');
484-
* ```
485-
*
486-
* Or, if you are using a config object use the `normalMap` property:
487-
*
488-
* ```javascript
489-
* this.load.atlas({
490-
* key: 'mainmenu',
491-
* textureURL: 'images/MainMenu.png',
492-
* normalMap: 'images/MainMenu-n.png',
493-
* atlasURL: 'images/MainMenu.json'
494-
* });
495-
* ```
496-
*
497-
* The normal map file is subject to the same conditions as the image file with regard to the path, baseURL, CORs and XHR Settings.
498-
* Normal maps are a WebGL only feature.
499-
*
500-
* Note: The ability to load this type of file will only be available if the Atlas JSON File type has been built into Phaser.
501-
* It is available in the default build but can be excluded from custom builds.
482+
* Note: The ability to load this type of file will only be available if the Spine Plugin has been built or loaded into Phaser.
502483
*
503484
* @method Phaser.Loader.LoaderPlugin#spine
504485
* @fires Phaser.Loader.LoaderPlugin#addFileEvent
505486
* @since 3.19.0
506487
*
507-
* @param {(string|Phaser.Types.Loader.FileTypes.AtlasJSONFileConfig|Phaser.Types.Loader.FileTypes.AtlasJSONFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them.
508-
* @param {string|string[]} [textureURL] - The absolute or relative URL to load the texture image file from. If undefined or `null` it will be set to `<key>.png`, i.e. if `key` was "alien" then the URL will be "alien.png".
509-
* @param {string} [atlasURL] - The absolute or relative URL to load the texture atlas json data file from. If undefined or `null` it will be set to `<key>.json`, i.e. if `key` was "alien" then the URL will be "alien.json".
510-
* @param {Phaser.Types.Loader.XHRSettingsObject} [textureXhrSettings] - An XHR Settings configuration object for the atlas image file. Used in replacement of the Loaders default XHR Settings.
511-
* @param {Phaser.Types.Loader.XHRSettingsObject} [atlasXhrSettings] - An XHR Settings configuration object for the atlas json file. Used in replacement of the Loaders default XHR Settings.
488+
* @param {(string|Phaser.Types.Loader.FileTypes.JSONFileConfig|Phaser.Types.Loader.FileTypes.JSONFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them.
489+
* @param {string} jsonURL - The absolute or relative URL to load the Spine json file from. If undefined or `null` it will be set to `<key>.json`, i.e. if `key` was "alien" then the URL will be "alien.json".
490+
* @param {string|string[]} atlasURL - The absolute or relative URL to load the Spine atlas file from. If undefined or `null` it will be set to `<key>.atlas`, i.e. if `key` was "alien" then the URL will be "alien.atlas".
491+
* @param {boolean} [preMultipiedAlpha=false] - Do the texture files include pre-multiplied alpha or not?
492+
* @param {Phaser.Types.Loader.XHRSettingsObject} [textureXhrSettings] - An XHR Settings configuration object for the Spine json file. Used in replacement of the Loaders default XHR Settings.
493+
* @param {Phaser.Types.Loader.XHRSettingsObject} [atlasXhrSettings] - An XHR Settings configuration object for the Spine atlas file. Used in replacement of the Loaders default XHR Settings.
512494
*
513495
* @return {Phaser.Loader.LoaderPlugin} The Loader instance.
514496
*/
@@ -541,6 +523,22 @@ var SpinePlugin = new Class({
541523
* The x and y coordinate given is used to set the placement of the root Spine bone, which can vary from
542524
* skeleton to skeleton. All rotation and scaling happens from the root bone placement. Spine Game Objects
543525
* do not have a Phaser origin.
526+
*
527+
* If the Spine JSON file exported multiple Skeletons within it, then you can specify them by using a period
528+
* character in the key. For example, if you loaded a Spine JSON using the key `monsters` and it contains
529+
* multiple Skeletons, including one called `goblin` then you would use the key `monsters.goblin` to reference
530+
* that.
531+
*
532+
* ```javascript
533+
* let jelly = this.add.spine(512, 550, 'jelly', 'jelly-think', true);
534+
* ```
535+
*
536+
* The key is optional. If not passed here, you need to call `SpineGameObject.setSkeleton()` to use it.
537+
*
538+
* The animation name is also optional and can be set later via `SpineGameObject.setAnimation`.
539+
*
540+
* Should you wish for more control over the object creation, such as setting a slot attachment or skin
541+
* name, then use `SpinePlugin.make` instead.
544542
*
545543
* @method SpinePlugin#add
546544
* @since 3.19.0
@@ -569,6 +567,21 @@ var SpinePlugin = new Class({
569567
* The x and y coordinate given is used to set the placement of the root Spine bone, which can vary from
570568
* skeleton to skeleton. All rotation and scaling happens from the root bone placement. Spine Game Objects
571569
* do not have a Phaser origin.
570+
*
571+
* If the Spine JSON file exported multiple Skeletons within it, then you can specify them by using a period
572+
* character in the key. For example, if you loaded a Spine JSON using the key `monsters` and it contains
573+
* multiple Skeletons, including one called `goblin` then you would use the key `monsters.goblin` to reference
574+
* that.
575+
*
576+
* ```javascript
577+
* let jelly = this.make.spine({
578+
* x: 500, y: 500, key: 'jelly',
579+
* scale: 1.5,
580+
* skinName: 'square_Green',
581+
* animationName: 'jelly-idle', loop: true,
582+
* slotName: 'hat', attachmentName: 'images/La_14'
583+
* });
584+
* ```
572585
*
573586
* @method SpinePlugin#make
574587
* @since 3.19.0

0 commit comments

Comments
 (0)