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

2014/8/18

add rectangle and fading

davemib123 davemib123

2014/8/18

#
Hi, Ive created a Rectangle class:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;

/**
 * Write a description of class Misc here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Rectangle extends Tiles
{
    int timer;
    public Rectangle(int countDown)
    {
        GreenfootImage LittleRectangle = new GreenfootImage(8, 14);
        LittleRectangle.setColor(new Color(0, 0, 0));  
        LittleRectangle.fillRect(0, 0, 8, 14);
        setImage(LittleRectangle);
        LittleRectangle.setTransparency(255);
        this.speed = 1;
        timer = countDown;
    }

    /**
     * Act - do whatever the Misc wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        animationCounter ++;
        timer--;
        if (timer <= 0)  
        { 
            fadeOut();
        }
    }    

    public void fadeOut()
    {
        GreenfootImage Transition = getImage();
        Transition.setTransparency(Transition.getTransparency() - speed);
        animationCounter++;
        if(Transition.getTransparency() <= 5)
        {
            getWorld().removeObject(this);
        }
    }
}
In my world class I am using this to create a block of rectangles:
 public void addRectangles()
    {
        for(int i=29 ; i<425 ; i+=8) {
            for(int j=282 ; j <= 340 ; j += 14) {
                addObject(new Rectangle(i + 25), i, j);
            }
        }
    }
How do I get each of the small rectangles to fade out line by line instead of all together?
davemib123 davemib123

2014/8/18

#
nevermind, think I have it done :D
You need to login to post a reply.