A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: HitTest to circle

  1. #1
    Junior Member
    Join Date
    Feb 2008
    Posts
    29

    HitTest to circle

    I'm creating a stealth game with an overhead view where you need to avoid spotlights. The character you control is a square movieclip so the bounding box hit test is fine. However the spotlights are circles so the bounding box hitTest isn't going to work. I also need it to register the hitTest if the objects are at all touching, not just if certain points on them are touching. what's the best way to do this?

  2. #2
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    http://www.kirupa.com/developer/acti...pt/hittest.htm

    Btw, read up on the forum rules, your footer image is way over the limit.



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


  3. #3
    Junior Member
    Join Date
    Feb 2008
    Posts
    29
    Thanks.

  4. #4
    Musical chair sumwungye's Avatar
    Join Date
    Jan 2008
    Location
    Planet Earth, third planet from the Sun
    Posts
    287
    When you say, "Thanks..." does that mean thanks to the footer problem or the hittest problem? Because if it's the hittest problem, I can help.

    Add the following code to your character.

    Code:
    if (this.hitTest(spotlight1)) {
    gotoAndStop ("gameover");
    } else if (this.hisTest(spotlight2)){
    gotoAndStop ("gameover");
    }
    Repeat this for all of your other spotlights, and my guess is that this is what you need.
    --SumWunGye

  5. #5
    Musical chair sumwungye's Avatar
    Join Date
    Jan 2008
    Location
    Planet Earth, third planet from the Sun
    Posts
    287
    Oh, and by the way, you could use this same method, replacing "gotoAndStop ("gameover");" with whatever you need to all of the spotlights, to keep them from touching.
    --SumWunGye

  6. #6
    Musical chair sumwungye's Avatar
    Join Date
    Jan 2008
    Location
    Planet Earth, third planet from the Sun
    Posts
    287
    ...If that's what you mean by
    Quote Originally Posted by Emasher
    I also need it to register the hitTest if the objects are at all touching
    ...
    --SumWunGye

  7. #7
    [Horse Thief] gotoAndCrash's Avatar
    Join Date
    May 2007
    Location
    NW, USA
    Posts
    576
    Here's a post I made regarding "hitTesting" to circles using the Pythagorean Theory :

    http://board.flashkit.com/board/showthread.php?t=753299
    1 Infinite Loop, Cupertino is a portal of Hell.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center