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

2 days ago

how to put a delay or pause on a method

Tietie12 Tietie12

2 days ago

#
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
public void doubleJump()
    {
        if (numJumps == 1)
        {
            vSpeed = -jumpStrength;
            setImage(new GreenfootImage("PlayerDouble.png"));

            fall();

        }
    }
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

2 days ago

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

2 days ago

#
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

yesterday

#
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:
if (vSpeed == -1)
Tietie12 Tietie12

23 hours ago

#
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

22 hours ago

#
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.