Be a Supporter!

How can you limit an object's range

  • 555 Views
  • 3 Replies
New Topic Respond to this Topic
lapslf
lapslf
  • Member since: Aug. 11, 2001
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
How can you limit an object's range 2002-01-15 11:37:37 Reply

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
Response to How can you limit an object's range 2002-01-15 16:48:25 Reply

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
Response to How can you limit an object's range 2002-01-16 09:29:48 Reply

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
Response to How can you limit an object's range 2002-01-16 22:47:44 Reply

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