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

2019/12/1

drawLine() change color of some lines but not all?

MaDrexan MaDrexan

2019/12/1

#
Hey, i drew a few lines from point to point with this code (actor class):
getWorld().getBackground().drawLine(x1, y1, x2, y2);
Now i want to change the color of some lines in red but not all. So there are some red and white lines. I tried this code here to change color in red:
getWorld().getBackground().setColor(new Color(255, 0, 0));
but it says "incompatible types: java.awt.Color cannot be converted to greenfoot.Color". And i tried this in my world class:
int r = 255;
        int g = 0;
        int b = 0;
        getBackground().setColor(new Color(r, g, b));
But in this case all lines change in red instantly, even though i drew the white lines before this method. Can anyone tell me wich code i should use for drawing red lines without replacing the white ones?
danpost danpost

2019/12/1

#
Remove the following line at the top of the class:
import java.awt.Color.*;
MaDrexan MaDrexan

2019/12/1

#
@danpost omg thx
You need to login to post a reply.