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

2019/7/11

Working with Colors

Proprogrammer04 Proprogrammer04

2019/7/11

#
I tryed to work with Colors, but I don't seem to get it... What do you need to import or write, so that it works? Please help(!)
danpost danpost

2019/7/11

#
Use:
import greenfoot.*;
(which you probably already have). Do not use:
import java.awt.Color;
or anything similar.
Proprogrammer04 Proprogrammer04

2019/7/12

#
import greenfoot.*;
Is already in the code, but if I just weite something like:
Color(255;0;0);
It does not work...
danpost danpost

2019/7/12

#
Proprogrammer04 wrote...
if I just weite something like:
Color(255;0;0);
It does not work...
Use commas instead of semicolons.
Proprogrammer04 Proprogrammer04

2019/7/14

#
I corrected that, but it still doesn't accept the Code. I watched a tutorial About this, and there he wrote something like:
    public void act() 
    {
        GreenfootImage draw = new GreenfootImage(100,100);
        draw.setColor(Color.BLUE);
        draw.drawLine(400,450,500,450);
        setImage(draw);
    }    
But if I run the Scenario, the line does not appear anywear on the screen... (The World is 900 by 900)
Proprogrammer04 Proprogrammer04

2019/7/14

#
I red an discussion about a similar problem, and the line shows up by now. Still there is the Problem with the Color...
Super_Hippo Super_Hippo

2019/7/14

#
Your image has a width of 100 and a height of 100. Your line is outside the image and therefore not visible.
Proprogrammer04 Proprogrammer04

2019/7/14

#
The Image is there, I can see a White line and ist doing what I want it to do, but it's White...
Super_Hippo Super_Hippo

2019/7/14

#
Again, you have an image which has the size 100/100. You have to draw inside this image (0..99 for x and y) if you want to see it. You draw from (400|450) to (500|450) which is outside the image. Imagine you have a piece of paper lying on a desk. If you draw on the desk, then it won't be visible on the paper.
Proprogrammer04 Proprogrammer04

2019/7/19

#
I know and I already fixed that... Now i‘s drawing on the background. But I cant change the color. I wachef an tutorial where he used something like this:
getWorld().setColo(Color.RED);
But when I tried this, it threw some errors back...
danpost danpost

2019/7/19

#
(1) getWorld returns a World object -- not a GreenfootImage object, which you can set the drawing color of; (2) setting the drawing color does not automatically change anything that was previously drawn; you must redraw the line after setting the new color;
You need to login to post a reply.