jump sprite with some specific height

  • amisha
    Likes 0

    Problem Description

    i want jump the player sprite on touch it .when i tap the sprite it jump one time then 3 time with diffrent level of height  and after some time its gone out of screen.

    i want to jump it some exact leval of height .hoe can i do this.

    I apply the physics on sprite that is

    on init() method

      sprite3 = Sprite::create("kartoon.png");
        sprite3->setPosition(Point(40,40));
        sprite3->setAnchorPoint(Vec2(0,0));
       

        spritibody=PhysicsBody::createBox(sprite3->getContentSize(),PhysicsMaterial(0,1,0));
        sprite3->setPhysicsBody( spritibody );
        
        spritibody->setDynamic(true);
       this->addChild(sprite3,4);

     

     

    onTouch the

     

     if(sprite3->boundingBox().containsPoint(locationInNode))
        {
            spritibody->setGravityEnable(true);
            spritibody->setDynamic(true);
            spritibody->applyImpulse(Vec2(0,20));
            sprite3->setPhysicsBody(spritibody);
            sprite3->setRotation(1);
            spritibody->setVelocity(Vec2(0, 0));
        
          }

     

     

     

  • Sonar Systems admin
    Likes 0

    Have you thought about using the jump action?

  • amisha
    Likes 0

    yes,

     

  • Sonar Systems admin
    Likes 0

    have you tried it?

  • amisha
    Likes 0

    i tried the above code,but its not working according to me

  • Sonar Systems admin
    Likes 0

    Have you tried the jump action built into Cocos2d-x?

  • amisha
    Likes 0

    ok i understand ,for fix jump i should use jump action but if i want jump with diffrent height then what to do??

  • Sonar Systems admin
    Likes 0

    Explain what you mean by different heights, could you elaborate on the games situation.

  • amisha
    Likes 0

    like in Fruit Ninja game,Fruit come randomly with different high

  • Sonar Systems admin
    Likes 0

    You use random number generator to generate the height and use that in your jump action calculation.

  • amisha
    Likes 0

    ohkey ohkey ...Thank you

  • Sonar Systems admin
    Likes 0

    Your very welcome :D

Login to reply