box2d

Move a body to the touched position using libgdx and box2d

时光毁灭记忆、已成空白 提交于 2019-12-13 02:08:01
问题 I am trying to move a body with no gravity to the click or touch position and then stop it. However, depending where I click it moves really fast or really slow because of the coordinates of my Vector3. Also, it behaves like that game asteroids which I do not want. Basically, I just need myBody follows the click of the mouse our touch. Here where I have got so far: @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { camera.unproject(touchPosition.set

How to Optimize mach_msg_trap

烂漫一生 提交于 2019-12-12 16:18:41
问题 I know this question has been asked before, but no one has given any helpful answers as to how to fix it. I have a cocos2d ios application that uses the box2d physics engine. I ran a performance test on it and the cpu spends 5.6% of its time on mach_msg_trap. From what I have gathered from other questions, it seems as if mach_msg_trap is just the main thread waisting time as a result of your application being idle. My application isn't idle though. It has shaky performance and hovers in the

Fast moving bodies miss the collision sometimes in Box2d, AndEngine

跟風遠走 提交于 2019-12-12 11:37:00
问题 I have a Fast Moving Body(A) which is dynamic. It is supposed to collide with another Body(B). A collides with B, but sometimes it passes the Body B without collision. This is totally random behavior. I must have that collision. Kindly guide why it is acting like this, randomly. 回答1: The effect of one object passing through another due to large movement in a single timestep is called tunneling . Box2D uses Continuous Collision Detection between dynamic and static objects to solve this problem

UIPinchGestureRecognizer - Suppress 'close pinch' detection

こ雲淡風輕ζ 提交于 2019-12-12 05:32:35
问题 I'm using the UIPinchRecognizer and an open pinch to detect when someone 'pulls apart' a sprite in a Box2D world. The problem is that when you drag two items toward each other it detects this as a close pinch and breaks all my touchjoints and the movement of the box2d objects. I've tried to split my problem into two questions - the question you're reading now: is it is possible to suppress the close pinch, and if that's not possible: how to detect an open pinch myself. I need to either

What is the 'f' used for in JBox-2d? [duplicate]

两盒软妹~` 提交于 2019-12-12 05:28:53
问题 This question already has answers here : What does suffix 'f' mean in Java code? (5 answers) Closed 5 years ago . It seems to be used in value declarations in the engine but the documentation of JBox-2D does not explain what this 'unit' is. Example: float x = 20.0f //<-- this 'f' FixtureDef fixDef = new FixtureDef(); fixDef.shape = shape; fixDef.density = 0.0f; //<-- this 'f' fixDef.friction = 0.9f; //<-- this 'f' What is it? If it is indeed a unit, what is it relative to? What benefit does

How to make a revoluteJoint oscillate?

江枫思渺然 提交于 2019-12-12 05:14:50
问题 I have created a revoluteJoint with a motor and lower & upper limits. I would like to know how to make the revoluteJoint oscillate between the lower & upper limits. Currently the body swings from the lower to the upper limit and then stops. Any help will be appreciated. This is the code final RevoluteJointDef revoluteJointDef2 = new RevoluteJointDef(); revoluteJointDef2.initialize(legBody, circleBody1, circleBody1.getWorldCenter()); revoluteJointDef2.enableMotor = true; revoluteJointDef2

Detect whether a specific part of body collided with another body in box2d

只谈情不闲聊 提交于 2019-12-12 04:37:38
问题 Kindly suggest some explanation or code regarding how can i detect collision between a specific part of one body with another body in box2d with libgdx.I am able to detect simple collision between two bodies using Contact Listener as mentioned hereBut I also want to check which part of bodies are ovelapping . Thanks, 回答1: The ContactListener provides you with Contact as a callback parameter. Those contacts will tell you which Fixtures did collide via contact.getFixtureA() and contact

Libgdx and Box2D Draw a custom shape

时间秒杀一切 提交于 2019-12-12 02:10:11
问题 I have the following shape: http://s16.postimg.org/sfhb5wgdx/slime.png and I want to draw it in LibGDx just like that because am using Box2d wand will be used in collisions. I have heard I can used a mesh to create this but there isn't much documentation about drawing anything from an image. Do I seriously have to define all the points myself? Is there a better way to extract a shape from in image? 回答1: Use Physics body editor https://code.google.com/p/box2d-editor/ this will solve your

Detect an open pinch - like UIPinchGestureRecognizer, programmatically in a Box2D/cocos2d world?

佐手、 提交于 2019-12-12 01:58:22
问题 I'm using the UIPinchRecognizer and an open pinch to detect when someone 'pulls apart' a sprite in a Box2D world. If I use UIPinchGestureRecognizer to detect pull aparts, it breaks my mouse joints when two objects are dragged together - which is less than ideal. I've tried to split my problem into two questions - how to detect an open pinch without UIPinchGestureRecognizer and is it is possible to suppress the close pinch. How can I write my own class to detect an open pinch? That is, two

Contact Listener not working in Libgdx

痞子三分冷 提交于 2019-12-12 01:55:22
问题 I am developing a game in Libgdx and I am working on collision detection between two bodies in box 2D. I used "Contact Listener" to detect collision but nothing happens when the bodies collide. This is my code public Player(World world,float x,float y,float width) { this.width=width; //IMP height=width*2; BodyDef polygon=new BodyDef(); polygon.type=BodyType.DynamicBody; polygon.position.set(x,y); // polygon.fixedRotation=true; PolygonShape poly =new PolygonShape(); poly.setAsBox(width/2