• Keep in touch:
  • Linked In
  • Twitter
  • RSS

What is a twip?

All coordinates and sizes in a Flash file are expressed in units called twips. One twip is equal to 1/20th of a pixel. For example a rectangle 200 pixels wide and 100 pixels high would be drawn with dimensions 4000 twips wide and 2000 twips high.

Sub-pixel dimensions and coordinates allows great precision when drawing and placing objects on the screen. This is not so important when drawing shapes but is is really useful in giving fine control in the ways the glyphs that represent text are drawn and positioned. Objects drawn off pixel boundaries are anti-aliased and the slightly blurred edges give a smoother appearance when dealing with small font sizes.

In Transform, all the classes used to display objects on the screen use twips as the unit of measurement*. However the Canvas class also allows you to selectively draw shapes using dimensions expressed in pixels, rather than twips. This makes drawing more intuitive by avoiding having to multiply coordinates and dimensions by 20 to convert them to twips.

    Canvas path = new Canvas();
    path.setPixels(true);

    int xorigin = 0;
    int yorigin = 0;
    int width = 200;
    int height = 100;

    path.move(xorign, yorigin);
    path.line(width, height);

*The only exception is in the classes that define images where the width and height are returned in pixels rather than twips. This means that to display an image at the correct size you must scale it by a factor of 20. See the cookbook article How do I add an image to a movie? for more details.