im working on a javascript game and i don't want the player to be able to leave the canvas. i have made it where you can't leave the bottom or right side like this
this.hitBottom = function(){
var rockbottom = myGameArea.canvas.height - this.height;
var rockside = myGameArea.canvas.width - this.width;
if (this.y > rockbottom) {
this.y = rockbottom;
}
if(this.x > rockside){
this.x = rockside;
}
but i can't figure out how to do the other 2 sides