Jumping object loop (player:applyLinearImpulse(0, -7, player.x, player.y))

I am looking for a way to loop/repeat a jumping command. I’ve been messing around with this and I saw some repeat options in the transitionto commands, but I don’t know how to apply something like that to this.

I am also aware that I’ll need to sense when I hit ground so I don’t go double jumping all the time :slight_smile: I’ll get to that, I just want to know how to repeat something like jumping. If you want to add the ground sensing stuff, please go ahead!
So I have this code, I start the game from my main.lua and the player jumps once. That’s cool, but now I want it to repeat jump (something along the lines of doodlejump, but totally different game, just the jumping mechanic I am after here).
Here is the code for applying linearimpulse which works right now.

player:applyLinearImpulse(0, -7, player.x, player.y) [import]uid: 61600 topic_id: 11880 reply_id: 311880[/import]

Ok this is making me mad. I can’t seem to figure out how to loop something over and over again.

I guess that will teach me, being brand new to corona sdk + lua for just a hair over a month now.

BAH! [import]uid: 61600 topic_id: 11880 reply_id: 43430[/import]

Anyone?

Hmmm [import]uid: 61600 topic_id: 11880 reply_id: 43913[/import]

I’m sorry Nick! I thought this was your old thread. My bad!

There are a few ways to loop things but the simplest/most common would be by using a timer.

Try this;

[lua]function jump (event)
player:applyLinearImpulse(0, -7, player.x, player.y)
end

jumpTimer = timer.performWithDelay(1000, jump, 0)[/lua]

The reason I named it “jumpTimer” was so it was easy to cancel if using director and changing scenes.

Make sense?

Also, you’ll want to play with that “1000”, every second would likely be too frequent.

Peach :slight_smile: [import]uid: 52491 topic_id: 11880 reply_id: 44015[/import]

OH SNAP.

Peach you roX0rs. That is exactly what I was looking for.
I feel some donations coming soon :slight_smile:
Ok so the *minor* stuff that goes with this:

–If I want the actor to jump, but not double jump - how is this done?
(the way I understand it is it has something to do with if actor is touching the ground then allow the jump, but when it’s not ground then dont)

In other news:

I got my apple dev license and my Corona SDK iOS license.

I have just about everything I wanted to do in my game figured out a couple of minor things I’m still sorting out but the “core” game play element is now there.

46 days into corona from being total noob (I still am lol) and knowing JACK DOODLEDEE about programming (I can barely do math as well lol) I am coming along OK.

Yea this is really exciting!

Thanks a bunch peach, that was the ticket! [import]uid: 61600 topic_id: 11880 reply_id: 44044[/import]

You know my Corona For Newbies Part 4? (Phyiscs?) I believe you do :slight_smile:

If you check out how it prints when my picture hits the ground, that’s how we’d stop a double jump.

Set up a variable called, for example, onFloor = true

Then rather than printing on collision with the ground, do onFloor = true

When they hit a jump button, do onFloor = false.

Make sense? :slight_smile:

Grats on your licenses :slight_smile: [import]uid: 52491 topic_id: 11880 reply_id: 44177[/import]