|
|
|
#1 |
|
Member
Join Date: Jun 2005
Posts: 45
|
Prevent movement off screen
Hi,
I curretnyl have this code for moving a character left and right on the stage: onClipEvent (load) { speed = 15; } onClipEvent (enterFrame) { if (Key.isDown(Key.LEFT)) { _x -= speed; _xscale = -100; } if (Key.isDown(Key.RIGHT)) { _x += speed; _xscale = 100; } } Is there a way I can make it so that when the player reaches a certain point at the ede of the screen it will prevent them from moving further i nthat direction (perhaps something where once it reaches a certain distance to the left then only the right key will work) Thanks |
|
|
|
|
|
#2 |
|
Junior Member
Join Date: Feb 2007
Posts: 3
|
I Add some code with urs!
onClipEvent (load) {
speed = 15; } onClipEvent (enterFrame) { if (Key.isDown(Key.LEFT)) { preXcor=_x; _x -= speed; _xscale = -100; if (_x<0){ _x=preXcor } } if (Key.isDown(Key.RIGHT)) { preXcor=_x; _x += speed; _xscale = 100; tot=_x+this._width if (tot>Stage.width){ _x=preXcor; } } } |
|
|
|
|
|
#3 |
|
Member
Join Date: Jun 2005
Posts: 45
|
That works great
thanks!
|
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|