Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My advice would be to keep track of the fixtures during construction. You have to create these fixtures at some point, right? Because you didn't tag any specific version of box2d I'll assume you're using the c++ version.</p> <p>box2d allows you to <a href="http://www.learn-cocos2d.com/api-ref/1.0/Box2D/html/classb2_fixture.html#a3db7f89ef4493247d922fe3d96351ad9" rel="nofollow"><code>SetUserData</code></a> for the fixture. If you are not already using the <code>userData</code> then you can use this to refer to an object that stores the fixture's neighbors. A simple structure might look like this:</p> <pre><code>struct FixtureNeighbors { b2Fixture* leftNeighbor; b2Fixture* rightNeighbor; }; </code></pre> <p>During construction of the fixtures, you should create a <code>FixtureNeighbors</code> object, cast it as a <code>void*</code>, and call <code>b2Fixture::SetUserData</code>. Then, during the game, whenever you want to find out who a fixture's neighbors are just call <code>b2Fixture::GetUserData</code>, cast the result back to a <code>fixtureNeighbors</code> object, and use that to access the left and right neighbors.</p> <p><strong>Notes</strong></p> <p>If you are already using the fixture <code>userData</code> to point to an entity or something else, you should add a <code>GetEntity</code> method to your <code>FixtureNeighbors</code> structure and you can still access the entity if you have the fixture.</p> <p>If a fixture can be touching more than two neighbors, just use an stl <code>vector</code> to store a list of them.</p> <p>I hope this helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload