Pausing DragonBones animation

How do I pause a DragonBones animation, or is there even a way to manually pause them at all? I’ve looked around to see if there is any way to do so, but I’ve found nothing so far. I tried using the methods used to pause a normal animation, but it just leads to errors. Not really sure but this might as well help out with my previous issue

I managed to come up with a solution to this problem shortly after discovering armature objects and dragonBones.d.ts, and welp since this is not found anywhere I’ll just drop what I did here

onLoad() {
 this.dBonesComponent = this.node.getComponent(dragonBones.armatureDisplay)
 this.currentFrame = 0 //This can be avoided with SHARED_CACHE's _curFrame, but since idk much of it and i used REALTIME for caching, I had to do that
 this.frozen = [0,0] //frozen is used in this case to trigger the temporary pause
 this.dBonesComponent.addEventListener(dragonBones.EventObject.LOOP_COMPLETE, this.animationEventHandler, this);
},
update(dt) {
 if (this.frozen[1] <= 0) {
  this.currentFrame += dt
  //do other stuff
 } else {
  this.node.pauseAllActions(); 
  this.dBonesComponent .armature().animation.stop(this.armature.animationName)
  this.frozen[0] += dt
  if (this.frozen[0] >= this.frozen[1]) {
   this.frozen = [0,0] //Used so the pause isn't permanent
   this.node.resumeAllActions();
   this.dBonesComponent.armature().animation.gotoAndPlayByTime(this.armature.animationName, this.currentFrame) //Normally, play would just begin by frame 0, but using the currentFrame variable, it can play at the frame it got "paused"
  }
 }
},
animationEventHandler: function (event) {
        if (event.type === dragonBones.EventObject.LOOP_COMPLETE) this.currentFrame = 0 //Useless double check lol, though the part of resetting current frame every time a loop ends is necessary
},
//One last note, but in order for this to work properly, resetting the value of this.currentFrame is also a must when making the program play a new animation

I’m not even sure if this can be considered good but, welp it worked for me and I don’t have much experience, so I’ll take it as the solution, plus it works in both simulator and browser.

1 Like