PDA

View Full Version : jittering: 72.8 - 0.9 = 71.85???


damian_d
02-10-2006, 02:19 AM
I'm somewhat new to flash. I've got some slow-moving text, and I've always found tweens to be rather jittery. I was convinced it was because of the precision of the coordinate system in flash. It can only increment _y or _x by 0.1 at least. So I was guessing any tween that worked out to be an increment of say 0.13 per frame got rounded up or down from frame to frame, and therefore caused the tween to be jittery.

So then, my next idea was to increment using a fixed value in actionscript, and then my problems should be solved, right? Here's the code:

onClipEvent (load)
{
instMovingText3._y = 80; //just placing it anywhere
}

onClipEvent (enterFrame)
{
instMovingText3._y -= 0.9; //decrease _y by 0.9 every frame
instMovingText3.instText.text = instMovingText3._y; //display _y value
}

So basically, this thing makes the text move up the screen slowly, by increments of 0.9. Precision is at 0.1, so I shouldn't get any rounding errors, right? Here's where it gets crazy. Below is the sequence of _y values that I've set to display in the text object.

79.1 //after first increment. 80 - 0.9 = 79.1
78.2
77.3
76.4 //everything going fine so far
75.5
74.6
73.7
72.8
71.85 //71.85?? Where did that come from?? I was expecting 71.9!
70.95
70.05
69.1 //At this point, we've gained a 0.1 somewhere. From where??
68.2

It continues like that, occasionally including those 0.05's here and there. Very strange.

I know this may sound very trivial to some of you -- I know, why do I need it to be so precise -- but it's totally perplexing me and if anyone has any ideas, I'd greatly appreciate it. Or, if you know any other way to keep slow-moving tweens from being jittery, please share. Cheers!!!

Damian

Tink
02-10-2006, 06:10 PM
not sure about the numbers but try increasing your frame rate to 31 fps to get smoother movement.

Flash uses twips not pixels so i'm guessing the rounding issue will be something to do with that.

damian_d
02-11-2006, 09:00 PM
I do do everything at 30 fps, so I don't think that's the problem. But I will look into twips and pixels, and see if that has something to do with it. Thanks much.

Regarding the numbers, still an open question for anyone who has any ideas about this puzzle.

pixelwit
02-12-2006, 01:51 AM
I think you're seeing a combination of two seperate issues. Flash only moves MovieClips if the distance is greater than .05 pixels and all computers make floating point errors.

Try this code:for(var i=80; i>0; i-=.9){
trace(i);
}
Do a search on the term "floating point error" to understand what's going on there.

This code shows how flash rounds all Clip positions to .05:for(var i=0; i<=500; i++){
var z = i*.001;
_y = z;
trace(z +"\t"+ _y);
}

-PiXELWiT
http://www.pixelwit.com

damian_d
02-16-2006, 02:46 AM
thanks pixelwit and tink.

Yes, I guess it's a machine floating point error thing. It came to a point where I was doing something like this:

thing._y = 40;
thing.textofthing.text = thing._y;

and the text would be something like 40.012498. But if I did the same thing with _y = 50, it would show up as 50 exactly. Strange.

Anyway, thanks much for your replies. In the process, I've learned something new, 'trace'. Much easier to debug that way :)

hangalot
02-16-2006, 05:21 PM
the 31 frames/second is for mac and pc compatibility (in a sense) there are a several blog post about that so do a google.