increment and hold until event

Moderators: Disciple, zlovatt

Post Reply
explorer
Posts: 17
Joined: March 1st, 2007, 11:12 pm
Location: Poland, Warsaw

hi. im curently making a simple experiment.

say i have a layer, and i want to turn its opacity down every 2 second.
maybe i've been working on this so long, that i cant see the solition and im overcomplicating things.

logic sais to do it like this:

Code: Select all

if( (time % 2) == 0 ){
transform.opacity = transform.opacity - 20;
}
of course this will not work. so i'm trying variables:

Code: Select all

if( (time % 2) == 0 ){
val=val - 20;
}
but to do that, i need to initialize the val value, and when i do so, i naturally get result only on one frame.

the basic idea is to remember value of a given variable from last frame.
i thought about creating a workaround using seedRamdom with timeless set to true, and random(x,x), to generate a value and keep it but its all the same.

my first choice was to use valueAtTime, but somehow i couldn't get it to work.

so... to sum up.... try to write an expression, that will fade out a layer, making it more transparent... even on every frame - only using your own variables, without using time functions.

if AE would treat each frame as one cycle of the loop, that this would do:

Code: Select all

transform.opacity--;
but unfortuneatly it doesn't.

so... any ideas?
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

This uses time, but play around with it and see if it does what you want:

stepTime = 2;
opacityIncrement = 20;
currentStep = Math.floor(time / stepTime);
value - currentStep*opacityIncrement



Dan
explorer
Posts: 17
Joined: March 1st, 2007, 11:12 pm
Location: Poland, Warsaw

thanks, but it does not... i forgot to say, that it cannot be based on time, because i have some events going on, that sould trigger this fading (or whatever) when the event occurs.

by event i mean a condition. i have som expressions going on. you might think of them as collsion detection. so when the collision occurs, i'd like to execute some actions on N following frames (for example decrement the opacity)

i hope that cleared it out. and thanks for a quick answer :)
explorer
Posts: 17
Joined: March 1st, 2007, 11:12 pm
Location: Poland, Warsaw

geezzz.... does this happen to you also?
you think about something, trying to solve a problem for whole day, or two, or more.... finally you post a question to some forum... and then after a few minutes you find a solution. :D

did it ever happen to you?

now... back to the deal. i think i could create a loop that would go throu all frames, and then check for the event.
eventhou the loop will be executed on every frame, it will not change its behaviour.

i think that sould work. and the funniest thing is, that i allready did that several times in my projects :D

so... what do you think... should i give it a try?
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

That method is kind of a last resort, but sometimes you have to do it. It should do what you need.

Dan
Post Reply