Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I just want to know if there is a way in java to detect when the character is on an item on the floor without without verifying if every items on the map contains the character or vice versa in every iteration.

share|improve this question

1 Answer 1

A common way to do this is to divide the game world into tiles (which is something you may want to do for other reasons too) and have each tile store a list of the items in it. That way, you only have to check the items that are in the same tile as the character (or possibly in an adjacent tile, if the items and/or the character can overlap several tiles).

If you have a large world with items scattered sparsely in it, you may also try fancier spatial subdivision techniques like quadtrees. In any case, the principle is the same: divide the world into chunks, assign each item or character into a chunk based on their location, and only check for collisions between things in the same or in adjacent chunks.

share|improve this answer
    
ok thank you i think i understand –  wineangel Apr 28 '13 at 23:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.