5.4: Adding Box2D to Processing Sketch Part 1 – The Nature of Code

[ad_1]
This video covers the basics of adding Box2D to a Processing sketch. This is part 1. Part 2 gets to the code.

Read along:

Help us caption & translate this video!


Posted

in

by

Tags:

Comments

4 responses to “5.4: Adding Box2D to Processing Sketch Part 1 – The Nature of Code”

  1. PiYouFree Avatar

    Hello all. I have really big problem. I don't know how to add box2d library to processing and can't move futher with this chapter. Someone can help me? The more detailed explanation wil be, the better 🙂 Thanks in advance.

  2. Appu kumar Avatar

    this is my array of object////////////////////
    public static int maiGameMatrix[][]={ { 1 , 2 , 2 , 2 } ,
    { 2 , 2 , 1 , 2 } ,
    { 2 , 2 , 2 , 2 } ,
    { 1 , 1 , 2 , 2 }

    };
    this is my drawing of object//////////////////////
    private void createBricks()
    {

    BodyDef brickDef = new BodyDef();
    brickDef.type = BodyDef.BodyType.StaticBody;

    brickBody = world.createBody(brickDef);
    CircleShape brickShape = new CircleShape();

    brickShape.setRadius(20/PPM);

    FixtureDef brickFixtureDef = new FixtureDef();
    brickFixtureDef.shape = brickShape;
    brickFixtureDef.density = 10.0f;
    brickFixtureDef.friction = 0.4f;
    brickFixtureDef.restitution = 0.1f;
    brickFixtureDef.filter.categoryBits = B2DVars.BIT_BRICK;
    brickFixtureDef.filter.maskBits = B2DVars.BIT_BALL;

    brickTexture = new Texture(Gdx.files.internal("bubble3.png"));
    brickSprite = new BrickSprite(brickTexture);
    brickSprite.setSize(50/B2DVars.PPM, 50/B2DVars.PPM);

    brickTexture1 = new Texture(Gdx.files.internal("bubble2.png"));
    brickSprite1 = new BrickSprite(brickTexture1);
    brickSprite1.setSize(50/B2DVars.PPM, 50/B2DVars.PPM);

    Vector2 brickPos = new Vector2();
    // brickPos.y = MainScreen.HEIGHT/PPM – 30/PPM;
    float brickWidth = brickSprite.getWidth()/1.3f;
    float brickHeight = brickSprite.getHeight()/1.3f;
    float startY = (MainScreen.HEIGHT – top1) / B2DVars.PPM;
    System.out.println("top1"+top1);

    for (int x = 0; x < maxRows; x++) {
    for (int y = 0; y < maxCols; y++) {
    // totalBricks++;
    l=maxRows-1-x;
    float left =brickWidth+ (brickWidth * y);
    float top= startY+brickHeight+ l * brickHeight;

    if(temGameMatrix[x][y]==1) {

    brickDef.position.set(left, top);
    brickBody = world.createBody(brickDef);
    Fixture brickFixture = brickBody.createFixture(brickFixtureDef);
    brickFixture.setUserData("a1" + x +y);
    brickBody.setUserData(brickSprite);
    }
    if(temGameMatrix[x][y]==2) {
    brickDef.position.set(left, top);
    brickBody = world.createBody(brickDef);
    Fixture brickFixture = brickBody.createFixture(brickFixtureDef);
    brickFixture.setUserData("a2" + x +y);
    brickBody.setUserData(brickSprite1);
    }

    }}}

    I like to destroy all object from the array which is 2.

  3. DICK Avatar

    Hi Daniel. Thank you for these videos they are very helpful! If you don't mind, I have a question….I'm trying to create a 2D isometric game and I'm using (libgdx) box2d to handle creating my map. What I need to do is create rectangles that represent parts of my terrain that are "impassable", however since its an isometric representation the rectangles must be rotated on a 30(degree) angle. I've tried using transforms and muls to rotate the rectangles initial positions, but no matter what they refuse (it seems) to be drawn at angles other than 90(degrees). Is there some sort of trick I'm missing? Should I be using polygon shapes instead, perhaps?

  4. Knödelcrafter Avatar

    What are you working btw, See you professor at a university? You cant live from youtube yet, do you?

Leave a Reply

Your email address will not be published. Required fields are marked *