Monday 21 November 2011

Twips

Although the x and y of a DisplayObject in ActionScript are accessed as Numbers they are stored internally as twips. Twips are units of one twentieth of a display pixel, small enough to position a DisplayObject with sub-pixel accuracy. But they are not Numbers and so should not be treated as such.

In particular if the position of an object needs to be stored for later use it should be stored somewhere else. Storing it in the built in fields of a DisplayObject is slower and less accurate.

Be especially careful of doing calculations on values stored as twips which can amplify the error, such as subtracting the positions of two DisplayObjects to get their separation or the bearing of one from the other, or using two positions of a moving DisplayObject to calculate its velocity.

1 comment: