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

  • SEARCH
  • Home
  • 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 7510283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:11:08+00:00 2026-05-29T23:11:08+00:00

ok, im following the RW tutorial on box2d, i have got to the part

  • 0

ok, im following the RW tutorial on box2d, i have got to the part of adding the body to the sprites, ok heres the problem,

i can add the sprite body on the ‘cat’ sprite, but when i try to add a body to the ‘car’ sprite, it just crashes..
it works fine if i only add a body to the ‘cat’ sprite, but why cant i add a body to the ‘car’?
they both use the same method to add a body!

heres the method of adding a body:

- (void)addBoxBodyForSprite:(CCSprite *)sprite {

b2BodyDef spriteBodyDef;
spriteBodyDef.type = b2_dynamicBody;
spriteBodyDef.position.Set(sprite.position.x/PTM_RATIO, 
                           sprite.position.y/PTM_RATIO);
spriteBodyDef.userData = sprite;
b2Body *spriteBody = _world->CreateBody(&spriteBodyDef);

b2PolygonShape spriteShape;
spriteShape.SetAsBox(sprite.contentSize.width/PTM_RATIO/2,
                     sprite.contentSize.height/PTM_RATIO/2);
b2FixtureDef spriteShapeDef;
spriteShapeDef.shape = &spriteShape;
spriteShapeDef.density = 10.0;
spriteShapeDef.isSensor = true;
spriteBody->CreateFixture(&spriteShapeDef);

}

here is the code for the ‘cat’

- (void)spawnCat {

CGSize winSize = [CCDirector sharedDirector].winSize;

CCSprite *cat = [CCSprite spriteWithSpriteFrameName:@"cat.jpg"];

//code here.......


[self addBoxBodyForSprite:cat];
[_spriteSheet addChild:cat];

}

heres the code for the ‘car’

- (void)spawnCar {

CCSprite *car = [CCSprite spriteWithSpriteFrameName:@"car.jpg"];
car.position = ccp(100, 100);
car.tag = 2;

[self addBoxBodyForSprite:car];
[_spriteSheet addChild:car];

}

ok with the above code it crashes, but if i remove [self addBoxBodyForSprite:car]; from the spawnCar method, then it doesnt crash, and only the ‘cat’ has a body, not the ‘car’….need help im very confused at the moment. thanks

  • 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-05-29T23:11:10+00:00Added an answer on May 29, 2026 at 11:11 pm

    Can you set a breakpoint at the beginning of the addBoxBodyForSprite method and step through the code to determine at what point the crash actually occurs? It is important to determine exactly what is causing the issue… everything in your method looks fine, so you would need to ensure that it is in here that the error is actually occurring.

    Search for Xcode Debugging if you don’t know how to do this.

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

Sidebar

Related Questions

I have used the following tutorial for my project . I need to add
Hope someone can help me. I have used the following tutorial as a guide
I have a problem with following tutorial: http://www.mkyong.com/jsf2/jsf-2-internationalization-example/ In faces-context file you have to
I am following this tutorial on creating a top-down car using Box2D: Link: Two
I have done the following tutorial: http://www.anddev.org/networking-database-problems-f29/connecting-to-mysql-database-t50063.html for connecting an android device to an
I have read the following tutorial Uploading Files To the Server Using PHP and
Ok so I actually got to add UINavigationBar inside a UITabBarController using the following
I have been playing with the source code available from the following tutorial .
friends, i am using following tutorial to lazy load list view now problem is
Hi I have used the following tutorial to send email from my application :

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.