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

2021/3/3

Having a Problem on a Jump Animation with falling onto a Ground

trGhuul trGhuul

2021/3/3

#
I made a Animation on Jumping but whenever I add the vSpeed in the getOneObjectAtOffset, my Animation switches between my Idle/Running and the Jump/Fall animation. If i remove it my character continues to go into the ground. hope somebody can help :3 checkFall() is in act-method and jump is in a while(Space %% onGround() == true)
public boolean onGround()
    {
        Actor a = getOneObjectAtOffset(0, RIR.getCurrentImage().getHeight()/2, GROUND.class);
        if(a == null)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
public void jump()
    {
        vSpeed=-jumpStrenght*8;
        fall();
    }
public void checkFall()
    {
        if (onGround() == true)
        {
            vSpeed = 0;
        }
        else
        {
            fall();
        }
    }
public void fall()
    {
        setLocation (getX(), getY() + vSpeed);
        vSpeed = vSpeed + acceleration;
        if(vSpeed < 0)
        {
            setImage("ROGUE_JUMPING_" + DIRECTION + ".png");
        }
        if(vSpeed == 0)
        {
            setImage("ROGUE_JUMPING_TURN_" + DIRECTION + ".png");
        }
        if(vSpeed > 0 && DIRECTION == "LEFT")
        {
            setImage(RFL.getCurrentImage());
        }
        if(vSpeed > 0 && DIRECTION == "RIGHT")
        {
            setImage(RFR.getCurrentImage());
        }
    }
trGhuul trGhuul

2021/3/3

#
while(Greenfoot.isKeyDown("Space") && onGround() == true); ****
danpost danpost

2021/3/4

#
trGhuul wrote...
while(Greenfoot.isKeyDown("Space") && onGround() == true); ****
Should use if, not while. Not sure if it makes any difference, but replace "Space" with "space" to be sure.
You need to login to post a reply.