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

Author Topic: Best way to smooth fill a bar  (Read 945 times)

ExileThomas

  • General Accounts
  • *
  • Posts: 23
    • View Profile
Best way to smooth fill a bar
« on: May 07, 16, 10:48:10 AM »

What is the best way to smoothly fill a bar (eg like a loading bar, progress bar etc)

I know in c# and other languages you can use a lerp and corouitene to do this, but these do not exist in heroscript.

I know i can use a timer and fire it of like every 0.05-0.1 second and fill it that way but i dont know if this is the most optimal way of doing it as would have to be fired off regularly to avoid the bar looking like it is jumping.

Is this the way i should go about doing it and then setting a graphics x length within this timer or is there a better way of doing it.

Thanks
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1129
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Best way to smooth fill a bar
« Reply #1 on: May 07, 16, 12:29:32 PM »

Take a look in the client script (E_AbilityBarClassMethods I think), for the timeoutability function. Its called form the server side to show when the skill will be usable again. Using different amounts of time, the bar will show progress over the same length of gui size. Its the shutter that is displaying over the top of the skill picture.

For an example, put 2 skills in the hotbar Fortification and Assault blast. Then right click them or hit the corresponding key to use them. Fort has a 30 sec delay while Assault has a 1 sec. Both cover the same distance of gui.
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1405
    • View Profile
    • Forever Interactive, Inc.
Re: Best way to smooth fill a bar
« Reply #2 on: May 07, 16, 01:49:41 PM »

There are some scripts already in the engine for gui animation, and one in particular that will do linear interpolation of any gui value called GUIA_Interpolate.  See here for details: http://hewiki.heroengine.com/wiki/GUI_Animations

I have never really played around with doing it by setting an animation in a field in the control, but here is an example of doing it code:

Code: [Select]
  GUIAnimation:addAnimation(me, "Interpolate", "position.x,"+me.position.x+",2,"+me.fDuration+",1,false,SMOOTH,false,0,pos")
For the addAnimation() function, the arguments are:
  • the control to be animated
  • the specific animation script to use (assumes that there is a script whose name is "GUIA_" followed by the text supplied here)
  • a string with comma-separated values that are the parameters dictating the animation

As you can see, you can use literal values for the animation parameters, or mix variables into the string.

You can optionally be notified of when the animation is done in a function or method called OnAnimationDone(...).  There are 3 ways to get that notification, shown in order in which they are considered:

1. If the class of the control being animated defines

Code: [Select]
method OnAnimationDone(animationID as String)
that will be called.

2. Failing that, if the control being animated has its 'script' field set and that script defines

Code: [Select]
shared function onAnimationDone(control as NodeRef of Class GUIControl, animID as String)
That that will be called in that script.

3. Failing that, if the animation node received from calling GUIAnimation:addAnimation() has its 'script' field set and that script defines the same function in #2, then that that will be called in that script.

#3 would look like this:
Code: [Select]
  anim as NodeRef of Class GUIA_Interpolate = GUIAnimation:addAnimation(me, "Interpolate", "position.x,"+me.position.x+",2,"+me.fDuration+",1,false,SMOOTH,false,0,pos")
  anim.script = SYSTEM.EXEC.THISSCRIPT

For #1 or #2 you can ignore the return value of addAnimation().

For the first parameter which indicates the field to animate, it can be a basic field such as opacity, or a class field where you access its fields via a period such as "position.x".  That would also apply to size which would be used as "size.x" for example.

NOTE: If you ever wish to do interpolating directly in your own code, there is the external function
Code: [Select]
InterpolateFloat(curve as Enum InterpolationCurve, left as Float, right as Float, t as Float) as Floatwhich is what the GUIA_Interpolate script uses.

Also, there are other animation scripts besides GUIA_Interpolate which the HJRef world used which could potentially be salvaged from there but they are not in the clean engine code, and you can, of course, attempt to write your own animation script if you are so inclined.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1405
    • View Profile
    • Forever Interactive, Inc.
Re: Best way to smooth fill a bar
« Reply #3 on: May 07, 16, 01:56:02 PM »

Finally, something that is a little confusing about how that one works is that the duration indicates the amount of time it would take to go from min to max, not necessarily from the current value to max (if current value is not min).  So, if the duration was set as 4 seconds, but the current value is already three-quarters of the way between min and max, then the animation will only take 1 second.

Thus, if you wish for the stated duration to be the actual length of the animation that is played, ensure that the current value is equal to min when you begin the animation.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.