RE: [Flashcoders] simple math question...

2007-03-14 Thread Rebecca Roberts
An easy way to do this is to build your movieClip so that the graphics
inside align in the upper left corner at (0, 0). Then take the width of
your movie and divide it in half. If you take this half-width value and
subtract it from your _xmouse then it should center your movieClip over
the mouse horizontally. Do the same for the half the height of your
movieClip subtracted from the _ymouse and your movieClip should be
centered vertically.

Here is the equation, but you'll need to fiddle with the code a bit.

mc._x = _xmouse - (mc._width/2);
mc._y = _ymouse - (mc._height/2);

Good Luck.

Becky

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of [p e r c
e p t i c o n]
Sent: Thursday, March 01, 2007 6:57 PM
To: flashcoders
Subject: [Flashcoders] simple math question...

good people,

how do i move a moviClip to center itself at (_xmouse, _ymouse)...i have
the
onPress part down...i just need to center it on those coordinates

thanks
___
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
___
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


Re: [Flashcoders] simple math question...

2007-03-02 Thread T. Michael Keesey

On 3/2/07, JOR <[EMAIL PROTECTED]> wrote:

sweet tip, thanks.

-- JOR


No prob. Incidentally, I'm pretty sure this is why BlurFilter, etc.
are optimized for blur amounts that are powers of 2.

--
Mike Keesey
___
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


Re: [Flashcoders] simple math question...

2007-03-02 Thread JOR

sweet tip, thanks.

-- JOR


T. Michael Keesey wrote:

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

___
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


Re: [Flashcoders] simple math question...

2007-03-02 Thread [p e r c e p t i c o n]

thanks for the info...very helpful!
cheers
[p]

On 3/2/07, Joshua Sera <[EMAIL PROTECTED]> wrote:


For an arbitrary registration point, use

var b:Object = mc.getBounds(mc._parent);
var offset:Object = {x:(mc._x - b.xMin, y:instance._y
- b.yMin)};

then

mc._x =  (_root.xmouse - mc._width/2) - offset.x;
mc._y =  (_root.ymouse - mc._height/2) - offset.y;


--- 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
>
> if it's centered you need not bother about the
> width/2 etc, but if it's
> somewhere else, you'll need to change it or do other
> calcualtions.
>
> Karina
>
> > -Original Message-
> > From: [p e r c e p t i c o n]
> [mailto:[EMAIL PROTECTED]
> > Sent: 01 March 2007 23:57
> > To: flashcoders
> > Subject: [Flashcoders] simple math question...
> >
> > good people,
> >
> > how do i move a moviClip to center itself at
> (_xmouse,
> > _ymouse)...i have the onPress part down...i just
> need to
> > center it on those coordinates
> >
> > thanks
> > ___
> > 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
> >
>
> ___
> 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
>






Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/
___
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


___
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


Re: [Flashcoders] simple math question...

2007-03-02 Thread Ian Thomas

It depends where the registration point of your clip is. If it's at
top-left or centre, then the calculation is simple - see all the other
posts in the thread.

If it's unpredictable, use getBounds() - do something like this:

var bounds:Object=myClipToCentre.getBounds(this);
myClipToCentre._x=_xmouse+(bounds.xMin+bounds.xMax)/2;
myClipToCentre._y=_ymouse+(bounds.yMin+bounds.yMax)/2;

HTH,
 Ian

On 3/1/07, [p e r c e p t i c o n] <[EMAIL PROTECTED]> wrote:

good people,

how do i move a moviClip to center itself at (_xmouse, _ymouse)...i have the
onPress part down...i just need to center it on those coordinates

___
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


RE: [Flashcoders] simple math question...

2007-03-02 Thread Joshua Sera
For an arbitrary registration point, use

var b:Object = mc.getBounds(mc._parent);
var offset:Object = {x:(mc._x - b.xMin, y:instance._y
- b.yMin)};

then

mc._x =  (_root.xmouse - mc._width/2) - offset.x;
mc._y =  (_root.ymouse - mc._height/2) - offset.y;


--- 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
> 
> if it's centered you need not bother about the
> width/2 etc, but if it's
> somewhere else, you'll need to change it or do other
> calcualtions.
> 
> Karina
> 
> > -Original Message-
> > From: [p e r c e p t i c o n]
> [mailto:[EMAIL PROTECTED] 
> > Sent: 01 March 2007 23:57
> > To: flashcoders
> > Subject: [Flashcoders] simple math question...
> > 
> > good people,
> > 
> > how do i move a moviClip to center itself at
> (_xmouse, 
> > _ymouse)...i have the onPress part down...i just
> need to 
> > center it on those coordinates
> > 
> > thanks
> > ___
> > 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
> > 
> 
> ___
> 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
> 



 

Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/
___
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


Re: [Flashcoders] simple math question...

2007-03-02 Thread T. Michael Keesey

On 3/2/07, T. Michael Keesey <[EMAIL PROTECTED]> wrote:


In a test
where I ran a calculation a million times, shift right was about 200ms
faster than division.


Sorry, that's not a helpful metric. I should have said shift right
took ~90% as much time.

--
Mike Keesey
___
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


Re: [Flashcoders] simple math question...

2007-03-02 Thread T. Michael Keesey

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


Re: [Flashcoders] simple math question...

2007-03-02 Thread [EMAIL PROTECTED]

MovieClip._width / 2  = its _x center
MovieClip._height / 2 = its _y center

hope it helps



[p e r c e p t i c o n] wrote:

good people,

how do i move a moviClip to center itself at (_xmouse, _ymouse)...i 
have the

onPress part down...i just need to center it on those coordinates

thanks
___
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



___
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


Re: [Flashcoders] simple math question...

2007-03-02 Thread Yehia Shouman

dont forget updateAfterEvent(); with the MouseMove use. it tells the player
to refresh visuals after the calculated mouse move event you catched even if
it wasn't time to render that frame.

On 3/2/07, Yehia Shouman <[EMAIL PROTECTED]> wrote:


1) either double click your clip and group everthing and center it
manually

OR
2) make sure your graphics inside that clip is at 0,0
and then

