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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:40:47+00:00 2026-05-26T15:40:47+00:00

I have created a box2d world, and I wanted to limit the height of

  • 0

I have created a box2d world, and I wanted to limit the height of the world.
I did search google and apparently there was an option in the previous version of box2d where you would have to define the size of your world, but I am not sure if you were able set the height of the world but in the current version they have taken that option completely off.

So I am just looking for a way to limit the height, as my player is a ball that jumps up and down and I want to limit how high it can jump (the jumps are done by physics and gravity and the speed of the ball so after a few good jumps, the ball jumps really high as its speed increases and I dont want to limit the speed) and put border on let say y=900.

  • 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-26T15:40:47+00:00Added an answer on May 26, 2026 at 3:40 pm

    The Box2D world has an infinite size. You can’t limit the world, but you can create a shape that encloses a certain area in the Box2D world.

    Here’s how to create a body and shape that puts a shape just around the screen, so that objects don’t leave the screen. It is easy to adapt this code by changing the corner coordinates to fit whatever you need:

            // for the screenBorder body we'll need these values
            CGSize screenSize = [CCDirector sharedDirector].winSize;
            float widthInMeters = screenSize.width / PTM_RATIO;
            float heightInMeters = screenSize.height / PTM_RATIO;
            b2Vec2 lowerLeftCorner = b2Vec2(0, 0);
            b2Vec2 lowerRightCorner = b2Vec2(widthInMeters, 0);
            b2Vec2 upperLeftCorner = b2Vec2(0, heightInMeters);
            b2Vec2 upperRightCorner = b2Vec2(widthInMeters, heightInMeters);
    
            // static container body, with the collisions at screen borders
            b2BodyDef screenBorderDef;
            screenBorderDef.position.Set(0, 0);
            b2Body* screenBorderBody = world->CreateBody(&screenBorderDef);
            b2EdgeShape screenBorderShape;
    
            // Create fixtures for the four borders (the border shape is re-used)
            screenBorderShape.Set(lowerLeftCorner, lowerRightCorner);
            screenBorderBody->CreateFixture(&screenBorderShape, 0);
            screenBorderShape.Set(lowerRightCorner, upperRightCorner);
            screenBorderBody->CreateFixture(&screenBorderShape, 0);
            screenBorderShape.Set(upperRightCorner, upperLeftCorner);
            screenBorderBody->CreateFixture(&screenBorderShape, 0);
            screenBorderShape.Set(upperLeftCorner, lowerLeftCorner);
            screenBorderBody->CreateFixture(&screenBorderShape, 0);
    

    Note: this code is for Box2D v2.2.1. I assume that’s what you’re using because you said “previous version” which required this code to be written differently (with the SetAsEdge method).

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

Sidebar

Related Questions

I have installed Python 2.6.6 and Box2D 2.0.2b1. And can't create box2d world -
I have around 10 bodies in my Box2D sample app which i have created
I have a TextReader which has been created by a black-boxed system so I
I have created a QWidget with a bunch of QToolButtons in it and I
I have created 3 classes as following Ext.mine.TextParent - Inherting from Textfield Ext.mine.child.TextChildA -
I have created some JQuery that will expand a div 'popup' on hover and
I have created a JSP / servlets application running in Tomcat 7. It runs
I have created an EDMX in visual studio 2010 SP1. It has been built
I have created an android application that calls (using kSOAP library) a SOAP based
I have created a custom post type named People. I have created a page

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.