44 * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License }
55 */
66
7+ var BuildGameObject = require ( '../../../src/gameobjects/BuildGameObject' ) ;
78var Class = require ( '../../../src/utils/Class' ) ;
89var GetValue = require ( '../../../src/utils/object/GetValue' ) ;
910var ScenePlugin = require ( '../../../src/plugins/ScenePlugin' ) ;
@@ -54,6 +55,8 @@ var SpinePlugin = new Class({
5455 this . sceneRenderer ;
5556 this . skeletonDebugRenderer ;
5657
58+ this . plugin = Spine ;
59+
5760 if ( this . isWebGL )
5861 {
5962 this . runtime = Spine . webgl ;
@@ -75,11 +78,9 @@ var SpinePlugin = new Class({
7578 this . temp1 ;
7679 this . temp2 ;
7780
78- // Register our file type
7981 pluginManager . registerFileType ( 'spine' , this . spineFileCallback , scene ) ;
8082
81- // Register our game object
82- pluginManager . registerGameObject ( 'spine' , this . createSpineFactory ( this ) ) ;
83+ pluginManager . registerGameObject ( 'spine' , this . add . bind ( this ) , this . make . bind ( this ) ) ;
8384 } ,
8485
8586 boot : function ( )
@@ -329,6 +330,13 @@ var SpinePlugin = new Class({
329330 return this ;
330331 } ,
331332
333+ setEffect : function ( effect )
334+ {
335+ this . sceneRenderer . skeletonRenderer . vertexEffect = effect ;
336+
337+ return this ;
338+ } ,
339+
332340 spineFileCallback : function ( key , jsonURL , atlasURL , preMultipliedAlpha , jsonXhrSettings , atlasXhrSettings )
333341 {
334342 var multifile ;
@@ -355,8 +363,8 @@ var SpinePlugin = new Class({
355363 /**
356364 * Creates a new Spine Game Object and adds it to the Scene.
357365 *
358- * @method Phaser.GameObjects.GameObjectFactory#spineFactory
359- * @since 3.16 .0
366+ * @method Phaser.GameObjects.GameObjectFactory#add
367+ * @since 3.19 .0
360368 *
361369 * @param {number } x - The horizontal position of this Game Object.
362370 * @param {number } y - The vertical position of this Game Object.
@@ -365,19 +373,63 @@ var SpinePlugin = new Class({
365373 *
366374 * @return {Phaser.GameObjects.Spine } The Game Object that was created.
367375 */
368- createSpineFactory : function ( plugin )
376+ add : function ( x , y , key , animationName , loop )
377+ {
378+ var spineGO = new SpineGameObject ( this . scene , this . scene . sys . spine , x , y , key , animationName , loop ) ;
379+
380+ this . scene . sys . displayList . add ( spineGO ) ;
381+ this . scene . sys . updateList . add ( spineGO ) ;
382+
383+ return spineGO ;
384+ } ,
385+
386+ /**
387+ * Creates a new Image Game Object and returns it.
388+ *
389+ * Note: This method will only be available if the Image Game Object has been built into Phaser.
390+ *
391+ * @method Phaser.GameObjects.GameObjectCreator#image
392+ * @since 3.0.0
393+ *
394+ * @param {object } config - The configuration object this Game Object will use to create itself.
395+ * @param {boolean } [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
396+ *
397+ * @return {Phaser.GameObjects.Image } The Game Object that was created.
398+ */
399+ make : function ( config , addToScene )
369400 {
370- var callback = function ( x , y , key , animationName , loop )
401+ if ( config === undefined ) { config = { } ; }
402+
403+ var key = GetValue ( config , 'key' , null ) ;
404+ var animationName = GetValue ( config , 'animationName' , null ) ;
405+ var loop = GetValue ( config , 'loop' , false ) ;
406+
407+ var spineGO = new SpineGameObject ( this . scene , this . scene . sys . spine , 0 , 0 , key , animationName , loop ) ;
408+
409+ if ( addToScene !== undefined )
371410 {
372- var spineGO = new SpineGameObject ( this . scene , plugin , x , y , key , animationName , loop ) ;
411+ config . add = addToScene ;
412+ }
373413
374- this . displayList . add ( spineGO ) ;
375- this . updateList . add ( spineGO ) ;
376-
377- return spineGO ;
378- } ;
414+ BuildGameObject ( this . scene , spineGO , config ) ;
415+
416+ // Spine specific
417+ var skinName = GetValue ( config , 'skinName' , false ) ;
418+
419+ if ( skinName )
420+ {
421+ spineGO . setSkinByName ( skinName ) ;
422+ }
423+
424+ var slotName = GetValue ( config , 'slotName' , false ) ;
425+ var attachmentName = GetValue ( config , 'attachmentName' , null ) ;
426+
427+ if ( slotName )
428+ {
429+ spineGO . setAttachment ( slotName , attachmentName ) ;
430+ }
379431
380- return callback ;
432+ return spineGO . refresh ( ) ;
381433 } ,
382434
383435 getRuntime : function ( )
0 commit comments