Character jumping control help needed

Hi guys. I'm currently working on a side-view RPG platformer game and I need help with character control. I managed to work on the basic controls (moving the character left-right), which was the easy part, but I couldn't find a way on how to control it to jump.

So, I've applied physics to my game and applied a linear impulse to my character towards the negative y to make it jump when I touch on the "Jump" button. It did jump as I expected, but I want to add a cooldown (or a timer) so that players won't be able to press jump while jumping. Here's when trouble came.

First, I tried to put a timer to it. So when I touch jump, the number decreases and I won't be able to jump until the number reaches 0 and resets to it's starting value. It worked on the first jump, but when I pressed jump on the second time, the timer decreases by 2 (it used to be 1). Then it decreases by 3 on the third jump, then 4, 5, 6, and so on. That means the gap between the jumps get shorter every time I jump.

Secondly, I tried the Collision version. Checking whether my character is touching (or colliding) with the floor or not. If yes, then I could hit jump to make the character jump. If no (or while the character is in mid-air), then I won't be able to hit the jump button. I've looked around but couldn't find how to control the jumping process. I've found some collision jumping codes, but it's for games like Jumping Doodle, where I won't have any controls on when I want the character to jump.

So here are my questions:
1. If I want to use the first version, how could I keep the amount the timer decreases each time I press jump to 1?
2. If I want to use the collision version, how could I control the jumps?

Sorry for writing so long, and thank you for reading, and your help.

Cheers,
Pascal

have a look at this it will gives you little idea

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
        
        local stand = display.newRect(0,315,1000,5)
        local hero = display.newCircle(40,10,15)
        hero.isColidedwithGround = false
        
        local physics = require "physics"
        physics.start()
        physics.addBody(stand,"static",{bounce = 0})
        physics.addBody(hero,{bounce = 0})
        
                
        local function onLocalCollision( self, event )
        
                        if event.phase == "began" then
                                hero.isColidedwithGround = true
                        end
        end
        hero.collision = onLocalCollision
        hero:addEventListener("collision",hero)
        
        local function jump()
                if hero.isColidedwithGround == true then
                        hero.isColidedwithGround = false
                        hero:applyForce(1,-3,hero.x,hero.y)
                end
        end
        Runtime:addEventListener("tap",jump)

Thanks a bunch!

Funny, I just found a solution with my countdown timer; I forgot to remove the listener.

Anyways, the collision version was the one I really wanted to apply to my game. So thank you again.

welcome dude

:)

views:1402 update:2012/1/9 8:53:30
corona forums © 2003-2011