Mega Bubble live & free on App Store :)

Mega Bubble is on the app store.. check it out, it’s free and fun!

box2d enable collisions between static/kinematic bodies

subclass b2body.cpp’s bool b2Body::ShouldCollide(const b2Body* other) const

or just comment out:

if (m_type != b2_dynamicBody && other->m_type != b2_dynamicBody)
    return false;

This is useful if you may need kinematic/static bodies to listen to collisions between each and also want to move them using cocos2d actions.

XCode behaviour

If you add abc.png to your app’s resources, build & run in the simulator/on device, then remove that file or rename it, it will still exist on the simulator/on device. This appears to be the case with shared libraries as well.

So make sure you remove your app/game from the test devices you were using during development, clean, then build & run in order to test a final time before final submission and after you’ve finished any modifications.

Using flood-fill to find unconnected nodes in bubble game

A previous blog post solved this algorithm with a recursive method.  Since then, it became necessary to improve the speed a little.

We will solve it the same way, using the flood/seed-fill algorithm (commonly used in graphics-editing programs Fill/Paint Bucket tool), but improve it by making it iterative and using c++ STL’s stack, vector, and map containers.

-(void) flagConnectedWithIndex:(int)index
    Enemytarget *targ = mapAllEnemies_[index];
    targ.connected = YES;

    stack stack;

    while(!stack.empty()) {
        int currIdx =;

        vector neighbors = [self getNeighborsWithIndex:currIdx];
        for(unsigned int x = 0; x < neighbors.size(); x++) {
            int neighborIdx = neighbors[x];

            if(mapAllEnemies_[neighborIdx] != nil) {
                Enemytarget *t = mapAllEnemies_[neighborIdx];

                if(!t.connected) {
                    t.connected = YES;

In this method, mapAllEnemis_ is a 1d sparse index array containing all of the bubbles. It is using STL’s map. getNeighborsWithIndex is also using the STL vector class. If we use swap this class to return an NSArray of NSNumber objects, the flagConnectedWithIndex method finishes much more slowly.

In the screenshot, you see there are 9 nodes/bubbles max. per row. On even rows with the black labels, the row is shifted to the right 16 px. On odd rows, shifted to the left.

-(std::vector) getNeighborsWithIndex:(int)index
    vector surrIndices;         

    // right - black labels in screen cap
    if(index/Grid_Num_H %2 == 0) {
        if( (index+1) %Grid_Num_H != 1) {
            surrIndices.push_back( index - 1); // left
            surrIndices.push_back(index - Grid_Num_H -1); // bottom left
            surrIndices.push_back(index + Grid_Num_H -1); // top left
        if( (index+1)  % Grid_Num_H != 0)
            surrIndices.push_back(index +1); // right

        surrIndices.push_back(index - Grid_Num_H); // bottom right
        surrIndices.push_back(index + Grid_Num_H); // top right
    // left (white labels in screen capture)
    else {
        surrIndices.push_back(index - Grid_Num_H); // bottom left
        surrIndices.push_back(index + Grid_Num_H); // top left

        if(index % Grid_Num_H != 0 )
            surrIndices.push_back(index - 1); // left

        if(index % Grid_Num_H != 8 ) {
            surrIndices.push_back(index + 1); //right
            surrIndices.push_back(index - Grid_Num_H + 1); // bottom right
            surrIndices.push_back(index + Grid_Num_H + 1); // top right
    return surrIndices;