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.

Ok, this may be hard to understand, but I'll do my best.

You will see that the first image is a normal mario, and the other is the result I am looking for. I'm trying to find a way to extract rectangles (biggest possible to smallest) from a texture2D, without overlapping rectangles. If the pixel is completely transparent, leave it out of the loop. I know it would be really easy to implement a rectangle for every pixel, but millions of rectangles isn't going to help performance wise. The goal is to get rectangles somewhat like this, decreasing the total rectangles greatly.

Any ideas or links? Anything would be great.

share|improve this question
2  
Why? (I smell a classic X Y Problem) –  Seth Battin Mar 8 '13 at 4:56
    
Lol, I'm partly wanting to try this as a different way of collision detection, but I can also see more uses for it as well. I know and use other ways of collision detection, but I would just like to see what I can use it for. Though, I'm not looking for ways to detect collision, I am looking to see if this is do-able, and what I can use it for. Why not? –  RustyGearGames Mar 8 '13 at 5:41
    
Why not just put a box around the sprite completely? I mean, a sprite like that looks like unless your game really demands it a box around the edge of the sprite will probably cut it... that's how Super Mario was implemented, fyi. –  Vaughan Hilts Mar 8 '13 at 6:17
1  
Throw the colors into a 2D array. If element is transparent go to next else store where element is as a subX, subY and move to next element until you hit transparency. throw subX, subY, difference of current X/Y from subX/Y as width/height (height is 1 if no difference) into a list of rectangles. Use Rectangle.Union() to join rectangles. Probably in a similar fashion to how you got them in the first place. Can't justify actually trying to implement it, but best of luck to you. –  Dialock Mar 8 '13 at 7:41
1  
There are multiple duplicate questions of this with different terminology. See for example stackoverflow.com/questions/5919298/… and the linked questions. –  msell Mar 12 '13 at 20:44
show 2 more comments

1 Answer 1

Honestly, this is a solution in search of a problem. I can't see any benefits towards doing such a thing, and it doesn't seem like you can think of any either. Best just to take existing solutions and run with those. (and chances are "a new way of doing collision detection" will suck, when pretty damn smart people like the chipmunk physics and box2d devs are regularly improving their algorithms).

You're creating more rectangles when that's the wrong way to go about it.

What you should be doing is creating one polygon from a trace/outline of the sprite. There are loads of algorithms out there which can do it, including marching squares/cubes. Chipmunk Physics (Pro) even has the ability to construct physics objects from traces, as do several other physicy things that I am aware of.

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.