Skip to content

Instantly share code, notes, and snippets.

@mattlundstrom
Created October 25, 2013 21:52
Show Gist options
  • Save mattlundstrom/7162384 to your computer and use it in GitHub Desktop.
Save mattlundstrom/7162384 to your computer and use it in GitHub Desktop.
Center an object with inertia, regardless of it's registration point.
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