I don't think using coercion rather than a Math method will make a noticeable difference in performance, really. But even though it's a bit faster, the results won't be always correct if what you're looking for is rounding (instead of just discarding decimals). Also keep in mind that int() works as Math.floor for positive numbers, but the effect is different for negative numbers (it's like doing Math.ceil if you forget about the sign).
I think Math.round is what it's needed here if you want correct results. Try this and it'll be clea why: trace( Math.round( 1.9) ); // 2 OK trace( Math.floor( 1.9) ); // 1 wrong trace( int( 1.9) ); // 1 wrong trace( Math.round( 1.3) ); // 1 OK trace( Math.floor( 1.3) ); // 1 OK trace( int( 1.3) ); // 1 OK trace( Math.round( -1.9) ); // -2 OK trace( Math.floor( -1.9) ); // -2 OK trace( int( -1.9) ); // -1 wrong trace( Math.round( -1.3) ); // -1 OK trace( Math.floor( -1.3) ); // -2 wrong trace( int( -1.3) ); // -1 OK Cheers Juan Pablo Califano 2008/12/17 Jiri Heitlager <[email protected]> > Casting to int is faster. > > var tX:int = int(sprite.x) > > Jiri > > > jonathan howe wrote: > >> Hi, Laurent, >> >> You could use localToGlobal(), apply Math.round() to this global point, >> compare the original global point with the rounded version, and then >> offset >> the child's coordineates by the differences. >> >> Caveats are: >> - if you do this multiple places in a display hierarchy, you'd need to >> work >> from the bottom upwards. >> - during animation you're bound to introduce a certain amount of >> jumpiness. >> >> On Wed, Dec 17, 2008 at 8:39 AM, laurent <[email protected]> >> wrote: >> >> Hi, >>> >>> Is there a way to be sure elements are positionned précisely on a Pixel ? >>> >>> I have a sprite containing sprites that are positionned on integer >>> coordinates so they are pixel positionned. >>> And this sprite is re-positionned when the window resize, so I used int() >>> to be sure I got x and y as integers but still the content get blury >>> sometimes. >>> Is there something to do that flash always position element on a pixel >>> not >>> a pixel and half...? >>> >>> thx >>> L >>> _______________________________________________ >>> Flashcoders mailing list >>> [email protected] >>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >>> >>> >> >> >> _______________________________________________ > Flashcoders mailing list > [email protected] > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

