Skip to content

Instantly share code, notes, and snippets.

@anuraghazra
Created May 16, 2019 12:38
Show Gist options
  • Save anuraghazra/c28025638fe302785b5f94be57743e78 to your computer and use it in GitHub Desktop.
Save anuraghazra/c28025638fe302785b5f94be57743e78 to your computer and use it in GitHub Desktop.
constrain() {
if (this.pos.x > CANVAS_WIDTH - this.radius) {
this.pos.x = CANVAS_WIDTH - this.radius;
}
if (this.pos.x < this.radius) {
this.pos.x = this.radius;
}
if (this.pos.y > CANVAS_HEIGHT - this.radius) {
this.pos.y = CANVAS_HEIGHT - this.radius;
}
if (this.pos.y < this.radius) {
this.pos.y = this.radius;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment