Search code examples
cocos2d-xcocos2d-x-3.0

Cocos2d-x-3 PhysicsBody applyImpulse doesn't accelerate sprite


I am struggling a little bit with applyImpulse. The docs say applyImpulse - Applies a continuous force to body. But my understanding is that a continuous force would make an sprite accelerate. f = m*a right? I have a constant force and a constant mass, so I should have a constant acceleration. However when I do this:

ball = Sprite::create("ball.png");
ball->setPosition(Vec2(s_center.x - visibleSize.width/10, s_center.x + s_center.y-visibleSize.width/3));
addChild(ball);
ballBody = PhysicsBody::createCircle(ball->getBoundingBox().size.width/2,  PhysicsMaterial(0.5f, 0.5f, 0.5f));
ballBody->setDynamic(true);
ballBody->setMass(30);
ballBody->setGravityEnable(false);
ball->addComponent(ballBody);
ballBody->applyImpulse(Vec2(0.00,-1300));

I get a ball that moves down the screen at what looks like a very constant velocity, and not acceleration. Am I doing something wrong?


Solution

  • Okay, the documentation is wrong. applyForce will apply a constant force, whereas applyImpulse will apply an impulse, or a instant force and let off (like a hit). I am a native English speaker and should have been able to figure that out sooner than I did.