Created
October 25, 2013 21:52
-
-
Save mattlundstrom/7162384 to your computer and use it in GitHub Desktop.
Center an object with inertia, regardless of it's registration point.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stage.addEventListener(Event.ENTER_FRAME, centerIt); | |
function centerIt(e:Event){ | |
var boundsRect:Rectangle = mc.getBounds( this ); | |
targetX = ( ( stage.stageWidth - mc.width ) / 2 ) - ( boundsRect.left - mc.x ); | |
targetY = ( ( stage.stageHeight - mc.height ) / 2 ) - ( boundsRect.top - mc.y ); | |
mc.x += ( targetX - mc.x ) / 4; | |
mc.y += ( targetY - mc.y ) / 4; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment