box2d-iphone

Cocos2d + Box2d - how to debug/show bodies?

微笑、不失礼 提交于 2019-12-06 15:49:45
问题 I've created a pretty simple setup using Cocos2d (2.0) and Box2d that comes packaged with it. I have a few bodies in my world, but don't have sprites linked up with them yet and I want to debug their orientations, positions, etc. This seems like a pretty standard task, but I could not find out how to do this easily. From my research it seems related to these methods: _world->SetDebugDraw(...); _world->DrawDebugData(...); // and the GLES-Render class Help? 回答1: I figured it out in case anyone

Objective-C++ importing C++ class fails, cassert not found

↘锁芯ラ 提交于 2019-12-06 06:24:15
问题 So I want to publicly expose a Box2D (C++) pointer to other Objective-C++ classes in my cocos2d + box2d project. I declare a method "getWorld" in my interface which references C++ class b2World and imports Box2D.h. All the files in my project are .mm extension, and I get the following compile error: In file included from DebugDrawLayer.mm:2: In file included from World.h:10: In file included from external/Box2d/Box2D/Box2D.h:34: external/Box2d/Box2D/Common/b2Settings.h:22:10: fatal error:

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 can I prevent a ball from sticking to walls in Box2D?

二次信任 提交于 2019-12-04 02:58:51
问题 I'm experimenting with box2d. I seem to have a problem people describe as sticky walls I have a ball and a paddle I'm using all the basic recommended scales I could find, 10m world, 1m ball The ball has the following properties: shape: circle (.5f radius) size: 1.0f density: 1.0f restitution: 1.0f friction: 0.0f The paddle used to move the ball is 1.5m, it has the following properties: shape: circle (.75f radius) size: 1.5f density: 10.0f restitution: 0.1f friction: 0.0f As you see the

Box2d custom polygon and sprites mis-matching

僤鯓⒐⒋嵵緔 提交于 2019-12-02 13:22:59
问题 I am using the Physics Editor for creating the Polygon in Box2d. It generates the Polygon and works fine in the non-retina display but doesn't work in the retina display..... I have attached the screen shot for both of the displays.Now when comes to retina display the polygon is not set over the car here's the image for that Here's my code which I am using in the Project CCSprite *car = [CCSprite spriteWithFile:@"opp_car.png"]; [car setPosition:ccp(wSize.width/2+50,wSize.height/2-120)]; [self

Box2d elastic rope joint

∥☆過路亽.° 提交于 2019-12-01 08:09:33
I'm writing a game, and I need to make up a rope. I maked it by b2RopeJoint, but there I have not found an opportunity to make it elastic. Then I looked for b2DistanceJoint, everything is cool with the elasticity, but I can't find an ability to set a limit only to the maximum distance (without minimum one). How can I do it? Try this. -(void) CreateElasticRope { //=======Params // Position and size b2Vec2 lastPos = b2Vec2(4,4); //set position first body float widthBody = 0.35; float heightBody = 0.1; // Body params float density = 0.05; float restitution = 0.5; float friction = 0.5; // Distance

Box2d elastic rope joint

扶醉桌前 提交于 2019-12-01 04:42:48
问题 I'm writing a game, and I need to make up a rope. I maked it by b2RopeJoint, but there I have not found an opportunity to make it elastic. Then I looked for b2DistanceJoint, everything is cool with the elasticity, but I can't find an ability to set a limit only to the maximum distance (without minimum one). How can I do it? 回答1: Try this. -(void) CreateElasticRope { //=======Params // Position and size b2Vec2 lastPos = b2Vec2(4,4); //set position first body float widthBody = 0.35; float

Box2d multiple fixtures and positioning

佐手、 提交于 2019-11-28 07:36:30
I'm attempting to create a "U" shape in Box2d (in Cocos2d) by joining 3 rectangles like so: |_| It sounds like joints are not the correct solution here since I don't want any movement so I have created a main body which is the middle bit and 2 fixtures for the sides. I've added the two sides to the middle bit like this: mainBody->CreateFixture(&leftFixtureDef); mainBody->CreateFixture(&rightFixtureDef); This works, however both side fixtures get added to the center of the mainBody. I can't seem to work out how to position the fixtures relative to the main body. Attaching a sprite/node to the

Simple gun in cocos2d+box2d game

a 夏天 提交于 2019-11-27 09:10:44
I'm newbie in box2d. Can you help me? I want to make gun (touch, move, stopped, ball flew). I make detection and rotation of gun, but I can't make popping of ball. How can I count velocity, which I need to set to the ball? Thank you very much The easiest way is to look at the direction the gun is pointing when you define the body, and use GetWorldVector to see how it has changed. For example if the gun is pointing directly upwards when you create the body, this would be the direction (0,1). Then you can use GetWorldVector at any time to get the current direction of that vector in world

Box2d multiple fixtures and positioning

谁说胖子不能爱 提交于 2019-11-27 01:53:01
问题 I'm attempting to create a "U" shape in Box2d (in Cocos2d) by joining 3 rectangles like so: |_| It sounds like joints are not the correct solution here since I don't want any movement so I have created a main body which is the middle bit and 2 fixtures for the sides. I've added the two sides to the middle bit like this: mainBody->CreateFixture(&leftFixtureDef); mainBody->CreateFixture(&rightFixtureDef); This works, however both side fixtures get added to the center of the mainBody. I can't