Stacked impulses

How To Make Flappy Bird
  • gassabr
    Likes 0

    Problem Description

    Hello, 

    I’m trying to create clone of Flappy bird and have question with physics in cococ2d-x: bird is falling under influence of gravity and moving up with impulse. Code (from different files):

    #define GRAVITY 200
    #define BIRD_FLY_DURATION 0.5
    //GameScene.cpp
    scene->getPhysicsWorld()->setGravity( Vect(0, -GRAVITY ) );
    
    bird.Fly( );
    this->scheduleOnce( schedule_selector( GameScene::StopFlying ), BIRD_FLY_DURATION );
    //Bird.cpp
    flappyBody->applyImpulse( Vec2(0, GRAVITY + 100) );
    

    And there is my problem: while user are clicking, vectors of impulse are added to each other. For example, result of 2 clicks one-by-one will be (0, 200). But in the game, result vector should be (0, 110) or (0, 180) depens on when actually you clicked. So, I need function to delete all previous impulses from the body. Is there any?

  • Sonar Systems admin
    Likes 0

    Try setting the impulse to 0 then setting to effectively delete it.

Login to reply