box2d

Is it possible to fast forward simulation in Box2D

爱⌒轻易说出口 提交于 2019-12-11 11:14:10
问题 I create a box2d world, put some objects on the screen with different properties like rotation, restitution ,density. And then I start the application. Is it possible to fast forward the simulation so that I can see the result quickly? By result I mean the final state of the world objects. Just like a video clip. 回答1: Thanks to Andrew I found that if I run the Step function multiple times, I can get the fast forwarded simulation. Here's just a little code that I guess anybody could write: -

GetBodyCount() always returning 0 in Box2d?

本秂侑毒 提交于 2019-12-11 10:35:32
问题 I am using the cocos2d-iphone + Box2d engine, I have a simple call in Box2d to create a body: b2Body *crateBody = world->CreateBody(&crateBodyDef); Then I am printing the newly incremented body count variable through: CCLOG(@"There are %0.0f bodies in the world.", world->GetBodyCount()); However, GetBodyCount() always returns 0 ? I know the body count variable is being incremented, as when I debug and step into CreateBody(..) m_BodyCount is incrementing, and my inspector returns 1

PTM_RATIO in retina display using Box2D, cocos2d and Physics Editor

♀尐吖头ヾ 提交于 2019-12-11 09:45:06
问题 I’m having a lot of problems trying to draw body shapes on my sprites. I tried a lot of combinations but I’m not able to make it work on retina display. I’m supporting iPhone retina only and both iPad (retina and not retina). A. PTM_RATIO The first question is which PTM_RATIO use for each device if I want the same physics in all devices. I read several posts and I don’t know if PTM stands for “ Point To Meter ” or “ Pixel To Meter ”. ¿Which column is the right one? B. Physics I want do draw a

Calculating the area and position of dynamically formed rectangles

血红的双手。 提交于 2019-12-11 09:33:30
问题 Hello stackoverflow community, I'm working on a puzzle game using Cocos2D/Box2D were the player draws lines on the screen. Depending on were the player draws, I want to then work out the area and position of the rectangles that appear as a result of the drawn lines. I've currently got an array of all lines in the game so I know their (x, y) positions and sizes but I'm at a lost as to how to calculate the area and Cartesian coordinates of the rectangles that are dynamically formed. To help

setAngularVelocity rotates really slowly

感情迁移 提交于 2019-12-11 09:16:46
问题 I am using the basic libgdx box2d to manage physics operations of a game. Everything is working properly, except the rotations: even when I set anyobject.body.setAngularVelocity(someLargeConstant); the object rotates really slowly(and almost at the same speed) no matter what the 'someLargeConstant' is. Except when I use small numbers for parameter, it can rotate slower. Thus I think I somehow have a maximum angular velocity constant inside my world object, which should be set to some small

Box2DDebugRenderer and SpriteBatch misplaced

别等时光非礼了梦想. 提交于 2019-12-11 08:37:39
问题 I am playing with libgdx for making yet another physics game :) and I have found something weird. Namely I use SpriteBatch for rendering images at the same time with Box2DDebugRenderer for debuging. But when the physics acts, they appear to be misplaced. I wrote: public class Canon implements ApplicationListener { private OrthographicCamera camera; private Box2DDebugRenderer debugRenderer; /... public void create() { camera = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT); world = new

box2d circular body stuck in corners

*爱你&永不变心* 提交于 2019-12-11 08:26:04
问题 Good day, I have a circular body which rolls in a certain direction. Some platforms in my game are built perpendicular to each other forming a 90 degrees corner like _| (without the gap :)) My problem is that the circular body gets stuck between the two platforms if it collides with the corner. Only by implying an impulse the body is released but gravity does not seem to affect it anymore. I have seen posts with solutions but they were all referring to square character bodies. Has anyone here

LibGDX Stop body from taking properties of previously deleted body

淺唱寂寞╮ 提交于 2019-12-11 07:57:23
问题 VIDEO FOR CLARITY: https://www.youtube.com/watch?v=3Mrro8sjcqo#t=25 I'm making my first LibGDX game, and I'm having trouble destroying and creating bodies. I've been using this snippet (because it seems to be everywhere) to remove bodies: private void sweepDeadBodies() { for (Iterator<Body> iter = tmpBodies.iterator(); iter.hasNext();) { Body body = iter.next(); if (body != null) { Entity data = (Entity) body.getUserData(); //Just the bodies data if (data.isFlaggedForDelete) { iter.remove();

How do I keep the angle of a body in pybox2d between -pi and pi?

限于喜欢 提交于 2019-12-11 07:34:49
问题 In the pybox2d manual it states the following: pybox2d uses radians for angles. The body rotation is stored in radians and may grow unbounded. Consider normalizing the angle of your bodies if the magnitude of the angle becomes too large (use b2Body.SetAngle). However, when I try to implement something to 'normalize' the angle I get the following error: AttributeError: 'b2Body' object has no attribute 'SetAngle' Code snippet: def update_outputs(self): # This is necessary to prevent the angle #

How to set the position of a sprite within a box2d body?

非 Y 不嫁゛ 提交于 2019-12-11 04:54:06
问题 Basically I have 2 polygons for my body. When I add a sprite for userData, the position of the texture isn't where I want it to be. What I want to do is adjust the position of the texture within the body. Here's the code sample of where I am setting this: CCSpriteSheet *sheet = (CCSpriteSheet*) [self getChildByTag:kTagSpriteSheet]; CCSprite *pigeonSprite = [CCSprite spriteWithSpriteSheet:sheet rect:CGRectMake(0,0,40,32)]; [sheet addChild:pigeonSprite z:0 tag:kPigeonSprite]; pigeonSprite