Is there anyway to change the speed of animation via actionscript? i mean, can we, err, make the animation within a particular mc, play faster or slower via actionscript? and if its not possible then what will be the possible ways of doing it, without making many animations at different speeds?
maybe change the fps?
Well blue, u can control the speed of the animation, irrespective of the FPS. Make your code run based on real-time and not on FPS.
For eg:
var duration = 1000
function animate()
{
char.nextFrame()
}
intervalID =setInterVal(animate,duration)
So this way, the function animate() gets called every 1 sec or 1000ms. And if you want to increase the speed of animation,just change your duration to 500, then the function will be called every 1/2 a second or 500ms. Thus increasing the speed of the animation. This is just a simple idea on how to make your code independent from the FPS. If you are using bitMapdata or copyPixel in your game, you would probably be using a Render() and an update() function, so even here it is possible to render() at a faster rate than update().Just google on it, you will find tons of article on it.
One thing you may need to do if you use setInterval or setTimeout is to account for the amount of time it takes for your code to execute.
At the begining of the function you call in your interval, move the movie clip to it’s next frame, clear the interval (or timeout) and set a variable to the value of getTimer().
At the end of this function block, determine the elapsed time with a second call to getTimer, then subtract that amount from your desired timestep for your next setInterval or setTimeout call.
Example:
var duration = 1000
function animate(){
clearInterval(intervalID); // clear the current interval
var current = getTimer(); // get the current time
char.nextFrame(); // advance the movie clip to the next frame
// all other code you want executed each timestep
var newTimeStep = duration - (getTimer() - current); // get the elapsed time
newTimeStep = (newTimeStep > 0) ? newTimeStep : 1; // check if function took longer than duration allows
intervalID = setInterVal(animate, newTimeStep); // set new interval with new time step
}
intervalID = setInterVal(animate, duration);
This method helps make things run smoothly, even when your code has a hiccup. It wont take care of issues with code than takes longer to process than your desired duration, but that’s a different bottleneck to deal with.
Wow thanks Jerryscript… and acebuddy29 thank you too!!
[quote=Jerryscript;2326069]One thing you may need to do if you use setInterval or setTimeout is to account for the amount of time it takes for your code to execute.
At the begining of the function you call in your interval, move the movie clip to it’s next frame, clear the interval (or timeout) and set a variable to the value of getTimer().
At the end of this function block, determine the elapsed time with a second call to getTimer, then subtract that amount from your desired timestep for your next setInterval or setTimeout call.
Example:
var duration = 1000
function animate(){
clearInterval(intervalID); // clear the current interval
var current = getTimer(); // get the current time
char.nextFrame(); // advance the movie clip to the next frame
// all other code you want executed each timestep
var newTimeStep = duration - (getTimer() - current); // get the elapsed time
newTimeStep = (newTimeStep > 0) ? newTimeStep : 1; // check if function took longer than duration allows
intervalID = setInterVal(animate, newTimeStep); // set new interval with new time step
}
intervalID = setInterVal(animate, duration);
This method helps make things run smoothly, even when your code has a hiccup. It wont take care of issues with code than takes longer to process than your desired duration, but that’s a different bottleneck to deal with.[/quote]
Sweeeeeet!!
网站优化可以为网站运营带来哪些效果?网站优化与[url=http://www.ckcf.com.cn]搜索引擎优化是什么关系?为什么说[url=http://www.ce36.cn]网站优化是落后的方式?提供最专业的网站优化分析与网站优化解决