How can you make it so that the player can’t go out of the screen? I have this code which works fine but only makes it not able to go out of the top and bottom:
//if the player moves below the stage area, move it back to the bottom of the stage
if((this._y+this._height)>Stage.height){
this._y=Stage.height-this._height;
}
//if the player moves above the stage area, move it back to the top of the stage
if(this._y<0){
this._y=0;
}
This doesn’t work though, it’s for not being able to move out one of the sides of the screen (not sure which though):
if((this._x+this._width)>Stage.width){
this._y=Stage.width-this._width;
}
if(this._x<0){
this.x=400;
}
Can anyone help with this please?
OFF TOPIC (another question):