1

So let me explain, I have a json file with numbers and the duration of how long each number should be displayed which is 4 seconds. I want the slider to show the first number (which is 1,000) and then four seconds later display 2,000 (which is second number) . But have it showing all the numbers in between 1,000-2,000.

My array looks like this:

[
{ 
    "ID": 1,
    "slider": 1000,
    "duration": .4
},
{ 
    "ID": 2,
    "slider": 2000,
    "duration": .4
},
{ 
    "ID": 3,
    "slider": 3828.52,
    "duration": .4
}
]

And I have found a code that works, it starts at 0 seconds and animates 1,000 counting up to 2,000. The only problem with this code is that it has a delay, So when the animation starts it stays at 1,000 for about one whole second and then starts to animate counting up to 2,000 at the four second mark. Then same thing at the four second mark, it stays at 2,000 for a second and then animates. How do i prevent this delay? I would like it to be constant. Here is the code which works but causes the numbers to delay:

data = footage("example.json").sourceData; rampTime = 3; done = false; i = t = tPrev = 0; while (t <= time){ tPrev = t; t += rampTime + parseFloat(data[i].duration)/ .4; i++; if (i >= data.length){ done = true; break; } } if (done){ parseFloat(data[data.length-1].slider); }else{ if ((time - tPrev) < parseFloat(data[i-1].duration)/ .4){ parseFloat(data[i-1].slider); }else{ v1 = parseFloat(data[i-1].slider); v2 = parseFloat(data[i].slider); t1 = parseFloat(data[i-1].duration)/ .4; t2 = t1 + rampTime; linear(time-tPrev,t1,t2,v1,v2); } }

If you can help find the solution please explain to me i am very new to coding and this is pretty complicated to me.Thank you!

0

Good question Xavier! I had a similar job recently, here's how I did it.

First I would suggest re-working your json file to be a little easier to parse. For example (hopefully I got your intention correctly):

{
    "slider1": {
        "start": 1000,
        "end": 2000,
        "duration": 4,
        "ID": 1
    }
}

Then add two sliders to your layer, one called Anim Duration (seconds) with a default value of 4. If you want to read this value from the json file add the following expression instead:

var data = footage("example.json").sourceData;

data.slider1.duration

Okay now to the second slider (which is the one that actually animates) add the following expression:

var data = footage("example.json").sourceData;

start_value = data.slider1.start;
end_value = data.slider1.end;

step = (end_value - start_value) / effect("Anim Duration (seconds)")("Slider").value; // alternately you can just plug data.slider1.duration here instead of using a second slider...
count = Math.floor(step * (time - thisLayer.inPoint)); // you don't need to use the in-point here, but it is conventient if you know that's where you want to start your animation

if (count < e_value) {
    count;
} else {
    end_value;
}

(if you have any trouble with this let me know, I don't have AE handy for testing so this was mainly done from memory and a snipped I have on me...)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.