Re: [Flashcoders] Pixel precise
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) );// 2OK trace( Math.floor( 1.9) ); // 1wrong trace( int( 1.9) ); // 1wrong trace( Math.round( 1.3) );// 1 OK trace( Math.floor( 1.3) ); // 1OK 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 jiriheitla...@googlemail.com 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 laur...@logiquefloue.org 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Pixel precise
int( ) is casting the content to integer, it has the effect to drop off the decimal part. Same as Math.floor but lots faster L Cor a écrit : If the sprite.x is not an exact round number (so not an correct integer) wouldn't that throw an error??? -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Jiri Heitlager Sent: woensdag 17 december 2008 15:11 To: Flash Coders List Subject: Re: [Flashcoders] Pixel precise 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 laur...@logiquefloue.org 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.9.19/1853 - Release Date: 17-12-2008 8:31 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Pixel precise
Depends on the application whether you can afford this... I would think that in some cases you would want to use rounding so that there is more accurate rendering... you want your object to snap to the nearest pixel, and nearest may be up instead of floored. I do want to emphasize that it is not simply enough to set the DisplayObject's own coordinates to an integer; if the DO in question is inside a parent DO with non-integer coordinates, it won't be correct. That's why I was recommending the localToGlobal technique. -jonathan On Wed, Dec 17, 2008 at 11:55 AM, Jiri Heitlager jiriheitla...@googlemail.com wrote: Math should be avoided when possible, I believe it is quit slow. Maybe Number 0 is even faster for rounding of ;) Jiri laurent wrote: int( ) is casting the content to integer, it has the effect to drop off the decimal part. Same as Math.floor but lots faster L Cor a écrit : If the sprite.x is not an exact round number (so not an correct integer) wouldn't that throw an error??? -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Jiri Heitlager Sent: woensdag 17 december 2008 15:11 To: Flash Coders List Subject: Re: [Flashcoders] Pixel precise 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 laur...@logiquefloue.org 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.9.19/1853 - Release Date: 17-12-2008 8:31 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- -jonathan howe ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Pixel precise
OK, thanks! -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of laurent Sent: woensdag 17 december 2008 17:24 To: Flash Coders List Subject: Re: [Flashcoders] Pixel precise int( ) is casting the content to integer, it has the effect to drop off the decimal part. Same as Math.floor but lots faster L Cor a écrit : If the sprite.x is not an exact round number (so not an correct integer) wouldn't that throw an error??? -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Jiri Heitlager Sent: woensdag 17 december 2008 15:11 To: Flash Coders List Subject: Re: [Flashcoders] Pixel precise 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 laur...@logiquefloue.org 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.9.19/1853 - Release Date: 17-12-2008 8:31 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.9.19/1853 - Release Date: 17-12-2008 8:31 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Pixel precise
Also, if you're using Bitmap objects, you can set the .pixelSnapping property to PixelSnapping.ALWAYS. That will ensure that the bitmap is always drawn at the nearest pixel rather than part pixel. No need for Math.round() or anything like that. Obviously, only works with Bitmaps... Ian On Wed, Dec 17, 2008 at 6:02 PM, Cor c...@chello.nl wrote: OK, thanks! -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of laurent Sent: woensdag 17 december 2008 17:24 To: Flash Coders List Subject: Re: [Flashcoders] Pixel precise int( ) is casting the content to integer, it has the effect to drop off the decimal part. Same as Math.floor but lots faster L Cor a écrit : If the sprite.x is not an exact round number (so not an correct integer) wouldn't that throw an error??? -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Jiri Heitlager Sent: woensdag 17 december 2008 15:11 To: Flash Coders List Subject: Re: [Flashcoders] Pixel precise 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 laur...@logiquefloue.org 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.9.19/1853 - Release Date: 17-12-2008 8:31 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.9.19/1853 - Release Date: 17-12-2008 8:31 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Pixel precise
Math should be avoided when possible, I believe it is quit slow. Maybe Number 0 is even faster for rounding of ;) Jiri laurent wrote: int( ) is casting the content to integer, it has the effect to drop off the decimal part. Same as Math.floor but lots faster L Cor a écrit : If the sprite.x is not an exact round number (so not an correct integer) wouldn't that throw an error??? -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Jiri Heitlager Sent: woensdag 17 december 2008 15:11 To: Flash Coders List Subject: Re: [Flashcoders] Pixel precise 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 laur...@logiquefloue.org 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.9.19/1853 - Release Date: 17-12-2008 8:31 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Pixel precise
If the sprite.x is not an exact round number (so not an correct integer) wouldn't that throw an error??? -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Jiri Heitlager Sent: woensdag 17 december 2008 15:11 To: Flash Coders List Subject: Re: [Flashcoders] Pixel precise 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 laur...@logiquefloue.org 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.9.19/1853 - Release Date: 17-12-2008 8:31 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Pixel precise
try using Math.round() on your position values... - Original Message - From: laurent To: Flash Coders List Sent: Wednesday, December 17, 2008 7:39 AM Subject: [Flashcoders] Pixel precise 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Pixel precise
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 laur...@logiquefloue.org 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- -jonathan howe ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Pixel precise
Make sure to always do Math.round to your x's and y's, so: mc.x = Math.round(xPos); mc.y = Math.round(yPos); And make sure to do the same to all mc's contained within it. .m On Wed, Dec 17, 2008 at 8:39 AM, laurent laur...@logiquefloue.org 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Pixel precise
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 laur...@logiquefloue.org 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 Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Pixel precise
On 12/17/08, jonathan howe jonathangh...@gmail.com wrote: - during animation you're bound to introduce a certain amount of jumpiness. For animation, if you're using something like Tweener that wont matter, since only the final position will be Math.round'ed. If you're rolling your own animation, just make sure only the final positions are rounded and allow all inbe'tween positions to non-rounded. .m ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders