|
| Playing animations in reverse |
 |
Mon, 21 Apr 2008 20:39:58 -070 |
Hi there,
I have a script that i use to run animations in my models, but i would also like
to be able to play them in reverse as well.
For example, i have a series of buttons that i use to trigger parts of my
animation. Button 1 runs 0-2 sec, Button 2 runs 2-4 sec and button 3 runs 4-6
seconds. Now if i decide to press my buttons in reverse order, i'd like to see
my animation running in reverse, such that button 2 will now play 6-4 sec and
button 1 will play 4-2 seconds.
I hope this all makes sense.
Has anyone come across this before?
Does anyone have any scripts that they're willing to share?
I can provide the script that i'm currently using if this will help anyone with
this problem.
Cheers,
|
| Post Reply
|
| Re: Playing animations in reverse |
 |
Wed, 23 Apr 2008 13:43:02 -070 |
George,
Here's a script that will play your animation in reverse. To play in reverse
successfully, you should set the default "Animation Style" to 'none'
in the 3D properties dialog. Otherwise, the C++ animation routine will collide
with the Javascript engine. (You can imagine how that might happen!).
Here's the script for reverse:
//=======================================
//get the first animation in the scene and create control vars
firstAnimation = scene.animations.getByIndex(0);
firstAnimation.speed = 3;
firstAnimation.oneFrame = 1 / firstAnimation.framesPerSecond;
scene.activateAnimation(firstAnimation);
//run the animation using a TimeEventHandler()=================
myTimer = new TimeEventHandler();
myTimer.onEvent = function(event)
{
firstAnimation.currentTime -= firstAnimation.oneFrame *
(firstAnimation.speed * 0.1);
if (firstAnimation.currentTime <= firstAnimation.startTime) {
firstAnimation.currentTime = firstAnimation.endTime; }
scene.update();
runtime.refresh();
}
runtime.addEventHandler(myTimer);
|
| Post Reply
|
| Re: Playing animations in reverse |
 |
Sun, 27 Apr 2008 21:32:45 -070 |
Thanks Gary,
The script you provided works perfectly
|
| Post Reply
|
|
|
|
|
|
|
|
|
|