box2d-iphone

Box2D and wrapping worlds

对着背影说爱祢 提交于 2019-12-13 03:17:22
问题 I really stuck at implementing wrapping world with Box2D. I want to create game object appearing from left when it hides to the right and vice versa and the same for top-down. My idea is to use object wich contains NSArray with 9 elements for superposition matrix (it's a quantum state when object exists at different locations at the same time, isn't it?). Every element must contain the body. It covers all situations and has a more clear logic for me. For example, if my object doesn't touch

Create multiple fixtures in one body

十年热恋 提交于 2019-12-11 18:28:56
问题 I want to create this types of Fixture in one body. Here square and circle both are different fixtures but attach in one body Thanks in advance 回答1: You can use number of tools to make the fixtures. At my best knowledege there are some Tools listed as follows Physics Editor Vertex Helper Sprite Helper Level Helper There might be more tools for physics editor, but I would prefer to use Physics Editor. 来源: https://stackoverflow.com/questions/12226475/create-multiple-fixtures-in-one-body

Sprite Body can not stop

大城市里の小女人 提交于 2019-12-11 18:08:19
问题 Hey i have another issue regarding jump sprite body. In my code i am using moveLeft and moveRight Button and when i am press moveRight Button using following code if (moveRight.active==YES) { b2Vec2 force=b2Vec2(4,0); ballBody->SetLinearVelocity(force); } Its move perfectly and When i release this Button than sprite body stop using following code else { b2Vec2 force=b2Vec2(0,0); ballBody->SetLinearVelocity(force); } But when i put this else part then jump can not done. My jump code is

Move my body to a point

旧城冷巷雨未停 提交于 2019-12-11 14:32:56
问题 I am using box 2d. I just want to move my body to the point. What is the best way to do this? 回答1: When you say you just want to move the body, do you mean you want to apply a force to get the body to a point? There's a joint designed for mouse movement, and it might work well in your case if you want to drag bodies around on an iPhone. It's called the Mouse Joint, and it's under 8.10 on these box2d docs. If you want a body that doesn't respond to things hitting it, but pushes things around

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

In box2d for iOS, how to find the distance between two circular bodies?

人走茶凉 提交于 2019-12-11 08:32:11
问题 I am using the following code to get the distance between two circular bodies of different radius: distance = b2Distance(body1->GetPosition(), body2->GetPosition()); I have realized that variable distance is storing the distance between the two centers of the bodies, but not the distance between the borders. What I want is distance=0 when the two bodies are touching. How can I do that? I've been trying this code but it fails: b2DistanceInput *distanceInput; distanceInput->transformA = body1-

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

how to change the group index of a body dynamically in box2d

走远了吗. 提交于 2019-12-11 01:35:13
问题 I am new to box2d. I have started a new game in box2d and created 5 dynamic bodies in the world. Initially I need to prevent collision between them. so i set group index of all bodies negative. After touching a body i want to allow the collision with that body. How to reset the group index. Please help.. 回答1: Sounds like you're looking for something like b2Body *body = world->GetBodyList(); b2Filter filter = body->GetFilterData(); filter.maskBits = filter.maskBits | THE_RELEVANT_CATEGORY_BITS

Moving Box2d Bodies Like CCSprite Objects

被刻印的时光 ゝ 提交于 2019-12-09 13:00:06
问题 In cocos2d, you can ease in CCSprites and move them around in all kinds of ways. Most importantly - they can have easing in/out. For most games this is desirable for smooth movement etc. id action = [CCMoveTo actionWithDuration:dur position:pos]; move = [CCEaseInOut actionWithAction:action rate:2]; [self runAction: move]; When moving a box2d body, the sprite attached to it is updated after the box2d step(). Moving the sprite and then updating the body is not an option here, as it entirely

Making a Box2d object follow a predetermined path

一曲冷凌霜 提交于 2019-12-07 09:38:27
问题 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 回答1: Another option: Attach a mouse joint to your body Use setTarget method of the mouse joint to move the body 回答2: 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