On 3/2/07, Karina Steffens <[EMAIL PROTECTED]> wrote:
If your mc's reg point is top left:
 mc._x =  _root.xmouse - mc._width/2
 mc._y =  _root.ymouse - mc._height/2

Incidentally, there's a neat trick you can do to speed up the
calculation AND ensure that the result is an integer (so that the clip
is aligned to the pixel). It's called "bitwise shift right":

mc._x =  _root.xmouse - (mc._width >> 1);
mc._y =  _root.ymouse - (mc._height >> 1);

The benefit in speed is probably negligible in this case. In a test
where I ran a calculation a million times, shift right was about 200ms
faster than division. (I wonder if the difference might be greater in
AS3, though....) However, if you also have to constrain to an integer
(e.g., using Math.floor()), then shift right is over twice as fast as
using Math.floor and division.

Basically, whenever multiplying or dividing by a power of 2, you can
use shift left (for multiplication) or shift right (for division) and
get a faster result that is automatically constrained to an integer.

x >> 1  is equivalent to  Math.floor(x / 2)
x >> 2  is equivalent to  Math.floor(x / 4)
x >> 3  is equivalent to  Math.floor(x / 8)
x >> 4  is equivalent to  Math.floor(x / 16)

x << 1  is equivalent to Math.floor(x * 2)
x << 2  is equivalent to Math.floor(x * 4)
x << 3  is equivalent to  Math.floor(x * 8)
x << 4  is equivalent to  Math.floor(x * 16)

You get the idea....
--
T. Michael Keesey
Director of Technology
Exopolis, Inc.
2894 Rowena Avenue Ste. B
Los Angeles, California 90039
--
The Dinosauricon: http://dino.lm.com
Parry & Carney: http://parryandcarney.com
ISPN Forum: http://www.phylonames.org/forum/
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to