Skip navigation
sachin_mak
Currently Being Moderated

How to set boundaries??

May 25, 2012 3:40 AM

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.

 
Replies
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    May 25, 2012 8:24 AM   in reply to sachin_mak

    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.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    May 25, 2012 10:27 PM   in reply to sachin_mak

    use:

     

    this.onEnterFrame=function(){

    if(!man_mc.hitTest(road_mc)){

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

    }

    }

     
    |
    Mark as:
  • Currently Being Moderated
    May 26, 2012 5:27 AM   in reply to sachin_mak

    try:

     

    trace("Does not hit!!!");

     

    instead, it will work.

     

    Yes, the ! means NOT

    so:

     

    IF NOT HITTEST = TRUE THEN

    TRACE "Not hitting"

    END IF

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    May 26, 2012 7:11 AM   in reply to sachin_mak

    use:

     

    trace(man_mc);

    trace(road_mc);

    this.onEnterFrame=function(){

    if(!man_mc.hitTest(road_mc)){

    trace("off");

    }

    }

     

    and move your man_mc completely off of road_mc.  copy and paste the first few lines of the text in your output panel.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    May 28, 2012 6:02 AM   in reply to sachin_mak

    1.  you should mark helpful/correct answers.

     

    2.  what do you want to click to trigger a hittest?

     

    3.  what do you want to click to move your man_mc?

     

    4.  in what direction do you want to move man_mc when whatever you answer in 3 is clicked?

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points