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

2020/4/28

greenfoot autumn 1 scenario

lottie lottie

2020/4/28

#
what does delta mean in the line "private int delta =2;" ?
danpost danpost

2020/4/28

#
lottie wrote...
what does delta mean in the line "private int delta =2;" ?
"delta" usually refers to a small amount of change. Alone, it does not tell you what is changing. You could post the entire class for a chance at a better response.
lottie lottie

2020/5/1

#
danpost wrote...
lottie wrote...
what does delta mean in the line "private int delta =2;" ?
"delta" usually refers to a small amount of change. Alone, it does not tell you what is changing. You could post the entire class for a chance at a better response.
/**
 * A block that bounces back and forth across the screen.
 * 
 * @author Michael Kölling
 * @version 0.1
 */
public class Block extends Actor
{
    private int delta = 2;
    
    /**
     * Move across the screen, bounce off edges. Turn leaves, if we touch any.
     */
    public void act() 
    {
        move();
        checkEdge();
        checkMouseClick();
    }
    
    /**
     * Move sideways, either left or right.
     */
    private void move()
    {
        setLocation(getX()+delta, getY());
    }
    
    /**
     * Check whether we are at the edge of the screen. If we are, turn around.
     */
    private void checkEdge()
    {
        if (isAtEdge()) 
        {
            delta = -delta;  // reverse direction
        }
    }
    
danpost danpost

2020/5/1

#
So, "delta" is the small change in position (horizontally, in this case) performed each act cycle. Usually, you will find "speed" or "xSpeed" referring to this value.
lottie lottie

2020/5/1

#
thank you!
You need to login to post a reply.