4 Replies - 512 Views - Last Post: 03 May 2012 - 07:25 AM

#1 T0pAz  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 26-April 12

Jumping not working more than once.

Posted 02 May 2012 - 10:32 AM

Hello guys. A small problem in here. Jumping does not works more than once. Here is the code

Global Var:

 private enum StateType 
        {
            walking,
            jumping
        }
private StateType state;
        private KeyboardState oldState;
private Vector2 velocity;



Update:

KeyboardState newState = Keyboard.GetState();

if (newState.IsKeyDown(Keys.Space) && oldState.IsKeyUp(Keys.Space) && state == StateType.walking)
                {

                    state = StateType.jumping;
                    velocity.Y = -speed;
                }

Restitution();

if (position.Y > graphics.PreferredBackBufferHeight / 2 - 78 && state == StateType.jumping)
                {
                    state = StateType.walking;
                    velocity.Y = 0;    
                }

oldState = newState;



Restitution:

if (state == StateType.jumping && position.Y <= 150)
                velocity.Y = speed;



Is This A Good Question/Topic? 0
  • +

Replies To: Jumping not working more than once.

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,846
  • Joined: 02-June 10

Re: Jumping not working more than once.

Posted 02 May 2012 - 03:36 PM

View PostT0pAz, on 02 May 2012 - 11:32 AM, said:

Hello guys. A small problem in here. Jumping does not works more than once. Here is the code


I'm sure you don't mean for this to sound like "I'm to important to do my own debugging. Here you minions do it." But that's how this reads.

Is there a question in there somewhere? - Please read, then let us know what you are asking of the volunteers. Otherwise it just implies you are asking "would you do it for me?"




T0pAz: What this shows us is that you aren't familiar with breakpoints and how to debug your own code. Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.


See FAQ # x. (Click the SHOW button below)


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated Apr 2012
Spoiler



This post has been edited by tlhIn`toq: 02 May 2012 - 03:37 PM

Was This Post Helpful? 2
  • +
  • -

#3 T0pAz  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 26-April 12

Re: Jumping not working more than once.

Posted 03 May 2012 - 12:52 AM

But I don't know which variable is causing the problem.
Was This Post Helpful? 0
  • +
  • -

#4 T0pAz  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 26-April 12

Re: Jumping not working more than once.

Posted 03 May 2012 - 02:19 AM

Fixed by myself from the tips of tlhIn`toq. Thanks!
Was This Post Helpful? 1
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,846
  • Joined: 02-June 10

Re: Jumping not working more than once.

Posted 03 May 2012 - 07:25 AM

Well done.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1