inside your MouseMove handler or onEnterFrame handler;
toCenterClip._x = _xmouse - (toCenterClip._width/2);
toCenterClip._y = _ymouse - (toCenterClip._height/2);

Yehia



On 3/2/07, [p e r c e p t i c o n] <[EMAIL PROTECTED]> wrote:
>
> good people,
>
> how do i move a moviClip to center itself at (_xmouse, _ymouse)...i have
> the
> onPress part down...i just need to center it on those coordinates
>
> thanks
> ___
> 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
>



___
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


Re: [Flashcoders] simple math question...

2007-03-02 Thread Yehia Shouman

1) either double click your clip and group everthing and center it manually

OR
2) make sure your graphics inside that clip is at 0,0
and then

inside your MouseMove handler or onEnterFrame handler;
toCenterClip._x = _xmouse - (toCenterClip._width/2);
toCenterClip._y = _ymouse - (toCenterClip._height/2);

Yehia



On 3/2/07, [p e r c e p t i c o n] <[EMAIL PROTECTED]> wrote:


good people,

how do i move a moviClip to center itself at (_xmouse, _ymouse)...i have
the
onPress part down...i just need to center it on those coordinates

thanks
___
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


___
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


Re: [Flashcoders] simple math question...

2007-03-02 Thread JOR

Try:

// movie_mc is the instance name of the movieClip
// you want to center on the mouse coords.
movie_mc._x = _xmouse - (movie_mc._width/2);
movie_mc._y = _ymouse - (movie_mc._height/2);

If the movieClip size doesn't change you can optimize this by 
precalculating the (movie_mc._width/2) and (movie_mc._height/2) parts so 
you aren't constantly doing it.


-- JOR



[p e r c e p t i c o n] wrote:

good people,

how do i move a moviClip to center itself at (_xmouse, _ymouse)...i have 
the

onPress part down...i just need to center it on those coordinates

thanks
___
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


___
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


RE: [Flashcoders] simple math question...

2007-03-02 Thread Karina Steffens
If your mc's reg point is top left:
 mc._x =  _root.xmouse - mc._width/2
 mc._y =  _root.ymouse - mc._height/2

if it's centered you need not bother about the width/2 etc, but if it's
somewhere else, you'll need to change it or do other calcualtions.

Karina

> -Original Message-
> From: [p e r c e p t i c o n] [mailto:[EMAIL PROTECTED] 
> Sent: 01 March 2007 23:57
> To: flashcoders
> Subject: [Flashcoders] simple math question...
> 
> good people,
> 
> how do i move a moviClip to center itself at (_xmouse, 
> _ymouse)...i have the onPress part down...i just need to 
> center it on those coordinates
> 
> thanks
> ___
> 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
> 

___
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