CountUp with a start, end and duration
Hi All!!!
I wanted a counter to count up to a specific number and stop. Kind of like you see on websites where the number of visitors or certificates earned.
Nothing fancy with regards to the number, no easing or flips
I set up a number variable called "countUp" and set the default to 0. Though it can be anything.
Next, I set up a text variable called "countUpDisplay" and set the default text to countUp.
I added a textbox to the slide.
On the main menu, I went to Insert>Reference and added the countUpDisplay variable to thetextbox.
FInally I added a trigger to execute javascript and used this code:
//countUp defining start and end numbers along with increment delay.
var player = GetPlayer();
function countUpTo(start, end, delay) {
var countingDiv = player.GetVar("countUp");
var count = start;
function updateCount() {
countingDiv = count;
count++;
if (count <= end) {
setTimeout(updateCount, delay);
}
//adding the count - 1 as the interval is counted at a fraction above . This will round down to the actual number.
player.SetVar("countUpDisplay", count -1);
}
updateCount();
console.log("Start: " + start);
console.log("End: " + end);
console.log("Delay: " + delay);
}
// (Start the count, end the count, delay in ms). For example, 1-20 with a delay with a delay of 1 second between each count would look like this: countUpTo(1, 20, 1000)
countUpTo(1, 200, 10)
I hope this helps anyone who's looking for a count-up!
Mike