Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / My character keeps going up when I hold the jump button, I don't know whats the problem

Author
Message
yahya
15
Years of Service
User Offline
Joined: 16th Oct 2008
Location:
Posted: 9th Jul 2009 04:07
I took the code from Sparks Slide example, it worked he jumps when I press space then goes back down, but after changing Sparks Slide code to a class, when I jump and hold space, he keeps going up???

Here is the hcaracters code:




Am sure he should go down after pressing jump, not fly :/
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 9th Jul 2009 11:39 Edited at: 9th Jul 2009 11:41
I suppose ground, jumptimer, etc. were global variables in your previous code? A class member function is just like any other function in C++. If you declare variables within the function, they are LOCAL variables, which are RE-INITIALIZED every time when the function is called. So your ground variable will be always 1 and the jumptimer will be always 0 when the function starts.

If you insist on this structure, then at least declare those variables which should preserve their values from one function call to the next, static. However, a much better way would be to make them private variables of your class. Then they are initialized only once when the instance is created.

Login to post a reply

Server time is: 2024-10-01 05:56:16
Your offset time is: 2024-10-01 05:56:16