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 some strange problem with my game which uses Box2D as physics engine and I'm out of ideas on what I can do to solve it.

My game is a class assignment where I need to build a simple game where the main character moves in a 2D environment while square blocks comes from below him. Each time a collision occurs, that block is attached to the character using a weld joint, when three blocks of the same colors are together, they annihilate themselves(an effect similar to Bejeweled). I'm using a recursive function to iterate through all the attached blocks of a given block to see if there are enough blocks for them to be deleted.

I'm using GetContactList function to iterate through the list of contacts to see which blocks are adjacent to each other. The results are quite disappointing, the blocks only get annihilated in few cases. After a lot of debugging, I found the issue, but I still don't know how to solve.

My issue is: after some time, GetContactList STOPS returning contacts (return NULL) to blocks that were already attached for some time. I spent some time reading the Box2D manual as well as some tutorials and still didn't find any clue of what is happening.

Below there's some simplified version of the code that I wrote.

for(int a = 0; a < blocksList.size(); a++)
{
   blocksList[a].BuildConnections();
}

And on BuildConnections

b2ContactEdge* edge = body->GetContactList();
while(edge != NULL)
{
   if (long_check_to_see_if_there's_a_block_nearby)
   {
       // add itself to the list to be anihilated
       globalList.push_back(this);
       //if there's, call BuildConnections again on the adjacent block
       adjacentBody->GetUserData()->BuildConnections;
   }
   edge = edge->next;
}

I know that there's another issue related to circular inclusions, but I fairly sure that this problem isn't causing the problem with the collisions.

You can download my entire code from this page if you'd like http://code.google.com/p/fellz/source/list

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I just solve the problem using a tip given by an user on Box2D forums, which I gonna reproduce here to help other people who might come into this problem as well.

irresistible force wrote:

Joints have a collideConnected property which is usually set to false by default, so that any collisions between the two joined bodies are ignored. Maybe you just need to set this to true.

share|improve this answer

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.