Go to Page... |
Thread Tools | Display Modes |
07/04/15, 11:06 PM | #1 | |
Join Date: Feb 2014
Posts: 12
|
Smoothly Animated Status Bar... Help!
I'm looking to smoothly animate a custom attribute bar. Currently I am using ZO_StatusBar_SmoothTransition. It's nice and simple but it does what the default bars are doing.
That is, because EVENT_POWER_UPDATE only fires every couple of seconds, it has a stop-start animation. I'm looking to make it a completely smooth animation without stopping, but I don't know how to accommodate for the period of time between updates without making the bar slower. I've tried a couple of different ideas with all of them not working or having too many drawbacks to be of real use. Any input would be appreciative! |
|
07/05/15, 01:49 AM | #2 |
|
I haven't tried it, but I would look at something like this (example using stamina):
Lua Code:
Then I believe the regen time is every 2 seconds, I don't think there is any API to get that regen time delay, I think its just always 2 seconds (I could be wrong). So when you update your stat if your using a status bar statusBar:SetValue(curStam) or if your doing the size translation you posted in the other thread..whatever, just adjust the time so it will complete in 2 seconds. Then by the time it finishes the next regen tick will come in & your update function fires again, sets the new powerValue and gives it 2 seconds to complete, so it never stops smoothly filling in the bar. The only problem I see with this is that your bar will always be 2 seconds behind the real bar when stats are regening because the original bars update the full amount immediately while your smooth animation will take 2 seconds to fill the bar in by the amount passed in from the power update event. I think the only solution to that problem would be to anticipate the next regen tick & and start filling in your status bar for the "next tick" before it actually happens. So like as soon as the stamina drops start running your updateBar function & filling in the bar immediately by the amount: amountRegen (posted in code above) instead of waiting for that next powerUpdate event to fire & tell you that you just gained xxx stamina....since we already know how much we are going to gain & I believe the regen time is always the constant 2 seconds then by the time the power update event fires & says you gained that amountRegen stamina, your bar has just finished filling it in and your ready to handle the next tick. Last edited by circonian : 07/05/15 at 03:05 AM. |
07/05/15, 02:58 AM | #3 |
|
Here you go, here is a complete example. This example does "anticipate" the next tick (as I mentioned above) so it does not fall behind during the 2 second regen delay.
I just altered my Stamina Bar tutorial code to smooth out the status bar updates. It was a tutorial for beginners so the bar is pretty ugly but it updates very smoothly. You can find it on my dropbox here: Circonians Stamina Bar Tutorial Addon (with Smooth Updates) I added some comments about what I did & why, you really only need to worry about the file CirconianStaminaBar.lua, lines 15-68 are the part that update the status bar. This is from a tutorial I wrote so theres probably other comments in there too. If you try to replicate it & have problems or have trouble understanding some other part of the code look at the tutorial: Circonians Stamina Bar Tutorial Also note I intentionally did not smooth out the drops/loss of stats. I agree to making it look nice, but I figured when you get hit for xxx dmg, that health is gone immediately so the bar should reflect that. Although you could easily alter the code to smooth out the stat losses as well. Last edited by circonian : 07/05/15 at 03:47 AM. |
07/05/15, 03:54 AM | #4 | ||
Join Date: Feb 2014
Posts: 12
|
EDIT: I changed the constants to... Lua Code:
and oddly enough it seems to work a little better. Last edited by Capadillo : 07/05/15 at 04:45 AM. |
||
07/06/15, 04:51 PM | #5 | |
|
I wonder if they have different regen time intervals in & out of combat or if the character sheet tooltip is wrong. Have you tried it while in combat to see if it still matches up with the default stat bars while in combat? |
|
07/06/15, 08:38 PM | #6 | ||
Join Date: Feb 2014
Posts: 12
|
EDIT: Added in this... Lua Code:
Lua Code:
It's about a close as i can eyeball. Odd number though. It would be an update every 1129.9ms. Assuming I have all that right, I just need to throw in a check for if we were healed and do a forced update for that as well. Though, having had looked, I'm not sure there is an event or function that only fires when we get healed. EDIT2: Could it be the difference in latency? EDIT3: Here's a link to my current version: DropBox. The main issue I have left over is when you're healed (i test by healing myself) the health bar sometimes jumps forward (like it should) then back again. Have a look and see what you think of the progress if you want! Last edited by Capadillo : 07/07/15 at 03:12 AM. |
||
07/07/15, 12:02 PM | #7 | |
|
Could what be? Do you mean the time interval difference on regen in & out of combat? No, since the real stat bar updates in large chunks the latency would have to be insane to have any effect & it would correct itself the first time the bar updated.
However, I only tested it for a minute or two. If it is doing what you say its happening in this part of the code: Lua Code:
If the bar is getting out of sync somehow and the currentValue of the bar is getting to large ( > currentPower) then that is the problem. That code is just whats making it jump, but its not the problem. Again I did not notice the problem, but my guess would be this: Lua Code:
You have 100 max health, you get hit for 20 dmg. Your code drops the bar to 80 and immediately starts filling in the bar. So as time goes on, you have 81 health, 82, 83, then you heal yourself for 10 health, this code sees that and saves it in self.forceHealthUpdate
Warning: Spoiler
Lua Code:
Your update function is still ticking away and the next time it ticks it sees that self.forceHealthUpdate +10 value and adds it to your health bars currentValue: Lua Code:
Now, you caught the heal in your CombatEvent function...but when you gain health the power update event fires also which your PowerUpdate function is registered to: Lua Code:
So now PowerUpdate fires because the EVENT_POWER_UPDATE also fired and this code runs: Lua Code:
and the key piece of this, finally....is that remember your bar registers you as having 94 health, while the game says you only have 90 health (because the game hasn't run an update for a health "regen") Lua Code:
Also, if your bar is updating to fast and getting to far ahead of your actual health from when you altered those interval values and you heal yourself this code could also cause the bar to jump back down. The best thing I can think of atm: If your bar is getting to far ahead of the actual values, you could do something like this to limit how far ahead the bar can go. This would prevent it from getting more than 1 regen tick worth of stat ahead of the actual power value, regardless of what your intervals are set at: Lua Code:
But if its being caused by the heals problem/example I gave then it could still be forced to jump back down...so you could also do something like this: Lua Code:
But if you do this fix, you probably need to do both of the fixes I mentioned because this code here would no longer prevent the bar from ticking to far ahead of your stats actual value!! so we need both fixes. But then this may also require you to readjust your interval regen values. Changes on my dropbox: TinyAttributeBar I did also notice one strange thing, If I run...at first the bar updates immediately as I'm running. If you keep sprinting though eventually the bar stops updating until you stop running & the first stamina regen power update event fires. Apparently it appears that (for stamina at least) GetPlayerStat(..) returns 0 if you sprint for to long (it doesn't take long). I don't know if this is a game bug or if its intentional, like you get tired and stop regaining stamina until you stop sprinting. |
|
07/08/15, 02:00 AM | #8 | |
Join Date: Feb 2014
Posts: 12
|
Hmm, none of that seemed to help with the issue I was having unfortunately.
I did however take some time and rewrote most of the two functions. I found a solution that I feel may be problematic later on, but it seems to work. No backtracking of the health bar at all from what I can see. It seems to have fixed the stamina bug as well. Should be the same link but just in case: It's been updated!. Again, thank you for responding! |
|
ESOUI » Developer Discussions » General Authoring Discussion » Smoothly Animated Status Bar... Help! |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|