-
amishaLikes 0Problem 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 adminLikes 0
Have you thought about using the jump action?
-
amishaLikes 0
yes,
-
Sonar Systems adminLikes 0
have you tried it?
-
amishaLikes 0
i tried the above code,but its not working according to me
-
Sonar Systems adminLikes 0
Have you tried the jump action built into Cocos2d-x?
-
amishaLikes 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 adminLikes 0
Explain what you mean by different heights, could you elaborate on the games situation.
-
amishaLikes 0
like in Fruit Ninja game,Fruit come randomly with different high
-
Sonar Systems adminLikes 0
You use random number generator to generate the height and use that in your jump action calculation.
-
amishaLikes 0
ohkey ohkey ...Thank you
-
Sonar Systems adminLikes 0
Your very welcome :D
Login to reply