Is it possible to change animation speed without decreasing FPS?

17 posts

Flag Post

I have an animated movieClip, and I need to change animation speed, changing FPS is not an option. And having multiple keyframes with different animation speeds isn’t a solution too, because it is a bicycle and jumping to another frame will not be smooth, could anyone help with this?

 
Flag Post

If it’s the wheels you’re animating; You can always try not using an animation to rotate them, but using actionscript instead.

public function everyframe() {
bike.wheel.rotation += bikeSpeed;
}
 
Flag Post

How about using a Timer, possibly with TimerEvent#updateAfterEvent if you want to animate it faster than the frame rate of the movie.

 
Flag Post
Originally posted by DrYoshiyahu:

If it’s the wheels you’re animating; You can always try not using an animation to rotate them, but using actionscript instead.

public function everyframe() {
bike.wheel.rotation += bikeSpeed;
}

Unfortunately it’s not only wheels:/

How about using a Timer, possibly with TimerEvent#updateAfterEvent if you want to animate it faster than the frame rate of the movie.

Sounds like a good idea, i will try this

(When timer completed)
timer.start();
Bicycler.nextFrame();

From here on I only need to change timer clock, what do you think about this?

 
Flag Post

IIRC timer animation is resource heavy and unreliable time-wise. Maybe you should use tweens within your MC and control them programmatically? (It’s likely that your goal will require recreation of that bicycle MC.)

 
Flag Post
Originally posted by vesperbot:

IIRC timer animation is resource heavy and unreliable time-wise. Maybe you should use tweens within your MC and control them programmatically? (It’s likely that your goal will require recreation of that bicycle MC.)

Controlling tweens programmatically would be certainly better, but which functions should i use? Is there some information about this? (tried googling but didn’t find anything).

 
Flag Post

Start with this There’s even a FPS setting for you to change dynamically :D

 
Flag Post

That uses a timer…

 
Flag Post

I looked at tween function, it’s good but won’t work with my case as it is only for moving, fading object. My movieclip is animated with different keyFrames (it’s a real animation) and i need to control the speed of how fast this movieClip goes through all it’s frames. BigJM’s suggestion will work, only 1 downside that it is resource hungry.

 
Flag Post

Had a go while I ate my lunch. Result here (fastswf didn’t like me :()

source:

 package  {
	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	
	public class VaryingFPSMovieClip extends MovieClip {
		
		public static var mainTimelineFPS:int=30;
		
		public var desiredFPS;
		protected var step:Number;
		
		public function VaryingFPSMovieClip() {
			step=1;
			desiredFPS=mainTimelineFPS;
			addEventListener(Event.ENTER_FRAME, update);
			stop();
		}
		
		protected function update(e:Event):void {
			step+=desiredFPS/mainTimelineFPS;
			if (step>=totalFrames+1) step-=totalFrames;
			gotoAndStop(int(step));
		}
	}
	
}

just change the ‘desiredFPS’ of your clip

 
Flag Post

That will skip frames if you want to animate faster than the frame rate of the movie.

 
Flag Post

Yup – but I think that’s pretty much unavoidable

 
Flag Post

Thanks to Aaants, that’s a very nice class.
But I had to comment out

desiredFPS=mainTimelineFPS;

Because it would fix my desired fps to main timeline fps, wouldn’t it?

This step:

step+=desiredFPS/mainTimelineFPS;

Is definitely very smart.

But I can’t understand how these lines work:

if (step>=totalFrames+1) step-=totalFrames;
gotoAndStop(int(step));

For example if I had desiredFPS and mainTimelineFPS ratio of 2:1, and a movieClip with 160 frames.
It would add +2 to step, each frame, and when step is > 161 it will minus 160, and step will be equal to 2, then movieClip goes to frame 2.
Now it will start raising step again from 2, but once it becomes greater than 161 step will be lowered by 160 again and it will be equal to 2 again, so how does it work? shouldn’t movieClip be standing still on frame 2?

 
Flag Post

There’s no need to comment it out – that line just sets a default that you can overwrite after you have made the MC:

 var myClip = new GuyOnBike(); // makes a bike with default FPS
// assumes GuyOnBike is a subclass of VaryingFPSMovieClip
myClip.desiredFPS = 15; // overwrites default FPS

You can even change the FPS on the fly; he could be at 15 FPS for a while then you just change it again to speed him up. Change it over time to make it look like he’s accelerating.

The other lines just make sure the MovieClip stays within a valid frame range. Normal MCs loop, I coded that part to make sure this one did too. It won’t stand still on frame 2 because it needs to step all the way back to 161+ before it is reset again.

 
Flag Post
Originally posted by Aaants:

Yup – but I think that’s pretty much unavoidable

Not if you use a timer with updateAfterEvent…

 
Flag Post

Well, I’ll bow to greater knowledge on that one, as it’s not something I’ve ever used :)

 
Flag Post
Originally posted by Aaants:

The other lines just make sure the MovieClip stays within a valid frame range. Normal MCs loop, I coded that part to make sure this one did too. It won’t stand still on frame 2 because it needs to step all the way back to 161+ before it is reset again.

Now I understand, I mistook

if (step>=totalFrames+1) step-=totalFrames;
gotoAndStop(int(step));

for:

if (step>=totalFrames+1)
{
 step-=totalFrames;
gotoAndStop(int(step));
}

Thanks! it’s working very well.

I also looked at updateAfterEvent, but site says that this function only redraws a stage after MouseEvent, KeyboardEvent or TimerEvent. I don’t know if it’s possible to use this with animation which is incide a MovieClip, but it would be possible to use this if there is an object tweened with code, but this example works the same with updateAfterEvent or without it:/

function onTimer(event:TimerEvent):void {
    if (40 < my_mc.x && my_mc.x < 375) {
        my_mc.x-= 50;
    } else {
        my_mc.x=374;
    }
    //event.updateAfterEvent();
}

var moveTimer:Timer=new Timer(500,50);
moveTimer.addEventListener(TimerEvent.TIMER,onTimer);
moveTimer.start();