Skip navigation
Currently Being Moderated

Create smart hit test checks?

May 19, 2012 11:42 PM

I'm working on a TD game, nothing special but to learn flash.

 

What I am currently doing is placing monsters on the map, and each monster loops through an array of the towers ranges each frame to see if it's in range of any of the towers.  It works well but I'm wondering if there's a way to make it better.

 

 

Is there a way to make the hit test smarter where every monster doesn't need to hit-test every tower? The only things I have been able to come up with involve further checking that would end up being more complicated then the simple hit test.

 

Note: I'm not using hitTest(), I'm using different maths to figure it out.

 

 

Thanks in advance.

 
Replies
  • Currently Being Moderated
    May 20, 2012 4:28 AM   in reply to ImperialUser

    If you show what you are currently doing it will be easier to tell if there is a smarter way.  If there is a chance that any monster can be in range of any tower, then you need to check every tower.

     

    One idea as an alternative would be to add invisible (alpha = 0) portions surrounding the towers that represents the range and use a hitTest to detect when they are within range, but I still see a need to check against all towers, at least all towers within a region.

     

    In terms of regions you could have different regions defined/.assigned to each monster when they get planted such that you only check towers within the region.

     
    |
    Mark as:
  • Currently Being Moderated
    May 20, 2012 10:02 PM   in reply to ImperialUser

    Recursive dimensional clustering http://lab.polygonal.de/?p=120

    Quadtree http://lab.polygonal.de/?p=202

     
    |
    Mark as:
  • Currently Being Moderated
    May 22, 2012 10:33 PM   in reply to ImperialUser

    I've never implemented one. So I'm not sure of all the details. There are lots of demos out there (mostly in other languages, but the ideas should be pretty similar.) I would probably start here: http://www.gamedev.net/page/resources/_/technical/graphics-programming -and-theory/quadtrees-r1303

     

    Remember that some kinds of operations are more "expensive" than others. So managing some arrays (or vectors) is likely to take less time than performing hit tests.

     
    |
    Mark as:
  • Currently Being Moderated
    May 22, 2012 10:39 PM   in reply to Rothrock
     
    |
    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