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

2013/5/28

Problem with color code! Help!

Kiara Kiara

2013/5/28

#
I'm learning how to use color in an image, but I'm having some trouble. This is just a test, but I have a ball and when I click this ball I want it to turn black. This is the code:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class Ball here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Ball extends Actor
{
    private Color color2 = Color.BLACK;  
    /**
     * Act - do whatever the Ball wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        paint();
    }    
    public void paint()
    { 
        if(Greenfoot.mouseClicked(this))
        {
            GreenfootImage img = new GreenfootImage(20,100);
            img.setColor(color2);
            setImage(img);
        }
    }
}
All help appreciated.
Kiara Kiara

2013/5/28

#
help, please?
davmac davmac

2013/5/28

#
The 'setColor' method just changes the color that will be used to draw on the image with the drawing methods; it doesn't change the color of the image. You need to draw on the image after setting the color.
You need to login to post a reply.