Archived

This topic is now archived and is closed to further replies.

Collision Detection with ID3DXSprite

This topic is 5576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m using DirectX8''s ID3DXSprite interface to create a tile-based RPG. I''m making nice progress so far with the engine, however there''s one thing that''s bogging me: how should I handle pixel-perfect collision detection? Any directions or code would be GREATLY appreciated! Thanks in advance

Share this post


Link to post
Share on other sites
I am also working on 2D pixel perfect collision detection using D3DXSprite. So far I've been leaning towards using stencil buffers, But not sure if and how this would work.

[edited by - rambo_bill on September 8, 2002 10:18:54 AM]

Share this post


Link to post
Share on other sites
Suggestion:
Maybe you could lock the surface upon loading and generate a bit collision map ''image'' (0''s and 1''s) - a 1 wherever the alpha is above a certain threshold value.
I have never done this, but am hoping to do something like it soon.

Share this post


Link to post
Share on other sites
stevenmarky has the right idea I think, except for the slight alteration that I would make a tool that can take a list of files or something and generate a file that contains a "map" of the image. Then you can simply load it at start up, as it might take a while to generate those maps when loading, depending on the size and amount of them.

But, do you think you would gain anything from pixel perfect collision detection for a tile based rpg? I mean, sure do it anyway as it''s a great learning experience, but it might be more firepower than you need.

Share this post


Link to post
Share on other sites
I have the exact same problem.
What I need to know is how to find out if a pixel is transparant or not, and then generate a ''collision-map'' from that.

Only problem is that I cant figure out how to do this ''check if pixel is transparant thingy'' with a dx8 sprite interface.
From what I found out this must be done in loading-stadge or be pre-generated to work speedwise.

If someone has a solution it would be very welcome.

Share this post


Link to post
Share on other sites
The problem with the pre-generated map idea for me is that I rotate my sprites using the D3DXSprite draw function at runtime. Now if I could have a single map and some how rotate it with the sprite that would work. Right now I'm thinking of defining shapes that outline the image, then test if these shapes collide. This way the shapes could be rotated with the sprite and provide for fast accurate collision detection. Of course pixel collision detection would be less headaches than this method.

[edited by - rambo_bill on September 9, 2002 7:05:08 AM]

Share this post


Link to post
Share on other sites
Don''t forget you could also try a collision routine where you define multiple rects for every animation. Still doesn''t help too much with on-the-fly rotation though.

Share this post


Link to post
Share on other sites
I''ve used the method Redline suggested, but then again, I haven''t tried it on Mirrored and/or Rotated objects. hmmmm.

-----------------------------
kevin@mayday-anime.com
http://www.mayday-anime.com

Share this post


Link to post
Share on other sites
Thinking about it some more you would probably have to rotate each point of the rectangle for multiple rects if using D3DXSprites rotation ability. Either that or use multiple frames of animation for rotation (each with it''s own rects).

Share this post


Link to post
Share on other sites