Skip to content

Instantly share code, notes, and snippets.

@unstoppablecarl
Created March 13, 2013 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save unstoppablecarl/5152423 to your computer and use it in GitHub Desktop.
Save unstoppablecarl/5152423 to your computer and use it in GitHub Desktop.
updateSize: function(width, height){
// get current center
var centerX = this.pos.x + this.size.x/2,
centerY = this.pos.y + this.size.y/2;
// set new width / height
this.size.x = width;
this.size.y = height;
// make the center coord match what it was previously
this.pos.x = centerX - this.size.x/2;
this.pos.y = centerY - this.size.y/2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment