pixijs / spine

Pixi.js plugin that enables Spine support.
Other
564 stars 217 forks source link

Global Timescale? #200

Open digilocker opened 6 years ago

digilocker commented 6 years ago

Hi all

Not really an issue, but wondering if something was implemented on this, had a search and see its not in the runtime, but could be useful in pixi-spine?

I'm basically thinking of a global pause/resume situation. At the moment one of my games is using a mixture of gsap tweens and spine animations. GSAP luckily has a pauseall function that works well, but with spine can't see an easy solution. At the moment only way I can think of is to manage all spine instances in an array and loop through to pause/resume. Could be handy?

macguffin commented 6 years ago

The other option is to "power" your animation directly from GSAP

Using something like this would set up a time line for each pixiSpine animation

  let _local_spine_tl: TimelineMax = new TimelineMax({repeat: -1});
                _local_spine_tl.lasttime = 0;
                _local_spine_tl.eventCallback("onUpdate", (_x) => {

                    SPINE.update(_local_spine_tl._totalTime - _local_spine_tl.lasttime);
                    if (callback !== null) {
                        callback(cbParams);
                    }
                    _local_spine_tl.lasttime = _local_spine_tl._totalTime;
                });

Or you can as you suggested push all you spine animations to an array and have a single global timeline control them all

  SPINE_MASTER_tl.lastTime = 0;
       SPINE_MASTER_tl.eventCallback("onUpdate", (_x) => {
            //       console.log(pe_tl._totalTime - pe_tl.lasttime)
            //     this.update(pe_tl._totalTime - pe_tl.lasttime)
            let i = SPINE_ACTORS.length;
            while (i--) {
               SPINE_ACTORS[i].update(SPINE_MASTER_tl._totalTime - SPINE_MASTER_tl.lastTime);
            }

            SPINE_MASTER_tl.lastTime = SPINE_MASTER_tl._totalTime;
        });

I usually prefer to make a time line for each character then I can do things like pause them individually or even slow them down

It was talked about briefly here: https://github.com/pixijs/pixi-spine/issues/164

Hope this helps.

ivanpopelyshev commented 6 years ago

Yeah, something like that. Just dont forget to remove that handler after spine object goes from the stage.