# Ronald01990

Member

5

100 Neutral

• Rank
Newbie
1. ## [XNA/C#] Method for jumping

Oh that's working!! Yeah Thanks man. Only problem is that if totalSteps is < 20, my character ends higher than his startposition, and if totalSteps is > 20 my character ends lower than his startposition. But with 20 it works great!!!
2. ## [XNA/C#] Method for jumping

Thanks a lot for helping me out! Unfortenately my character is now moving up and it won't stop haha.
3. ## [XNA/C#] Method for jumping

Yes, if I press the right shift, my character has to jump: if (keyboardState.IsKeyDown(Keys.RightShift)) Now I understand that a update is drawn after a method call. So now I split the function in two seperated methods and call the second one if the first one had finished: if (keyboardState.IsKeyDown(Keys.RightShift)) { if (jumpUp(ref sjefkePosition.Y, ref jumpHeight)) jumpDown(ref sjefkePosition.Y, jumpHeight); } And down under: static bool jumpUp(ref float charPosY, ref float jumpHeight) { //Temporary vars float charStartPosY = charPosY; float jumpStartHeight = jumpHeight; bool goDown = false; //Check if character is not going down, let the man jump! while (!goDown) { for (float i = 0; i <= jumpStartHeight; i++) { charPosY -= jumpHeight; jumpHeight--; if (i >= jumpStartHeight) { //If the man finished jumping, set goDown true goDown = true; jumpHeight = jumpStartHeight; } } } return goDown; } static void jumpDown(ref float charPosY, float jumpHeight) { float jumpStartHeight = jumpHeight; //If our man jumped high enough, let him fall down again for (float i = 0; i <= jumpStartHeight; i++) { charPosY += jumpHeight; jumpHeight++; } } So I thought I got it now, but... This isn't working either . My character is now moving down (so it's leaving my screen)... I'm feeling so stupid haha
4. ## [XNA/C#] Method for jumping

Like I said, I'm a noob in C#/XNA Haha. The first reply is a little too much now, the second is better to understand . I thought that the character would be drawn automaticly. So if I understand you, I have to draw him when he is on the top of his jump... But how do I do that? As far as I know, you cant draw anyting in a method?!
5. ## [XNA/C#] Method for jumping

Hi people, I'm a noob in C# and XNA and just started with it. I'm having trouble with the following problem: I'm writing a method that let a object jump, bu I can't get it working. The parameters are an y position (a reference) and the jump spring hight. Down under my code so far: static void jump(ref float charPosY, float jumpHeight) { //Temporary vars float charStartPosY = charPosY; float jumpStartHeight = jumpHeight; bool goDown = false; //Check if character is not going down, let the man jump! while (!goDown) { for (float i = 0; i <= jumpStartHeight; i++) { charPosY -= jumpHeight; jumpHeight--; if (i >= jumpStartHeight) { //If the man finished jumping, set goDown true goDown = true; jumpHeight = 0; } } } //If our man jumped high enough, let him fall down again if (goDown) { for (float i = 0; i <= jumpStartHeight; i++) { charPosY += jumpHeight; jumpHeight++; } } } The first part - the jump part of this method - works fine if I comment the "goDown" part (the object jumps then) and also the "falling down"-part works if I comment the jump part. Together it won't work; it looks like the two parts are canceling each other. I think that is a strange thing, because the boolean "goDown" will be activated when the first part is done with the for loop... I hope anybody have a glue or an answer for me! Thanks a lot!! (Sorry if my English isn't that good, I'm Dutch )
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!