box2d

Rendering box2d in libgdx

南笙酒味 提交于 2019-12-01 14:00:41
问题 I have a game world of size 800x480 using a FitViewport and was initally rendering box2d bodies + fixtures using pixels so all the physics appeared floating and slow. Looking at the documentation I realised box2d uses metrics units so I went through and converted the box2d positions and sizes by a factor of 32 so I end up with a box2d world of 25x15 metres. The issue I'm having is that now box2d objects are rendered incredibly small. How can I scale them back so they appear regular size on

Can I scale a shape in box2d as sprite do?

℡╲_俬逩灬. 提交于 2019-12-01 13:58:36
As we always use the function in cocos2d,I can scale my sprite whenever I want.Can I do the same thing in box2d?For example, I created a circle shaped body,then I want to make it bigger. I tried reassign the m_radius after I created a circle,but not work. If you are simply assigning shape.m_radius to a new value, it will not work. You need to reference the shape object associated with the b2Fixture that you created for your object: fixture->GetShape()->m_radius = new_radius/PTM_RATIO; Hope this helps. 来源: https://stackoverflow.com/questions/9075359/can-i-scale-a-shape-in-box2d-as-sprite-do

Box2D: How to get the position of a static body?

大城市里の小女人 提交于 2019-12-01 13:38:51
I have a Box2D world with a mixture of static and dynamic bodies. On collisions, I can only get the positions of the dynamic ones. Is it possible to get the positions of static objects? N.b., this is a development of a previous question, Box2D: How to get the position of a sensor? I found a way - in the collision, the center of the AABB will give the position contact.GetFixtureA().GetAABB().GetCenter() You can get the position vector using the following code: b2Transform t = body->GetTransform(); b2Vec2 pos = b2Vec2(t.p.x,t.p.y); 来源: https://stackoverflow.com/questions/5666834/box2d-how-to-get

calculate box2d impulse for a certain angle of impact

我怕爱的太早我们不能终老 提交于 2019-12-01 13:15:56
I have a ball (a dynamic body in the shape of a circle) that acts on a surface (trampoline) in the conditions of a gravity force. When the ball impacts the trampoline (drawn in the picture from point A to B) I would like to apply an impulse (normal to the trampoline surface) to the ball. The problem is that right now i use: b2Vec2 impulse = b2Vec2(0, [self fullMass]*[GameMaster sharedInstance].usrTrampolineForce); b2Vec2 impulsePoint = _body->GetWorldPoint(b2Vec2(0/PTM_RATIO, -1.0/PTM_RATIO)); _body->ApplyLinearImpulse(impulse, impulsePoint); Which sends the ball perpendicular(on the surface)

Can I scale a shape in box2d as sprite do?

故事扮演 提交于 2019-12-01 13:14:03
问题 As we always use the function in cocos2d,I can scale my sprite whenever I want.Can I do the same thing in box2d?For example, I created a circle shaped body,then I want to make it bigger. I tried reassign the m_radius after I created a circle,but not work. 回答1: If you are simply assigning shape.m_radius to a new value, it will not work. You need to reference the shape object associated with the b2Fixture that you created for your object: fixture->GetShape()->m_radius = new_radius/PTM_RATIO;

box2d contact listener fixtures order

被刻印的时光 ゝ 提交于 2019-12-01 12:51:41
问题 I am trying to understand how does it work. In my game I use box2d physics, to handle contacts I use contact listener, example: ContactListener contactListener = new ContactListener() { @Override public void beginContact(Contact contact) { final Fixture x1 = contact.getFixtureA(); final Fixture x2 = contact.getFixtureB(); if (x1.getBody().getUserData() != null && x2.getBody().getUserData() != null) { if (x1.getBody().getUserData().equals("player")) { player.increaseFootContacts(); } } } And

LIBGDX speeding up a whole game (using box2d)

巧了我就是萌 提交于 2019-12-01 12:36:11
I was wondering how i can speed up whole game done with libgdx (for example after clicking a button). The way i have in my game is modify a timestep variable used in world.step(TIMESTEP, VELOCITYITERATIONS, POSITIONITERATIONS); but im now sure if it's a good idea. If there a any better way to archive that? When using Box2D you can speed up your game by modifying the physics step. One problem is that you should use a constant steptime. I use the following code below in my games: private float accumulator = 0; private void doPhysicsStep(float deltaTime) { // fixed time step // max frame time to

LIBGDX speeding up a whole game (using box2d)

荒凉一梦 提交于 2019-12-01 11:21:51
问题 I was wondering how i can speed up whole game done with libgdx (for example after clicking a button). The way i have in my game is modify a timestep variable used in world.step(TIMESTEP, VELOCITYITERATIONS, POSITIONITERATIONS); but im now sure if it's a good idea. If there a any better way to archive that? 回答1: When using Box2D you can speed up your game by modifying the physics step. One problem is that you should use a constant steptime. I use the following code below in my games: private

how many pixels is a meter in Box2D?

早过忘川 提交于 2019-12-01 10:34:06
Question is simple so, no codes! If someone knows Box2D and SDL2, then, please tell me how to wrap SDL_Rect with b2body. Ofcourse, it requires to know the conversion of metre to pixel and vice versa. This is because Box2D measures distance in metres. Can you give me a simple expression or function to convert metres(of Box2D) to pixels or pixels to metres(of Box2D)? Can you give me a simple expression or function to convert metres(of Box2D) to pixels or pixels to metres(of Box2D)? Unfortunately, this isn't as simple as it sounds, for us. Because, if your game is on worms, then your game world

Box2D: How to get the position of a static body?

旧巷老猫 提交于 2019-12-01 10:11:14
问题 I have a Box2D world with a mixture of static and dynamic bodies. On collisions, I can only get the positions of the dynamic ones. Is it possible to get the positions of static objects? N.b., this is a development of a previous question, Box2D: How to get the position of a sensor? 回答1: I found a way - in the collision, the center of the AABB will give the position contact.GetFixtureA().GetAABB().GetCenter() 回答2: You can get the position vector using the following code: b2Transform t = body-