Currently Browsing

Posts Tagged ‘ cocos2d ’

Cocos2D: Box2D change filter dimensions

If you ever need to change the size of a b2PolygonShape, use the following code snippet:

for (b2Fixture *fixture = playerBody->GetFixtureList(); fixture != NULL; fixture = fixture->GetNext())

            b2PolygonShape* shape = (b2PolygonShape*)fixture->GetShape();

            int iFixtureSizeW1 = 200;
            int iFixtureSizeY1 = 200;

            b2Filter objectFilter = fixture->GetFilterData(); // Object's filter data

                shape->m_vertices[0].Set(-iFixtureSizeW1, -iFixtureSizeY1);
                shape->m_vertices[1].Set( iFixtureSizeW1, -iFixtureSizeY1);
                shape->m_vertices[2].Set( iFixtureSizeW1,  iFixtureSizeY1);
                shape->m_vertices[3].Set(-iFixtureSizeW1,  iFixtureSizeY1);


Cocos2D: Changing Filter Data During Gameplay

I’ve been working on making Sewer Wars gaming experience easier for the player. I found an easy solution: disabling collisions between player and enemy objects when the player is jumping and the enemy object is close to it. With this easy to implement solution the player will not die or get hurt (collide) when doing a jump when being very close to the enemy object.

Add this code to the function you’ll call when the player (is jumping) and enemy objects are close enough:

b2Filter filterData;
filterData = b->GetFixtureList()->GetFilterData();
filterData.maskBits = 0xFFFF ^ (0x0002); // Add the categoryBits you want your enemy object to ignore

b is a b2Body of your enemy. So in the above code, you are changing b’s enemy filter data to ignore collisions with the player’s categoryBits (0×0002).

If you don’t know what maskBits are or how collision filtering works, read my Cocos2D/Box2D Collision Filtering tutorial.

Cocos2D/Box2D Endless Platformer

It’s been a long time since my last iDevBlogADay contribution. I’ve been (and still am) very busy, but wanted to share with you this code. I’m working on an endless platformer game ( and i didn’t find any tutorial or source code to help me start with the development so I’m sharing with the Cocos2D community part of my code.

I did find a tutorial from (some of my code uses snippets from this tutorial) which helped me understand how to move Box2D objects.

With this demo you will be able to:

- Create endless platforms
- Build platforms with different sizes
- Position platforms in random positions
- Assign three CCSprite to the Box2D platform (see figure 1)

The code is optimized for iPhone retina, but with some minor modifications you can make it work under iPhone & iPad screens.

If you find any bugs or can optimize the code please let me know!

Click here to download the source code.

Sewer Wars Trailer

Trailer for the upcoming iOS game SEWER WARS! Check out for updates!

Sewer Wars Trailer from devround on Vimeo.

Sewer Wars Developer Diary

This is Sewer Wars ( main character’s Texture Atlas, getting big!