Frerich Raabe
Frerich Raabe

Reputation: 94409

How can I convert a Point to pixel coordinates?

To get the global screen position (in pixels!) of some DisplayObject I'm calling DisplayObject::localToGlobal like

var o: DisplayObject = ...;
var topLeft: Point = o.localToGlobal( new Point( 0, 0 ) );

I noticed that every now and then I'm getting double values for topLeft.y, even though I expected some integer value. Is there some scaling or coordinate system I have to take into account?

Upvotes: 0

Views: 791

Answers (2)

Mexican Seafood
Mexican Seafood

Reputation: 504

This could be due to transformations applied to the parents of your DisplayObject.

You can find out all the transformations affecting a DisplayObject using:

myDisplayObject.transform.concatenatedMatrix;

This is the results of all transformations applied to your target and its parents up to the root of the display list.

More info.

Upvotes: 2

Sunil D.
Sunil D.

Reputation: 18193

x/y coordinates and width/height are floating point values in Flash. It is perfectly legal to size/position objects with sub-pixel values (ie: non-integer values).

With respect to scaling, you can query the objects scaleX and scaleY properties to see if they are being scaled, or force these values to 1.

Upvotes: 0

Related Questions