This site requires JavaScript, please enable it in your browser!
Greenfoot back
Tietie12
Tietie12 wrote ...

2020/1/14

how to put a delay or pause on a method

Tietie12 Tietie12

2020/1/14

#
im trying to make a double jump method for my game the method works but it registers the button presses to fast and just jumps forever
1
2
3
4
5
6
7
8
9
10
11
public void doubleJump()
    {
        if (numJumps == 1)
        {
            vSpeed = -jumpStrength;
            setImage(new GreenfootImage("PlayerDouble.png"));
 
            fall();
 
        }
    }
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
public void act()
    {
 
        if (Greenfoot.isKeyDown("left"))
        {
            moveLeft();
            Actor p = this.getOneIntersectingObject(Platforms.class);
            if(p != null)
            {
                moveRight();
            }
        }
        if(Greenfoot.isKeyDown("right"))
        {
            moveRight();
            Actor p = this.getOneIntersectingObject(Platforms.class);
            if(p != null)
            {
                moveLeft();
            }
        }
        if (Greenfoot.isKeyDown("up") && onPlatforms() && numJumps < 2)
        {
            jump();
            numJumps++;
 
        }
        hitSpike();
        hitGoal();
        if (onPlatforms())
        {
            vSpeed = 0;
            numJumps = 0;
            setImage(new GreenfootImage("Player.png"));
        }
        else
        {
            fall();
        }
        if (Greenfoot.isKeyDown("up") && numJumps < 2 && dbJumped == false)
        {
            doubleJump();
            dbJumped = true;
 
        }
    }
here is the code i have for movement and for double jump i am looking for a way to slow down how fast it registers a button click
danpost danpost

2020/1/14

#
You may want to increment numJumps on the 2nd jump (in your doubleJump method).
Tietie12 Tietie12

2020/1/14

#
i put the numJumps++ in the method for double jump and now when i press the jump key it makes numJumps = 2. i am unsure as to how to make it only add one for the first jump and then if it is at 1 jump a second time and if its at numJumps = 2 fall down and then it will reset when it hit the platform
danpost danpost

2020/1/15

#
You may be able to delay the double jump so that it only happens near the apex of the first jump by adding the condittion:
1
if (vSpeed == -1)
Tietie12 Tietie12

2020/1/16

#
do you mean replace the if statement for double jump with that condition? i am just confused to where i should add that condition.
danpost danpost

2020/1/16

#
Tietie12 wrote...
do you mean replace the if statement for double jump with that condition? i am just confused to where i should add that condition.
I mean to add it to the condition you already have.
You need to login to post a reply.