# Limiting player movement

**URL:** https://forum.kirupa.com/t/limiting-player-movement/241481
**Category:** Uncategorized
**Created:** [October 14, 2007, 9:26pm UTC](https://forum.kirupa.com/t/limiting-player-movement/241481 "2007-10-14T21:26:47Z")
**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 14, 2007, 9:26pm UTC](https://forum.kirupa.com/t/limiting-player-movement/241481/1 "2007-10-14T21:26:47Z")

</div>

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):

> **[Making movie clip move in random directions](https://www.kirupa.com/forum/showthread.php?t=278057)**
>
> Got a web design/development question or just want to hang out with the most awesome people on the planet? Drop on in!
