0

需要在vue页面引入pixi.js的spine动画功能我可以导入pixi.js但是Spine函数总是显示“Uncaught TypeError: Cannot read property 'Spine' of undefined”[在此处输入链接描述][1]spineboy. atlas/spineboy.json/spineboy.png/在这个链接中 npm install pixi.js import * as PIXI from 'pixi.js'

 <template>
   <div>
     import spine
   </div>

 </template>
 
 <script>
 
 import * as PIXI from 'pixi.js'
 
 mounted: function () {
   var app = new PIXI.Application();
   document.body.appendChild(app.view);
 
   // load spine data
   app.loader
     .add('spineboy', 'assets/pixi-spine/spineboy.json')
     .load(onAssetsLoaded);
 
   app.stage.interactive = true;
 
   function onAssetsLoaded(loader, res) {
       // create a spine boy
       var spineBoy = new PIXI.spine.Spine(res.spineboy.spineData);
 
       // set the position
       spineBoy.x = app.screen.width / 2;
       spineBoy.y = app.screen.height;
 
       spineBoy.scale.set(1.5);
 
       // set up the mixes!
       spineBoy.stateData.setMix('walk', 'jump', 0.2);
       spineBoy.stateData.setMix('jump', 'walk', 0.4);
 
       // play animation
       spineBoy.state.setAnimation(0, 'walk', true);
 
       app.stage.addChild(spineBoy);
 
       app.stage.on('pointerdown', function() {
           spineBoy.state.setAnimation(0, 'jump', false);
           spineBoy.state.addAnimation(0, 'walk', true, 0);
       });
     }
   }
 
 
 </script>

 ```


[1]: https://github.com/pixijs/examples-v4/tree/main/examples/assets/pixi-spine
4

0 回答 0