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

2019/4/25

MOVE ACTOR DOWN CONTINOUSLY UNTIL IT HIT ANOTHER ACTOR THEN STOP

gdrgnxxi gdrgnxxi

2019/4/25

#
how can i make my object slide downwards with just pressing the key "ENTER" then it will only stop moving downwards when it is touching the other actor.
danpost danpost

2019/4/25

#
private int ySpeed = 0;

public void act()
{
    if (ySpeed == 0 && Greenfoot.isKeyDown("enter")) ySpeed = 1; // start
    setLocation(getX(), getY()+ySpeed); // move
    if (isTouching(Actor.class)) setLocation(getX(), getY()-ySpeed); // stop (negates move)
}
You need to login to post a reply.