3

I'm attempting to create an 80s-style basketball scoreboard in After Effects, that appears briefly after scores but is otherwise not displayed. I've got a control layer that is simply text, and outputs either '0' or '100' depending on whether I want the scoreboard on the screen, this value is then fed into the opacity of everything.

It all worked perfectly, until I was watching a game from that era and realised the scoreboard doesn't display on every score. So I went back to work, trying to add a timer to it. The idea is this: the scoreboard displays on a keyframe changing the score, and a variable is set to the time at which this occurs. When the next score-changing keyframe occurs, the time is checked against the previous time and a slider. If the difference between the previous time and the current time is greater than the slider, it displays the score and sets the variable to the new time, otherwise it does nothing.

Problem is, I can't get it to work. I've tried including the variable in the if statement that actually sets the text to '100', but it loses that value as soon as the text is set back to '0'. I've tried what I've got below, but it's obviously updating the thing every single time. Or never, possibly. I can't remember, it's been a couple of days and I've attacked it from a mind-numbing number of angles.

Is there a way to achieve this? I feel like it'd be really easy if all the score keyframes were in one layer, but I have separate layers for each team.

I've also got it set to always display the score in the final two minutes, and not display the score while the clock is stopped (so as to prevent it updating in the middle of sets of free-throws).

I think that's all the info I need to provide, but I'm not 100% sure.

//a home, b away, c clock
a = thisComp.layer("HomeScore").text.sourceText;
b = thisComp.layer("AwayScore").text.sourceText;
c = thisComp.layer("Stopwatch").effect("ClockRunning")("Checkbox")
delayTime = comp("Control").layer("Null 4").effect("HideScoreIfLast")("Slider");
secLeft = parseInt(thisComp.layer("SecLeft").text.sourceText);

lasteval = 0;
displayscore = false;

//set keyframe indexes
aindex = a.nearestKey(time).index;
bindex = b.nearestKey(time).index;
cindex = c.nearestKey(time).index;

//set keyframe times
atime = a.key(aindex).time;
btime = b.key(bindex).time;
ctime = c.key(cindex).time

//adjust index if necessary
if (atime > time) aindex--;
if (btime > time) bindex--;
if (ctime > time) cindex--;

//if clock stopped, use next clock keyframe
if (c.numKeys > cindex && c.valueAtTime(c.key(cindex).time) == 0){
     cindex++;}

//time of last keyframe
aeval = a.key(aindex).time;
beval = b.key(bindex).time;

//check which score changed last, set eval to time of change, evalindex to index of change - if clock stopped at score, use clockstart keyframe instead
if (aeval > beval) {
    if (c.valueAtTime(aeval) == 0) {
    eval = (c.key(cindex).time);
    evalindex = aindex;
} else {
eval = aeval
evalindex = aindex;}
     }
else {
    if (c.valueAtTime(beval) == 0) {
    eval = (c.key(cindex).time);
    evalindex = bindex;
} else {
eval = beval
evalindex = bindex; }}


//if score not displayed recently, or if last two minutes, display score and update last display
lastmath = (eval - lasteval) - delayTime;
if (lastmath >= 0 /*|| secLeft < 120*/) {
    displayscore = true;
    lasteval = eval; 
    }
    else {
        displayscore = false;
        lasteval = eval - (lastmath + delayTime);
    }

//display where time appropriate
if (eval <= (time - 1) && eval >= (time - 5) && displayscore == true)
{
    text.sourceText = 100; }
else {
text.sourceText = displayscore;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.