Skip to content

Instantly share code, notes, and snippets.

@unstoppablecarl
Created March 13, 2013 14:06

Revisions

  1. unstoppablecarl created this gist Mar 13, 2013.
    14 changes: 14 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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;
    }