Additional JS event - HUD element value changed

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

Post Reply
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Additional JS event - HUD element value changed

Post by phkb »

Would it be possible to have an event to trigger whenever a change occurs on various HUD elements? For instance, speed increase/decrease, shield up/down, energy bank increase/decrease, that sort of thing. I've been playing around with creating a HUD with custom dials, and was trying to get a curved bar for things like speed, but when using a timer to check for changes the bar moves in a rather jerky way. There doesn't appear to be anyway to achieve this without using a timer, and I imagine running a timer for HUD elements would be quite a drain on resources. If there was an event the custom speed bar could be animated smoothly.

Of course, there might already be a way to do this - feel free to point out my ignorance! And if it's not possible, that's fine too. I'll stick with vertical/horiztonal bars!
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6681
Joined: Wed Feb 28, 2007 7:54 am

Re: Additional JS event - HUD element value changed

Post by another_commander »

Rather than using a timer, why not use a frame callback to check if a value has changed? Frame callbacks are called by default in each frame, as suggested by the name.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Additional JS event - HUD element value changed

Post by phkb »

Ah! Looks like I have some learning to do! Thanks!
Post Reply