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

2018/10/30

What does the value<target string mean?

BH54 BH54

2018/10/30

#
public void act() 
    {
        if (value < target) {
            value++;
            updateImage();
        }
        else if (value > target) {
            value--;
            updateImage();
        }
    }
danpost danpost

2018/10/30

#
BH54 wrote...
What does the value<target string mean? << Code Omitted >>
This particular Counter class has an animated score display. If, let us say, 5 points was to be added to the score, the true score is set as a target for which the value of the counter (which is displayed) is to more slowly progress to. So, if the value of the counter was zero (as is the value of target), when 5 is added, target is set to 5 and the displayed value will be seen to be "rolling" up to the new "target" value. The act method basically says to change the shown value by one toward the target value if they are not both equal (each act cycle).
You need to login to post a reply.