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

2015/6/18

Continuously moving object?

miegoer miegoer

2015/6/18

#
I'm trying to make a green blob move continuously in one direction that is decided by the player but I don't have a clue how to make the blobs movement continuous? This is what I have so far:
    public void turnBlob()
    {
    if(Greenfoot.isKeyDown("left"))
    {
        turn(-1);
    }
    if(Greenfoot.isKeyDown("right"))
    {
        turn(1);
    }
    }
    /**
     * This method fires the blob.
     */
    public void fireBlob()
    {
    if(Greenfoot.mouseClicked(this))
    {
       
    }
    }
wabuilderman wabuilderman

2015/6/18

#
What you need to do is have a "speed" variable. increase the variable when you want it to move. In the act statement, simply call a move(speed) function. This way, if speed = 0, you don't move, if it is greater than 0, it will move forward.
You need to login to post a reply.