LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Jumping and background collision

Root / Programming Questions / [.]

ChaseCZCreated:
How do i make a sprite jump? And how to make a good background collision using arrays and bgget? I know i'm just spamming threads about bg collision but nobody just helped me yet. This is what i have so far... The top and bottom collision is alright but the right and left is super glitchy. Then the jumping is weird because when i press B it just decreases Y by 30, so the sprite just teleports. It would be nice if you made an example program or example code, thanks!
Typo fixthanks 12me21 for fixing the typo in the title

im wondering about bg collision too! that why i post here. in nellr heighboo i just used x,y coordinates, but that took forever, so i want to learn about bg collision with bgget.

How do i make a sprite jump? And how to make a good background collision using arrays and bgget? I know i'm just spamming threads about bg collision but nobody just helped me yet. This is what i have so far... The top and bottom collision is alright but the right and left is super glitchy. Then the jumping is weird because when i press B it just decreases Y by 30, so the sprite just teleports. It would be nice if you made an example program or example code, thanks!
Typo fixthanks 12me21 for fixing the typo in the title
For jumping, you should have a variable for gravity and velocity. Gravity should best be equal to something less then 1 like 0.2 or 0.3. Velocity can be equal to 0. It sounds like you already know about while and wend if you can use the buttons and they work. Think of it like this, if the b button is pushed and you are not already jumping (jump==0) then jump==true or jump==1 and velocity is equal to a small negative number like -4 or -3 or -2. After that, increment the velocity by gravity and your y postion by velocity. You should have something to land on so you don't just drop out of the screen, so make a temporary floor with (if y>180 then y=180. Just before the end of the loop, jump and velocity should equal zero again. Don't forget your vsync. When you get jumping right, use bgget inside of your loop. Then, if the bgget for what is beneath the sprite is turns out true, then velocity=0. Something similar to that, and bugs can be worked out later.