Skip to content

Instantly share code, notes, and snippets.

@anuraghazra
Created May 16, 2019 12:36
Show Gist options
  • Save anuraghazra/fe9b603e38cf8b4c4387642b3d5441af to your computer and use it in GitHub Desktop.
Save anuraghazra/fe9b603e38cf8b4c4387642b3d5441af 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