Skip to main content
Known Participant
May 25, 2012
Answered

How to set boundaries??

  • May 25, 2012
  • 1 reply
  • 1937 views

hello every one,

I want a man_mc to walk just on  the road. But i dunno how to set boudaries so that mine man_mc doesn't go outside of road.

Plz help.

This topic has been closed for replies.
Correct answer kglad

use:

this.onEnterFrame=function(){

if(!man_mc.hitTest(road_mc)){

// do whatever.  your man is completely off the road

}

}

1 reply

kglad
Community Expert
Community Expert
May 25, 2012

if your road is close to rectangular or can be approximated by several rectangular shapes you can use the hitTest to determine when your character goes outside the rectangular shapes.

if you want more accuracy or can't use rectangular shapes, you can use the bitmapData's hittest.

Known Participant
May 26, 2012

thank you.

but actually i dunno how to check hit of one object with another object.!

my road is in rectangular shape. my man_mc is on road_mc. now how to add hit test and where to put it?

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 26, 2012

use:

this.onEnterFrame=function(){

if(!man_mc.hitTest(road_mc)){

// do whatever.  your man is completely off the road

}

}