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.

Newcomers DBPro Corner / Problems with Jumping Code

Author
Message
Duncan161
13
Years of Service
User Offline
Joined: 15th Mar 2011
Location:
Posted: 15th Mar 2011 16:11
I can get my Sprite to jump up but then it doesn't seem to want to come down. If anyone could give me a hand it would be great
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Mar 2011 19:26
That's not a great example to give us a real idea what's going on. If I had to guess I'd say it's in the last "If" statement somewhere... or some code we haven't seen yet...

Could you post some code we can compile? It always helps.

revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 16th Mar 2011 21:02 Edited at: 16th Mar 2011 21:13
Hi Duncan161, Welcome to the forum!
As baxslash has already said, that isnt the most helpful snippet when it comes to figuring out what is wrong, but I think I have a solution for you (This is only a guess until I can see the rest of the code).




Keep in mind that I havn't even checked to see if this compiles so there might be a silly error somewhere.

In the future could you comment (and preferably indent) your code, It really helps us to see what is going on and usually reveals why a snippet isn't acting as expected.


Edit: Another Note is that since your character's position is stored in an Integer variable, you are losing quite a bit of accuracy. If you attempt to store a float value in an integer variable, it simply chops off anything after the decimal point.

What if your character is supposed to move a distance of 0.1?
[Example]
A=0
A=A+0.1
`A would still equal zero here
[/Example]

After 10 cycles like this, your character would be one pixel off of what it should be.
Duncan161
13
Years of Service
User Offline
Joined: 15th Mar 2011
Location:
Posted: 22nd Mar 2011 13:54
Thanks for the help, sorry about the poor quality of the code I posted.
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 24th Mar 2011 05:41
No problem, did the code I posted work for you?
Just glancing at what I had posted, I noticed that there is no check to see if the character is on the ground before resetting the jump. (That means that the character would be able to keep "double jumping"). Assuming that the code works at all, a solution would be:

Login to post a reply

Server time is: 2024-11-24 06:47:36
Your offset time is: 2024-11-24 06:47:36