PDA

View Full Version : Smoothing Line Draw


AniComUS
09-30-2005, 02:23 PM
How can this line drawing move more smoothly?

This script draws a horizontal line using setInterval, but the movement is not smooth. Is there a way to cause the line to be drawn more smoothly? No matter how short I make the interval or how small I make the line drawing increment, there are still little hestitations in the movement.


stop();

var Xorig:Number = 50;
var Yorig:Number = 50;

var Xend:Number = 500;
var Xchg:Number = 2;

var intervalId:Number;
var count:Number = 0;
var maxCount:Number = (Xend-Xorig)/Xchg;
var duration:Number = 1;

function lineTween():Void{
lineStyle(1, 0x000000, 100)
moveTo(Xorig, Yorig);
lineTo(Xorig+(count*Xchg), Yorig);

if(count >= maxCount) {
clearInterval(intervalId);
}
count++;
}

intervalId = setInterval(this, "lineTween", duration);

amen0
09-30-2005, 02:28 PM
hi , try to 60 fps or more mabye will be more smooth

AniComUS
09-30-2005, 02:50 PM
I believe this function is independent of the frame rate. It begins with stop(); and additionally, high fps just chokes the computer more.

Paerez
09-30-2005, 03:06 PM
The function is independent of the frame rate, so, in the computer the line will be exactly the right length. BUT on your screen the line is only as long as it was the last time the screen was updated. So if you have a low framerate, the line will be drawn jerkily.

Turning up the frame rate is the only solution. I would also set the interval to run approximately as often as the frame rate, because any faster will not help.

For example, with a frame rate of 50, there is a new frame drawn every .02 seconds (20ms). So set the frame rate to 50 and have the line update every 20ms and it will be nicely synced to use only the absolute necessary amount of cpu power.

AniComUS
09-30-2005, 03:58 PM
That's an unfortunate conclusion, because for other reasons, running a movie at 50 fps is not workable. We only need about 24 fps, or so as with film, to rely on persistence of memory for the images to appear smooth. It is still not smooth even at 100fps and 10ms. It is probably not the machine, as I am running a new iMac G5 with 1 GIG RAM and no other applications running.

I thought the updateAfterEvent() function allowed the screen to be changed independent of the frame rate. I read that in MM liveDocs:


http://livedocs.macromedia.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=00001870.html

"Function; updates the display (independent of the frames per second set for the movie) when you call it within an onClipEvent() handler or as part of a function or method that you pass to setInterval(). Flash ignores calls to updateAfterEvent that are not within an onClipEvent() handler or part of a function or method passed to setInterval()."

So now I am confused.

Paerez
09-30-2005, 04:10 PM
updateAfterEvent() will update the screen, but with a duration of 1ms, this gives you the equivalence of 1000 frames per second, since updateAfterEvent will cause an extra frame draw every 1ms.

Your code looks very smooth to me at 25 fps with duration set to 40.

You really are limited by the frame rate, since updateAfterEvent will, in effect, increase your frame rate. But keep in mind that if something moves very quickly it will look jerky, but if you make it move slowly it will seem smoother. Try duration 40 with fps 25.

amen0
09-30-2005, 04:12 PM
yes same here i tried this number and it look smooth :)

AniComUS
09-30-2005, 04:56 PM
Thank you both. I guess it just boils down to what one judges to look smooth. I think I see jerks in the motion (slight changes in velocity). Maybe it's not there. I do wear strong glasses.

All the best,

flashead
09-30-2005, 05:50 PM
I found the problem...
I am running a new iMac G5
When it comes to Flash, Macs suck.