Hot answers tagged jbox2d
4
I think you should include food in the simulation.
If you do you will already have efficient checks for collisions with player body which you will need to make yourself otherwise. If you do not iclude it in the simulation you might need to implement a sweep and prune algorithm yourself (or maybe some space partition or similar) that box2d will already be ...
4
My thought is that you could use it - Say as a static body and assign it to an impact group that has no effect on other bodies. But like you say, box2d will do collision for you so it would make it a lot easier to implement pacman eating the food. And also like you say, it would be asleep so it wouldn't cost too much more in computation.
Why make it more ...
3
There's nothing wrong with Box2D web - perhaps just the way you are trying to draw the data. Are you using the debugRenderer?
Box2D - A web port
Physics simulations are always decoupled from the rendering routines (or they should be!). This is because they typically work within their own spatial regions that calculations are done in. This is metric in the ...
2
First thing I would look at is how setting the center point of object affects the local coordinate space of your polygon vertices.
Box2d gives you the position of the geometry at its center of mass by default, and the verts will be offset from the center in local space. I would try commenting out the lines:
p.setCenterX(center.x);
p.setCenterY(center.y);
...
2
What you have here is a misunderstanding of how physics engines work.
When a force is applied, it is merely set as some state indicating that the force was applied. The actual movement does not yet happen. The physics engine needs to integrate the physics with a time step, do collision checks, and then resolve those collisions (which can apply more ...
2
It all depends on the complexity of your simulation. The more objects you have the more time it will take to solve the collisions.
You can set your food filters to collide only with your player and your food bodies type to static.
Then when you collide simply disable the collision resolution and add your food objects to the "end of lived" list.
You might ...
1
You can use GLES_Render class in TestCpp, which is located in
./samples/TestCpp/Classes/Box2DTestBed/GLES-Render.cpp
./samples/TestCpp/Classes/Box2DTestBed/GLES-Render.h
of the download package.
To implement the debug draw, you can draw the debug renderer with your world data after CLayer::draw(); as demonstrated in ...
1
Your problem is that you are trying to create a PolygonShape with more than 8 vertices. Box2D, and thus JBox2D, default to a maximum of 8 vertices per polygon. This is why you don't get an ArrayIndexOutOfBoundsException until index 8 (0 based indexing means it's vertex #9).
You can change the maximum number of vertices by simply modifying ...
1
I don't know about JBox2D but in the actual Box2D lib there is PolygonShape.GetVertex()
//Returns a Vec2 (the coordinates) of a vertex given its index
const b2Vec2& GetVertex(int32 index) const;
So according to your code, I think calling shape.GetVertex(1) returns the second vertex you added.
1
It turned out that the vertices of my bullets were not making proper shapes due to a simple mistake.
They were something like: (0.0, 0.0),(0.0,0.5),(0.5,0.5),(0.0,0.5) which is obviously wrong but very hard to spot. Thank you for the help everyone, and I did end up using LibGDX; it's awesome.
Only top voted, non community-wiki answers of a minimum length are eligible