LEARN ABOUT EXPRESSIONS IN THIS DETAILED AFTER EFFECTS TUTORIAL! | We’ll create a loader bar, percent counter, and a countdown timer that can be customize by changing one simple slider.
In this After Effects tutorial, we’ll learn a whole bunch about how to use expressions and work with time and expressions by creating a bar that loads to 100% while displaying a bit of text that counts upward to show the progress from 0-100% and a countdown clock that should how long in minutes and seconds until the loading is complete. It’s the trifecta of perfect countdown and loader screen goodness. To cap off the tutorial, you can write the code once and simply change one slider to change the duration of your loader and everything updates automatically!
Tags: after effects, after effects tutorial, after effect CC, after effects tutorials, after effects countdown, after effects expressions, how to, after effects loading bar, loader, live countdown, countdown splash screen, splash screen after effects, after effects countdown, after effects countdown tutorial, after effects timer tutorial, after effects linear, after effects variables, visual effects, time in after effects, tutvid, nathaniel dodson, AE
Tutorial Recording Notes:
Disclaimer: these are the actual notes I used to record this video and are written in a language you may or may not understand. Hopefully, you find them useful or cool.
Finished code:
Bar code:
duration=thisComp.layer(“DurationInSeconds”).effect(“Slider Control”)(“Slider”);
barWidth = linear(time, 0, duration, 0, 100);
[barWidth,100]
Text code:
duration=thisComp.layer(“DurationInSeconds”).effect(“Slider Control”)(“Slider”);
Math.floor(linear(time,0,duration,0,100)) + “%”
Clock code:
duration=thisComp.layer(“DurationInSeconds”).effect(“Slider Control”)(“Slider”);
countdown = Math.floor(duration-time);
minutes = Math.floor(countdown/60);
seconds = countdown%60;
function addZero(n) {
if (n<10) return “0” + n else return n;
}
if(duration > 0 && time < duration){
“Time Remaining: ” + minutes + “:” + addZero(seconds);
} else {“Time Remaining: 00:00”}
- New composition that is 30fps and runs for 00:2:00:00 (two mins) and is 2560×1440 in size
- Make 1500×25 bar and set fill to a very light purple
- Set this bar’s anchor point to center-left
- Make 1520×45 bar, no fill, set border to very light purple/blue/teal
- Select both bars and align horizontal and vertical
- Add text with Cocogoose at 100px, center-aligned, filled with light blue/teal
- Align the text filled above the bar. Fill with temp text “27%
- Duplicate this text and drag below the bar and change the text size to 60px
- Create a New Null Object and add a slider to this and set it to 60.
- Get to Transform>Scale on the bar fill layer and uncheck the chain link
- Alt/Opt click to add expressions to the Transform>Scale of the bar fill layer
- Define the variable that will hold the duration: duration=PICK WHIP TO SLIDER VALUE
- Add this to the next line: barWidth=Math.floor(linear(time, 0, duration, 0, 100)); (quickly explain the linear expression and what’s going on here. Mention the Math.floor to round numbers down to get rid of the decimal + bunch of numbers)
- Add this to the next line: [barWidth,100] (outputting the var as the width in scale and maintaining 100% height for the loader.)
- Test the loader bar and it should start crawling across the screen.
- Go to the Text>Source Text and open the expressions panel
- Add duration=PICK WHIP TO SLIDER VALUE
- Add Math.floor(linear(time,0, duration,0,100)) + “%” (explain how this lines up with how we used linear before and adding the “%” as a string to the end of the text field to cover our bases.
- Test the animation and see how it’s working
- Go to the Text>Source Text in the lower text layer and open the expressions editor
- Define the duration variable again
- Create a variable to reverse time for our countdown: countdown = Math.floor(duration-time); (subtracting the current time from the number of seconds set in the duration + using Math.floor to round the number down)
- Create variables to hold the minutes and seconds:
- minutes = Math.floor(countdown/60);
- seconds = countdown%60;
- Divide the countdown number by the number of seconds in a minute
- The “%” symbol is the modulos operator and it creates a looping repeat constrained by that number
- To quickly test how this works and looks, add this:
- “Time Remaining: ” + minutes + “:” + seconds;
- Explain adding a string of text, and pasting in the values from those vars. Show the problems proudly.
- Create the “addZero” function that I like to use in a situation like this:
- function addZero(n) {
- if (n<10) return “0” + n else return n;
- }
- Explain the function and returning the number that will then be used in the expression
- Now modify the output text line of code to look like this: “Time Remaining: ” + minutes + “:” + addZero(seconds); (explain)
- The last thing to clean up is the negative numbers that happen if you scroll past the duration in seconds set by the slider value.
- Create an if/else statement:
- if(duration > 0 && time < duration){
- } else {“Time Remaining: 00:00”}
- Explain the if/else and that we need to add in what happens on the IF part of the statement
- Take the “Time Remaining: ” + minutes + “:” + addZero(seconds); bit from before and put that as what happens when the if statement is fulfilled.
- BOOM!
Leave a Reply