Edge tracing / b2ChainShape creation for tile based games

Post your tutorials and samples here.
QuadrupleA
Posts: 8
Joined: Sun Mar 24, 2013 9:29 pm
Contact:

Edge tracing / b2ChainShape creation for tile based games

Postby QuadrupleA » Sat Jun 29, 2013 1:18 pm

Had a thought the other day that I should share some code I wrote for tracing the edges of solid tiles in a tile-grid based game prototype I made - I did a cursory search online and didn't find anything like it before I started. The algorithm is straightforward enough but there are a fair number of steps.

It basically breaks an arbitrary-sized tile world into "chunks" (e.g. 10x10 tiles), and within each chunk traces the edges between solid & empty, joins them to create as few vertices & discontinuities as possible, and creates b2ChainShape's to accomodate. Here's a visual example from the game prototype I used it on (SubMiner):

Image

If anyone would find this useful let me know, and I'll separate out the code and post it. The code is prettier than the placeholder graphics :). It's C++, using a bit of the STL (mainly vector<> I think). The one addition I didn't get time for was, between 10x10 chunks, to create "ghost vertices" in adjoining chain segments (the prototype I was working on didn't need it).

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Edge tracing / b2ChainShape creation for tile based game

Postby irresistible force » Sat Jun 29, 2013 9:18 pm

Nice!
People using Tiled might like to have that too, not sure if there are forums for it?

howbizarre79
Posts: 8
Joined: Sun Jun 30, 2013 10:09 am

Re: Edge tracing / b2ChainShape creation for tile based game

Postby howbizarre79 » Tue Jul 02, 2013 8:39 am

Awesome. This will be extremely useful for us. Will you be willing to share the code or the algorithm you are using?

Regards

jalfonsosm
Posts: 18
Joined: Fri Nov 12, 2010 1:38 am

Re: Edge tracing / b2ChainShape creation for tile based game

Postby jalfonsosm » Thu Sep 05, 2013 12:00 am

Awesome, congrats!
I was searching something like that. Do you plan publish the source code? Would be helpful for may developers!

DrTwox
Posts: 5
Joined: Fri Nov 29, 2013 10:30 pm

Re: Edge tracing / b2ChainShape creation for tile based game

Postby DrTwox » Fri Nov 29, 2013 10:37 pm

Any progress on a source code release?

jalfonsosm
Posts: 18
Joined: Fri Nov 12, 2010 1:38 am

Re: Edge tracing / b2ChainShape creation for tile based game

Postby jalfonsosm » Wed Mar 12, 2014 6:32 am

At the end I used this approach:

http://www.learn-cocos2d.com/2013/06/ge ... s-cocos2d/

You can find the full project in this tutorial.


Return to “Tutorials and Samples”



Who is online

Users browsing this forum: No registered users and 1 guest