HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: How To: Stop and Destroy All GUI Animations  (Read 1546 times)

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1405
    • View Profile
    • Forever Interactive, Inc.
How To: Stop and Destroy All GUI Animations
« on: Jan 16, 13, 05:21:34 PM »

I don't know if this has ever happened to you, but for me, sometimes a gui animation gets bad parameters and it causes the console to be spammed with error messages as the timer of the animation keeps ticking.  There is the method removeAnimations() of class GUIControl to stop animations on that control, but sometimes it is difficult to find the control that is causing problems.

So I wrote this catch-all function in the GUIAnimation script to shut down all running animations so I can run it from the console and easily stop the error spam:

Code: (hsl) [Select]
public function RemoveAllAnimations()
  //Stop and Destroy all normal animations:
  animationList as List of Association = QueryAssociation(0, "GUIAnimation", 0)
  foreach a in animationList
    if(IsAssociationValid(a))
      animation as NodeRef of Class GUIAnimation = a.target
      if animation != None
        if animation.animationScript != None
          if HasFunction(animation.animationScript, "GUIAnimation_remove")
            animation.animationScript:GUIAnimation_remove(animation, a.source)
          .
        .
        if animation != None
          DestroyNode(animation)
        .
      .
    .
  .
 
  clear animationList
 
  //Stop and Destroy all synched animations:
  animationList = QueryAssociation(0, "GUISyncedAnimation", 0)
  if animationList.length > 0
    foreach assoc in animationList
      if IsAssociationValid(assoc)
        animation as NodeRef = assoc.source
        if animation != None
          where animation is kindof GUISyncedAnimation
            loop i from animation.controlsToAnimate.length to 1 by -1
              if animation.animationScript != None
                if HasFunction(animation.animationScript, "GUIAnimation_remove")
                  animation.animationScript:GUIAnimation_remove(animation, assoc.target)
                  if animation == None
                    break
                  .
                .
              .
              remove animation.controlsToAnimate at i keep
              removeAssociation(animation, "GUISyncedAnimation", assoc.target)
            .
            if animation != None and animation.controlsToAnimate.length == 0
              DestroyNode(animation)
            .
          .
        .
      .
    .
  .
.

Its a combination of how to find all controls running animations and the guts of how removeAnimations() works to stop a particular control's animations.

Feel free to use it if you find it useful.
« Last Edit: Jan 18, 13, 09:25:49 AM by ScottZarnke »
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.