box2d-iphone

GetBodyCount() always returning 0 in Box2d?

Hi There, 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 re...

Box2d: mousejoint jerky

Hi to all! I'm making my first iPhone game. I have increasing number balls that can be dragged. I had some problems with inertial delay of mousejoint and I configured them as follows: b2MouseJointDef md; md.body1 = _groundBody; md.body2 = body; md.target = p; md.maxForce = 10000.0f * body->GetMass(); md.dampingRatio = 0; md.frequencyH...

removing bounce off colliding objects in box2d

Hi, I am trying to delete an object in box2d when 2 object collide. When my 2 objects do collide, one of the object bounces off the other. it does delete the other object, but i want it to make it look like it went through rather than a bounce. I have my body Def type set to b2_staticBody. Any help would be appreciated. ...

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

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]; CCSp...

cannot convert 'b2PolygonShape' to 'objc_object*' in argument passing

Hey there, I am not sure if many of you are familiar with the box2d physics engine, but I am using it within cocos2d and objective c. This more or less could be a general objective-c question though, I am performing this: NSMutableArray *allShapes = [[NSMutableArray array] retain]; b2PolygonShape shape; .. .. [allShapes addObject:sha...

Only Integrating Box2D collision detection in my 2d engine?

I have integrated box2d in my engine, ( Debug Draw, etc. ) and with a world I can throw in some 2d squares/rectangles etc. I saw this post, where the user is basically not using a world for collision detection, however the user doesn't explain anything about how he's using the manifold (b2Manifold), etc. Another post, is in the cocos2d...

Casting to derived type problem in C++

Hey there everyone, I am quite new to C++, but have worked with C# for years, however it is not helping me here! :) My problem: I have an Actor class which Ball and Peg both derive from on an objective-c iphone game I am working on. As I am testing for collision, I wish to set an instance of Ball and Peg appropriately depending on th...

Move my body to a point

I am using box 2d. I just want to move my body to the point. What is the best way to do this? ...

cocos2d circular edge

Hi, i am using the following code to draw a circular edge in scene. // Create edges around the entire screen b2BodyDef groundBodyDef; //groundBodyDef.position.Set(0,0); b2Body *groundBody = _world->CreateBody(&groundBodyDef); b2PolygonShape groundBox; b2FixtureDef boxShapeDef; boxShapeDef....

Box2d:negative value return from GetLinearVelocity();

When I use the following, sometimes I get a negative value in mmVelik.x and mVelik.y. Can anyone explain why?? b2Vec2 mVelik = ballBody->GetLinearVelocity(); ...

On shake of an iPhone move a ball in shaking direction..(using box2d physics)

Hi, Please look at the code first.... - (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration { b2Vec2 localPoint; localPoint.Set(0,0); if (acceleration.x>1.5 || acceleration.y>1.5) { b2Vec2 mVelik = ballBody->GetLinearVelocityFromLocalPoint(localPoint); b2Vec2 forca...

Developing A Simple Game without using Game Engines???

I am trying to develop a simple soccer game including penalty kicks in which i have to animate a ball from player to the goal post...earlier i have been using simple animations using a timer to add to the axis of ball image so that it moves from 1 point to another..but i did not have the desired result as animations were not that smooth....

Objects that defy gravity but collide with others in Box2D. How?

Hello, newbie to iPhone game development and Box2D here. I'm developing a game in which I can move (drag) otherwise stationary objects that can collide with other objects. How do I make these objects stationary in a Box2D world with gravity while maintaining their ability to collide with dynamic bodies? One random thought is to exert ...

box2d:Disable bounce on collision

hi, I have some box,creating using box2d,which restitution's are set to zero.but when they fall over one another there appear bounce event.but i don't want that...i want them not move when fall over another.it can be done if i switch off gravity.but i also want gravity.here is my code UIImage *imageOfSnowV1 = [ UIImage imageNamed:[NSSt...

cocos2d + box2d: Rotation towards point

I'm attempting to rotate a box2d body that's tied to a cocos2d sprite via box2d's GetUserData() in my iPhone application. Specifically, I'm attempting to grab the latest touch location and rotate my box2d body in that direction. I'm fairly inexperienced when it comes to box2d, so any advice would be appreciated. Below is a quick stab at...

box2d world :: everything is so light !!!

hello, i'm using box2d 2.1.2 with cocos2d 0.99.4 in my world, everything is light, there is no sensation about dropping a stone or a box !! everything falling slowly at the same speed b2Vec2 gravity; gravity.Set(0.0f, -10.0f); bool doSleep = true; world = new b2World(gravity, doSleep); and my objects : b2BodyDef *TBodyDef = new...

box2d:Move body with animation

Hi, i am using box2d to developed iphone game.But i have not a lot of experience.I move a body to a location using this code body->SetTransform(b2Vec2(posx2,posy2), 0); and the body does move.But i need it to move with animation.in objective c i use UIView Animation to do similar type of things. can anyone tell how it possible in coc...

How to make a moving object "stick" to a stationary object in box2D

Hello, I have been experimenting with the box2D sample project within cocos2D for the iPhone and am wondering if box2D is the appropriate engine to use to make a moving object "stick" to a stationary object when the moving object is finished moving in a certain direction. Here is a simplification of what I am trying to achieve: I hav...