Box2D is an open-source rigid-body 2D physics simulation library for games, written in C++, with ports in various languages

learn more… | top users | synonyms

1
vote
1answer
11 views

Libgdx Box2D random positions and intervals falling bodies

I need to make that objects fall from the top of the screen random intervals and positions. Here's my code where I create lot of objects and add them to ArrayList private void createBalls() { ...
0
votes
0answers
16 views

Setting up SFML and Box2D at the same time on VS2013 [on hold]

How do I add SFML and Box2D at the same time and both workable, while I can add them independently after I put them into the same project one of them doesn't seem to work.
0
votes
1answer
44 views

How to make a ball hit many tiled circular objects in LibGDX

Hey guys I've been learning to make games with LibGDX. I did a tiled map in Tiled and the rest of code in java using Android Studio. I could make a ball bounce on the flour using Box2D, but I can't ...
0
votes
1answer
354 views

libgdx - Box2d debug draw not correct

I have a problem where the bodies in my debug draw does not draw correctly, take a look: As you can see, there is some space between the dynamic body and the ground. I have checked the contact ...
0
votes
2answers
518 views

Libgdx box2d crashing

im making a game in libgdx which i having a bunch of circle bodies floating around in space and when the player's body crashes into another body, that body deletes and creates two smaller bodies ...
0
votes
1answer
516 views

Move Box2D body towards mouse click

In a top down game using Box2D, I would like the player's Box2D body to rotate towards the mouse click, and then move to a point on mouse click (move, not teleport). I have worked out the rotation ...
5
votes
2answers
89 views

How do I turn an image into a Box2D physics object?

I'm using Box2D for a Game Programming course, and I was wondering if it is possible to choose the best shape and size of shape for the rigidbody/fixture for a sprite based on its transparency. I've ...
1
vote
1answer
33 views

Problems managing collision filtering

I have my character fixture and body(is a tank), so when I press the screen it throws a rocket(which also has a body and a fixture) that the player can controlll touching the screen. My game also has ...
4
votes
1answer
269 views

LibGDX Box2D TileGame Efficiency

