box2d

how to use the libgdx contactlistener

橙三吉。 提交于 2019-12-05 19:17:32
问题 I've just began to work with the Libgdx's Box2d Engine but i simply do not understand when the methods of the Contactlistener should be called. There is on the one hand "begin contact" and on the other "end contact". Where should i call them, to get the Number of of a certain fixture touching others? And how do I implement the Contactlistener ? A redirec' to a Tutorial would answer my Question. I didn't find anything while searching google. This one helped me a lot but it is written for C++

Making a Box2d object follow a predetermined path

吃可爱长大的小学妹 提交于 2019-12-05 17:04:29
I'm making a game in which a certain object (modelled as a box2d body) has to follow a fixed path. Is there a way by which I can specify the path coordinates and make the object advance over it for each dt? Thanks Another option: Attach a mouse joint to your body Use setTarget method of the mouse joint to move the body You should use a Kinematic body, but you can't change its position manually, you have to change its speed for the dynamics and collisions to be applied correctly. I suggest the following algorithm: 1st - Calculate the position on the track that the body should be in on the next

How to apply constant force on a Box2D body?

你说的曾经没有我的故事 提交于 2019-12-05 15:34:16
I am making a Box2d game for the iPhone. I need to apply a force on a body which represents my main character. The body is actually a rectangle on top of a circle connected using a revolute joint. I am using this as the skeleton for my character who is supposed to be running through the game(any suggestions or feedback on this too would be appreciated). I need a force to be applied continuously so that it keeps him moving. What would be the best way to do this? I am currently applying linear velocity inside the tick method. _world->Step(dt, 10, 10); if(gamestarted) { b2Vec2 force = b2Vec2(6,

How to make two bodies stick after a collision?

天大地大妈咪最大 提交于 2019-12-05 13:49:33
I am really stuck on this I can successfully detect a collision but I can't make the two bodies involved in the collision to stick. Here is my ContactListener world.setContactListener(listener); listener = new ContactListener() { @Override public void preSolve(Contact contact, Manifold oldManifold) { } @Override public void postSolve(Contact contact, ContactImpulse impulse) { } //called when two fixtures cease to touch @Override public void endContact(Contact contact) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); Gdx.app.log("beginContact", "between" +

Couldn't load shared library box2d for libgdx

一世执手 提交于 2019-12-05 12:55:20
I have a libGDX project that is built using maven. It's run fine in the past, but recently, it's stopped working, due to libGDX moving box2d to being an extension. I added the extension as a dependency to the core of my project like I would any other dependency: <dependency> <groupId>com.badlogicgames.gdx</groupId> <artifactId>gdx-box2d</artifactId> <version>${gdx.version}</version> <scope>compile</scope> </dependency> however, when I try to run the project for desktop (or anything else, really), I get the following error: [java] Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't

How to grab a b2Body and move it around the screen? (cocos2d,box2d,iphone)

耗尽温柔 提交于 2019-12-05 07:05:50
问题 I want to move any b2body that is touched on the screen around the screen. I've heard something about mouse joints.. I found that: http://iphonedev.net/2009/08/05/how-to-grab-a-sprite-with-cocos2d-and-box2d/ but I just gives me a lot of errors if i just copy the ccTouch Methods into a new project (of course the variables in the header too). E.g. world->Query <- NO MEMBER FOUND May someone make a tut/a new project and upload it here. Or is there a better way? 回答1: First you have to create

Xcode C++ and Objective-C refactoring

人盡茶涼 提交于 2019-12-05 05:18:57
Is there a way to refactor mixed C++/Objective-C code in Xcode ?? I am writing a game using Cocos2D and Box2D, and the Box2D is written on C++, so every class I write should have .mm extension and therefore when I try to e.g. rename the variable, I got a message like " Xcode can only refactor C and Objective-C code ". Thanks in advance! Sulthan Xcode is VERY limited with refactoring, even with plain Obj-C. It's basically renaming and it can't even rename in comments. If it says it can't do something, then it probably can't. The only way to rename is using find & replace . Note that Xcode can

Showing trajectory indicator

烂漫一生 提交于 2019-12-05 04:50:17
问题 From the image you can see that the ball fired on the left that fire behind it, does not match the calculated trajectory. Im drawing the ball trajectory using an equation from a SO question, this is modified to take into consideration the box2d steps of 30 frames per second. This does calculate a valid trajectory but it does not match the actual trajectory of the ball, the ball has a smaller trajectory. I am applying a box2d force to the ball, this also has a density set and a shape. The

How to stop the forces acting on a body in box2d

怎甘沉沦 提交于 2019-12-05 02:17:58
I am using box2d on the iphone to create a game. I have a body that is effected by gravity to move down and not right or left. It will get hit by another body and will then be moving right or left. I then have a reset button which moves the body back to its starting point. The only problem is that it is still moving right or left. How can I counteract the forces that a ball is already traveling? How can I get rid of this right and left movement when I reset my game? box2d automatically clears forces each simulation step. I think you are just changing you body's position when reseting, but not

How to subscribe self on the event of Device Orientation(not interface orientation)?

心已入冬 提交于 2019-12-04 23:54:58
in my app i want to call some method in CCScene myscene in the case of device rotation(orientation change).I disabled the autorotation(because i want it not to happen). The issue is: i want to change gravity in the scene depending on my device orientation. My code : -(void) onEnter { [super onEnter]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notification_OrientationWillChange:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notification_OrientationDidChange:)