How can you limit an object's range
- lapslf
-
lapslf
- Member since: Aug. 11, 2001
- Offline.
-
- Forum Stats
- Member
- Level 08
- Blank Slate
I've got a keyboard controlled object, and i want to make it impossible to send it out of the screen, understand what i mean? what code/tegnique do i have to use for this?
- BANE
-
BANE
- Member since: Apr. 14, 2000
- Offline.
-
- Forum Stats
- Member
- Level 12
- Blank Slate
simple. make the actions on the clip that's going to move as follows:
onClipEvent(enterFrame){
if(Key.isDown(Key.UP) and _y>0){
_y-=5
} else if(Key.isDown(Key.DOWN) and _y<400){
_y+=5
}
if(Key.isDown(Key.LEFT) and _x>0){
_x-=5
} else if(Key.isDown(Key.RIGHT) and _x<550){
_x+=5
}
}
substitute different numbers in for different boundaries. also, make sure this code is on the clip itself. just click on it on while on the main timeline, and open the actions panel.
-BANE
- lapslf
-
lapslf
- Member since: Aug. 11, 2001
- Offline.
-
- Forum Stats
- Member
- Level 08
- Blank Slate
OK thanx, but now that i use this code, the movespeed doesn't work anymore. how do i fix that?
- BANE
-
BANE
- Member since: Apr. 14, 2000
- Offline.
-
- Forum Stats
- Member
- Level 12
- Blank Slate
um, i'm gonna take a stab at guessing what you're talking about here... change that 5 to _root.movespeed, then you can alter that elsewhere
-BANE