I am trying to implement Box2D into my top down tile game in LibGDX. Each world consists of a set of chunks, and each chunk is 16 tiles wide/long. The maximum/minimum chunks loaded at one time is 9 (a ...
1
vote
1answer
19 views

Box2d How to connect distance joint to the ground?

I have a rectangular fixed size world. I want to connect a body inside it to any place(near that body) in the world with a b2DistanceJoint. Do I need to create a large static body with the size of the ...
1
vote
1answer
180 views

Rotating towards a point in Box2D

I'm using Box2d as my physics engine and I'm trying to solve what would normally be a simple problem but what has become a nightmare for me and preventing me from finishing my app. (6 months work) ...
0
votes
1answer
38 views

How to unload/remove body components in Box2D?

I want to know how to release/clear/remove a variable. (specifically b2BodyDef, b2Body, b2FixtureDef, b2PolygonShape types.) I've heard there's a keyword called delete, guessing by it's name it may ...
2
votes
3answers
153 views

How to make sure that when two bodies collide, there is only one collision detection on box2d?

I'm using LibGDX with box2d, and when to bodies collide collision is detected multiple times. here's the code `public void preSolve(Contact contact, Manifold oldManifold) { Body a = ...
1
vote
1answer
35 views

LibGDX box2d - Jumping not working

I'm trying to make a platformer game using Box2D, but I can't manage to do the jumping. The source code is here: https://github.com/ZacGarby1/Platformer. I have no idea why it's not working because I ...
1
vote
2answers
44 views

Box2D LibGDX Body.getPosition() and Body.getWorldCenter() problems

I have a problem with my game in Java with Box2D and LibGDX I found out that when I use body.getPosition() it is only half of that of body.getWorldCenter(). The problem here is for me that I use ...
3
votes
1answer
78 views

Creation of a tiled map editor polyline in box2d is not working correctly

I'm currently trying to create a box2d polyline object in my libgdx game, but it's not working as expected. To get a better picture of my subject, have a look at how it should look like, and how it ...
0
votes
1answer
50 views

Black screen when launching on phone

I am coding a game in libgdx. While adding the background I used the html module to watch the results fast and easy on my computer. But when I try to see it on my phone I just get a black screen. My ...
1
vote
0answers
15 views

Movement for Box2D Bodies

I'm having trouble wrapping my head around something that should be relatively simple. I'm making a breakout clone using LibGDX and Box2D. I'm also using the Ashley ECS. For movement with bodies, I ...
1
vote
1answer
745 views

Changing Box2D Body from Kinematic to Dynamic after contact

What is the correct way to change a Kinematic body into a dynamic body? context - I have a dynamic body as a projectile which has to be fired at a kinematic body (it is kinematic because i am ...
2
votes
1answer
733 views

LibGDX - Box2D: Realistic Light and Layers

I'm having some problems with my current game. Short description: It's a 2D game where you have to avoid the lights or you lose HP. My problem is the following one: Here is the rendering process: ...
0
votes
1answer
146 views

How to convert pixels to meters in Box2d with Cocos2d-x 3.5?

I am using Cocos2d-x 3.5. I created a simple game with edge bodies and one circular body to test box2d. Physics wasn't working well, so i thought i should convert pixels to meters and use that meters ...
1
vote
0answers
37 views

Moving box2D body with texture?

I was following the solution from this http://stackoverflow.com/questions/20180063/box2d-body-with-texture. I ended up getting this working for static bodies. But when trying to get the PolygonSprite ...
2
votes
1answer
448 views

Wheel Joint Implementation in AndEngine

I am currently developing car game in AndEngine. In which I was using revolute joint for car wheel and chassis attachment. But my friend suggest me that use wheel joint for that purpose for better ...
6
votes
2answers
342 views

Letting the user draw a Polygon Body and Image

In my game, I want to provide the user with a drawing feature. By free hand drawing, the user creates a polygon shape. Then, in my game implementation, I have to create a body for the found vertices ...
8
votes
4answers
398 views

Creating a Melee Weapon in Box2D (libGDX)

I am struggling with how to implement a melee weapon that can swing when a key is pressed. I am imagining two different attacks (stab and swing) I have tried creating two fixtures (character + ...
2
votes
1answer
255 views

LibGDX Box2D Lights - Illuminate background

I have a box2D world made of tiles. I use a custom DirectionalLight for light up the scene from above (It shines through transparent blocks [eg.: the water] more deeply). The problem is (as expected), ...
0
votes
0answers
37 views

How to dynamically draw a filled polygon with a given array of vertices?

Say I have a simple array of vertices (or floats with every odd index being the X of a vertex and every even being the Y), how could I paint all the area between the vertices? As in, I have maybe ...
1
vote
1answer
1k views

Drawing Shape in DebugView (Farseer)

As the title says, I need to draw a shape/polygon in Farseer using debugview. I have this piece of code which converts a Texture to polygon: //load texture that will represent the tray ...
5
votes
4answers
88 views

Dealing with collisions across adjacent static bodies

The Problem: I have the following setup: A, B and C are rectangular static bodies in box2d. p is a circular dynamic body in box2d. The movement of 'p' is solely controlled by the current gravity ...
1
vote
1answer
519 views

Lighting shadow casting sprites with box2Dlights

I currently have something like this using box2Dlights Ideally, I would like objects casting shadows to be lit, so the object is lit but there is still a shadow cast around it. Right now the object ...
0
votes
1answer
91 views

Set Position of multiple bodies

I have a character composed of five bodies which are tied together by a lot of joints. On of them is the overall chassis, to which all forces and impulses are applied to move the whole Character. All ...
1
vote
3answers
111 views

Most optimal way to load 2D world

I am creating a 2D car racing game. (Yes, a Hill Climb Racing clone) What I am doing right now is load 10% of the map every time the user gets to 7%. For example: Imagine the map has 10km. (10000m) ...
2
votes
3answers
290 views

Dynamic Hills like Contre Jour in Cocos2d

I'm interested in maps/environments which are flexible and change at runtime, such as those in Contre Jour. I have looked for a long time to find out how to make this effect, but I couldn't find an ...
4
votes
2answers
84 views

How do I set angular velocity/torque so that it's pointing to velocity/direction?

Right now, when I spawn a shootable object, it goes like this: Because I just set it's angle to this: float aimAngle = (float) Math.atan2(velocity.y, velocity.x); bullet.setBodyAngle(aimAngle); ...
0
votes
2answers
377 views

Libgdx using Box2d with TiledMap to create collision detection

I'm fairly new to Libgdx and have some good basic knowledge on Java. Right now I am stuck on how to add collision to my TiledMap, I am using the Mapeditor to create the tilemap. I read so many ...
3
votes
1answer
39 views

Static body bridging two other static bodies

I have two box2d bodies like below, What I need is to create another body that kind of bridges this two bodies. I am not looking for a box2d joint, but a body that will be like a bridge touching the ...
0
votes
1answer
237 views

box2d ChainShape into curved line

i need to draw a curved line , i searched the internet and found nothing , maybe someone with knowlegde on the subject can help me with a link , i used chain shape and did this , and i don't know ...
0
votes
0answers
24 views

Get entity at supplied world position LIBGDX

So I'm making a simple 2D rpg. What I need is to be able to interact with the entity that the player is looking at. I need to be able to look at E.g another player in the world and press 'E' and have ...
4
votes
1answer
71 views

How to spawn Chunks in Libgdx?

I'm currently working on a 2D platforming game with an infinite map. I did my research and I discovered that I can use chunks. Based on my understanding chunks is about spawning terrain at the right ...
1
vote
3answers
74 views

How do I make a box don't slide up/walk normally on a slope?

I'm trying to implement slopes in my game. When I walk up the slope and suddenly stop, here is what happens: And when I move down, it goes like this: I have set density to 0.5, friction to 0 on ...
1
vote
0answers
65 views

Should I compute impact damage with energy or momentum?

My game uses physics (Box2D in particular). Just about every object in the game can be destroyed, and the primary method of combat is by slamming objects into one another at high speed. It makes ...
0
votes
0answers
33 views

LibGDX Box2DLights - Global Illumination

I'm using LibGDX + Box2D to create dynamic lights in my game, but I'm currently stuck. I'm trying to light up every game object in the game with its own shadow, kinda like global illumination. Do you ...
1
vote
0answers
18 views

Multiple bodies or multiple fixtures for a wall in Box2D?

I am making a game with a sort of "playfield" where the game takes place, acting as boundaries on a top-down shooter. I am using Box2D for physics, and I am questioning which of the following would be ...
0
votes
1answer
39 views

How to predict future position of an object(bullet sync)?

There is a multiplayer game and server sends to all clients a message when a shot happens, containing bullet position, bullet velocity and timestamp. By having timestamp, we can calculate the lag, ...
0
votes
1answer
20 views

Does all box2d bodies have collision detection?

What I want to know is if both b2-static and dynamic bodies have automatic collision detection. And how do I tell box2D what it should do when it collides with a specific body?
-1
votes
1answer
75 views

Box falls extremely slow? (~1 pixel per second)

As the title says I have a problem where my box2d bodies falls extremely slow. Around 1 pixel per second. My world is stepped like this world.Step(1 / 60.0f, 8, 3);, each frame. The way I update ...
-1
votes
1answer
61 views

Game crashes when trying to access function inside of a class, inside of a vector

So, I have a object, inside of a vector and I'm trying to call a function in that object : std::vector<Box>entities; entities.insert(entities.begin() +1, Box(&world, ...
0
votes
1answer
60 views

Clearing memory from variables? [closed]

So, I've heard of the delete keyword, which clears variables that use the new or new[] keywords. I have a class called Box, which I made a object of in my main.cpp. What if I want to clear a ...
0
votes
2answers
99 views

sf::RectangleShape's position is not same as I set it to

When I try to print my box.getSfShape()'s position it does not print out the position I set it to have. ( The box.getSfShape()'s position is by default set to 0 ) Wrong output : ( printing the ...
0
votes
0answers
22 views

Libgdx Box2D - Object not showing up

I am trying to put a sprite into my b2d-world. But for some reason, it is not showing up. I've already checked the camera settings, they are defenetly correct. Then I came to the point to check the ...