Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8040371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:52:28+00:00 2026-06-05T03:52:28+00:00

I have around 10 bodies in my Box2D sample app which i have created

  • 0

I have around 10 bodies in my Box2D sample app which i have created with the help of following method. But in my Update method i want get the b2FixtureDef of the bodies because i need there filter.groupIndex which is different for every body. I have the Update method as follows which loops thru all the b2Body but cant really find how to get the b2FixtureDef from b2Body??

-(void) addNewSprite:(NSString *)spriteName AtPosition:(CGPoint)p isDynamic:(BOOL)dynamic
{
    //CCNode *parent = [self getChildByTag:kTagParentNode];

PhysicsSprite *sprite = [PhysicsSprite spriteWithFile:spriteName];

[self addChild:sprite];

sprite.position = ccp( p.x, p.y);

sprite.tag = check;

// Define the dynamic body.
//Set up a 1m squared box in the physics world
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;  
bodyDef.position.Set(sprite.position.x/PTM_RATIO, sprite.position.y/PTM_RATIO);
bodyDef.userData = sprite;
b2Body *body = world->CreateBody(&bodyDef);

// Define another box shape for our dynamic body.
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox((sprite.contentSize.width/PTM_RATIO/2)*(sprite.scaleX),
                    (sprite.contentSize.height/PTM_RATIO/2)*(sprite.scaleY));//These are mid points for our 1m box

// Define the dynamic body fixture.
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox; 
fixtureDef.density = 1.0f;
fixtureDef.friction = 1.0f;
fixtureDef.userData = sprite;

switch (check)
{
    case 1:
        fixtureDef.filter.categoryBits = 0x0002;

        fixtureDef.filter.maskBits = 0x0004;
        break;
    case 2:
        fixtureDef.filter.categoryBits = 0x0004;

        fixtureDef.filter.maskBits = 0x0002;
        break;
}

body->CreateFixture(&fixtureDef);

[sprite setPhysicsBody:body];

check++;
}

-(void) update: (ccTime) dt
{
    //It is recommended that a fixed time step is used with Box2D for stability
    //of the simulation, however, we are using a variable time step here.
    //You need to make an informed choice, the following URL is useful
    //http://gafferongames.com/game-physics/fix-your-timestep/

int32 velocityIterations = 8;
int32 positionIterations = 1;

// Instruct the world to perform a single step of simulation. It is
// generally best to keep the time step and iterations fixed.
world->Step(dt, velocityIterations, positionIterations);    

for(b2Body *b = world->GetBodyList(); b; b=b->GetNext()) {    

    if (b->GetUserData() != NULL) 
    {

        //b2Fixture fixtureDef = *b->GetFixtureList();
        //b2Filter filter = fixtureDef.GetFilterData();

        // how to get b2FixtureDef from b

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:52:29+00:00Added an answer on June 5, 2026 at 3:52 am

    Actually, i cannot imagine why do you need to get this info in your update method. You cannot get fixtureDef, as it is used for fixture creation only. But you can get filter data for each body fixture using GetFilterData() method. It will contain category bits, mask bits and group index.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have around 100 rows of text that I want to tokenize, which are
I have around 5 GB of html data which I want to process to
i have around 1000 of rows in database which i want to divide in
I have around 10 System.Drawing.Bitmap elements, which I want to dump to PDF. When
I have around 100 csv files with common headers, which i want to merge.
I have around 40 aspx pages in my website. I want to use a
I have around 3 websites residing in a server which is being shared with
I have around 4000 entities that I need to insert into a Java App
I have around fifty migrations in my store app, some of them are schemamigration
I have around 3000 SWF files, some are interactive which has lots of actionscripts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.