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

2018/10/30

What does this code do?

iamdsd iamdsd

2018/10/30

#
public void act()
    { 
        setImage(images[imageNo]);

        imageNo += increment;
        if(imageNo >= IMAGE_COUNT) 
        {
            increment = -increment;
            imageNo += increment;
        }
        
        if(imageNo < 0) 
        {
            getWorld().removeObject(this);
        }
    }
danpost danpost

2018/11/4

#
iamdsd wrote...
What does this code do? << Code Omitted >>
It appears to animate an actor in such a way as to go forward in some way (maybe change or grow or progress and then go backward (maybe revert or shrink or regress). This action is done one time and the actor is them removed from the world. Lines 3 and 5 iterate through the images in the array. The first if block reverses the direction that the images in the array are being used. The second if block removes the actor after the last image going in reverse is used. To make more clear, the code could be used to animate an explosion (where its image grows and dissipates).
You need to login to post a reply.