Hi -
Is there some part of the Extension Project or just in the normal Hype API that allows for getting the time of a certain timeline?
I’m asking because I’d like to do something where only certain actions happen when the timeline is between Xseconds and Yseconds.
I know there is a way to do this directly on the timeline but I need to do a great many things with this info.
Is there another way to approach this?
To be more specific…I have a series of elements (more than a dozen) and I’d like them to change color as the timeline progresses and change back to the original color when the next button changes. I cannot simply add these changes on the timeline because the buttons when clicked jump to a different part of the timeline. Therefore, if the user clicks a button the timeline edit will not changed the button back to its original color.
Thanks Mark. I do see that. I guess I was asking an even more nube type question: Can I add an event listener to the time of the timeline as it updates?
There’s not currently an event generated for timeline time changes.
The two basic techniques are:
Use your own timer (via setInterval or requestAnimationFrame) and check the timeline time. Be aware of resource management and making sure to not eat unnecessary CPU.
Create an animation with a Math Equation timing function and as this is javascript, call out to your own function callback here.
Thanks for your help. @MaxZieb 's example is a bit beyond me and I’m not able to understand exactly how it is implemented. If anyone has time to post a more simplified example using this technique for the time line so I can better understand this that would be great.
Thank you!
Matt
So as a quick test I aliased a function inside a hype function like this.
// element - DOMHTMLElement that triggered this function being called
// event - event that triggered this function being called
function timr(hypeDocument,element, event )
window.hypFunc = function(){
var ell= hypeDocument.getElementById('txt')
var timer = hypeDocument.currentTimeInTimelineNamed('foo')
ell.innerHTML = timer
}
}
And set the timr hype function to run on prepare for display.
I then set one of the foo timlines start keyframes to a Math Equation.
Yes! You can even forward the parameters as seen in take2 here. The problem with Math functions they don’t have any value context and you can only measure their progress. The moment you offset them or want to sample them backwards you will have to look at the start value to see in what direction the progress is actually progressing and adjust the callback accordingly.
Here are some samples. I added a timeline draggable element that controls the main timeline to make the point clearer. I also used a custom behavior so we don’t have to hard code the action. Many components could react to the “signal” this way.
Here is a sample using regular timeline actions. Works fine as long as the timeline is played without jumping over the trigger points (by dragging it over or using the API to set the time offset).
For future reference. The version from @MarkHunte is also very smart as it has no dependencies and uses the built in Math Equation. I tweaked the structure of Marks file to look like the other two solutions to underline the full potential of Marks approach. It also fires only when Hype’s playhead is passing through the area of the animation seen in the GUI! I created the two solutions as they where suggested by @jonathan and it was mentioned that they are beyond understanding.