0

Currently, I have a program that has a ball, bouncing back and forth. In order to find out how fast it's bouncing, I made this:

b2Vec2 velocity = blueCircleBody->GetLinearVelocity();
float constantSpeed = velocity.Length();

NSLog(@"%.f", constantSpeed);

This is inside a tick: function. Every second, I want to see how fast the ball is moving. As I notice in the Output window, the ball seems to slow down after few minutes.

2012-12-16 11:29:10.458 Bubble Fill V1[31623:c07] 30
2012-12-16 11:29:11.474 Bubble Fill V1[31623:c07] 30
2012-12-16 11:29:12.475 Bubble Fill V1[31623:c07] 30
2012-12-16 11:29:13.492 Bubble Fill V1[31623:c07] 24
2012-12-16 11:29:14.525 Bubble Fill V1[31623:c07] 24

Is there a reason why the ball randomly went from 30 to 24?

Additionally, I have another problem. If I restart the program, with all the same data, the ball is going at a different speed for unknown reason. This means that the impulse/force I use doesn't dictate how fast it's going.

Here's some more information on the ball:

    blueCircle = [CCSprite spriteWithFile:@"blueCircle.png"];
blueCircle.position = ccp(winSize.width/4, winSize.height/4);
blueCircle.tag = 2;
[self addChild:blueCircle];




blueCircleBodyDef.type = b2_dynamicBody;
//Find a way to make the BoundingBox/GroundBox to not be affected by the Force of the Walls
blueCircleBodyDef.position.Set(winSize.width/4/PTM_RATIO, winSize.height/4/PTM_RATIO);
//blueCircleBodyDef.position.Set(blueCircle.position.x/PTM_RATIO, blueCircle.position.y/PTM_RATIO);
blueCircleBodyDef.userData = blueCircle;
blueCircleBody = world->CreateBody(&blueCircleBodyDef);

float blueCircleRadius = blueCircle.contentSize.width/2 * blueCircle.scale;
blueCircleShape.m_radius = blueCircleRadius/PTM_RATIO;


blueCircleFixtureDef.shape = &blueCircleShape;
blueCircleFixtureDef.density = 1.0f;
blueCircleFixtureDef.friction = 0.0f;
blueCircleFixtureDef.restitution = 1.0f;
blueCircleBody->CreateFixture(&blueCircleFixtureDef);





force.Set(0, 140);
//blueCircleBody ->ApplyLinearImpulse(force, blueCircleBodyDef.position);
//blueCircleBody->SetLinearVelocity(force);
blueCircleBody->SetGravityScale(0);
blueCircleBody->SetLinearVelocity(force);
4

0 回答 0