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 6532197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:58:16+00:00 2026-05-25T09:58:16+00:00

I have sprites(which have bodies) that can fall down into a box, in a

  • 0

I have sprites(which have bodies) that can fall down into a box, in a b2world.

I wonder in what way should I define that box body, so only when another body hit it from upside, it looks like he went inside that box, and I don’t see it anymore ..

should I just put it in another z layer?
how can I define a body to be open in its upside only ?

I have created the body like this:

-(void)basket //TAG5
{
    //define sprite
    basket=[CCSprite spriteWithFile:@"basket.png"];
    basket.tag=5;
    basket.position=ccp(200,50);
    b2BodyDef spriteBodyDef;
    spriteBodyDef.type = b2_staticBody;
    spriteBodyDef.position.Set(basket.position.x/PTM_RATIO,basket.position.y/PTM_RATIO);
    spriteBodyDef.userData = basket;
    basket1Body = world->CreateBody(&spriteBodyDef);

    b2PolygonShape spriteShape; //b2polygon-for box shape
    spriteShape.SetAsBox(basket.contentSize.width/PTM_RATIO/2,basket.contentSize.height/PTM_RATIO/2); //for b2polygon
    b2FixtureDef spriteShapeDef;
    spriteShapeDef.shape = &spriteShape;
    spriteShapeDef.density = 10.0;
    spriteShapeDef.isSensor = false;
    stand1Body->CreateFixture(&spriteShapeDef);
    [self addChild:basket]; 
}

I am using cocos2d and box2d.
any explanation of a simple way of doing this will be appreciate .

  • 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-25T09:58:16+00:00Added an answer on May 25, 2026 at 9:58 am

    To make the box you could use three polygons (left and right walls, and bottom), or edge shapes. Then yes, just draw something over the top so that the objects are hidden when they go into that area.

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

Sidebar

Related Questions

i have many sprites in my game,which all have bodies in a b2world. and
How can I have that functionality in my game through which the players can
I have a mutable array which stores sprites but the problem is that the
I have two sprites in my app. Both should have touches enabled and both
I have written code that automatically creates CSS sprites based on the IMG tags
I have an image file that has all the character sprites that I will
I have sprites which are spawning from bottom to top. They are coming randomly
I have some images which I would like to use as sprites in my
First i have scaled the layer larger which contains the sprites. Now I need
I have a sprite in which I have added other sprites. Something like: var

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.