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 have a isometric grid with sprites that are placed in this sort of manner:

x: 5
y: 7
OffsetX: 5px
OffsetY: 10px

This is - what i want to do is when placing a new sprite, check to see if they collide, i can do it quite easily by just checking the x and y but the offset confuses me on how i can efficiently check for a collision.

Dose any one have any suggestions on neat ways to efficiently check collisions with offsets?

share|improve this question
    
I assume x and y are the location of the sprite's tile on the isometric grid, and that OffsetX and OffsetY are regular rectangular pixel offsets? You're going to need to define a size for these sprites... once you go beyond "two sprites can't share a tile," you can't get any further without saying "this sprite is a 20x20 pixel box" or "this sprite is a circle with radius 30px." –  John Calsbeek Feb 18 '13 at 3:53
    
I have the image dimensions which i from the image properties like: image.width will equal the image in pixels wide. Although its more complex due to alot of sprite images contain alpha areas. Which is why its hard. –  Dave Feb 18 '13 at 4:08
add comment

1 Answer

up vote 2 down vote accepted

using the dimensions of your 2D sprite representing your isometric object doesn't sound like a solid idea to me. a long object along the x axis might has the same sprite width as an object which is wide along the y axis, but both might have different collision boxes.

I would treat those 2 values seperate and calculate collision using bounding boxes that approximate the dimension in isometric space. the offset makes sense because sometimes its not easy to approximate a box for your object. if you have a tree for example, the crown is going to be much bigger than the actual collisionbox which only includes the trunk, but you also want to have the sprite centered within the box and therefor you move the 2D sprite using your offset values.

enter image description here

The image above shows a large sprite (white), with a small collision box (blue) and some offset is used to center the sprite correctly.

Seperating your visual representation from the collision is the way to go in my opinion, even if objects can't be larger then 1 tile of your grid.

share|improve this answer
add comment

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.