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

2015/11/12

Drop an actor

IsabelSchouten IsabelSchouten

2015/11/12

#
Hi everyone, I have a problem. When i push the down arrow, the actor is supposed to fall all the way down the world, unless there is another actor, then the actor falls on the other actor. My code does not work as how i want it to work because sometimes the actor falls in another actor, so the other actor is underneath the actor which has fallen. Does anybody know what i did wrong in my code?
//fall down
            while (!isTouching(Bal.class) && getY() < getWorld().getHeight() - 1) // Werkt niet, moet while one.class, two.class enzo ook zijn
            {
                setLocation(getX(), getY()+1);
            }
            setLocation(getX(), getY()-1);
            active = false;
            ((SpeelVeld) getWorld()).spawnNewBal();
        }
    }
}
danpost danpost

2015/11/12

#
First off, this is not the entire code that controls the actor. Also, using 'while' will cause the actor to find another actor or the bottom of the world instantly (the actor will not move, but transport without visually passing through the points between where it starts and where it "should" end up.
You need to login to post a reply.