# Restricting movement

**URL:** https://forum.kirupa.com/t/restricting-movement/241738
**Category:** programming
**Created:** [October 17, 2007, 3:13pm UTC](https://forum.kirupa.com/t/restricting-movement/241738 "2007-10-17T15:13:44Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![leonthelion](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@leonthelion](https://forum.kirupa.com/u/leonthelion)
#### Post date: [October 17, 2007, 3:13pm UTC](https://forum.kirupa.com/t/restricting-movement/241738/1 "2007-10-17T15:13:44Z")

</div>

I’m having a problem with this. Heres the code I use to stop me from moving out of the bottom of the screen:

```php
 
 //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;
  }

```

this (I think) makes you not able to move out the top of the screen:

```php
 //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 stop the player from moving out the right side of the screen:

```php
 
if((this._x+this._width)>Stage.width){
   this._x=Stage.width-this._width;
  }
  if(this._x<0){
   this.x=0;
  }

```

this one isn’t working though it stops you from moving out of the left of the screen:

```php
 
   if((this._x+this._width)>Stage.width){
   this._x=Stage.width-this._width;
  }
  if(this._x>550){
   this.x=550;
  }

```

Thanks for helping.
