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

2015/3/7

how to make a car actor stop when the light actor sets its image to red light

1
2
Rayray Rayray

2015/3/7

#
public class TrafficLights extends World
{

    /**
     * Constructor for objects of class Traffic.
     * 
     */
    public TrafficLights()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1); 
        addObject(new Car(), 10, 25);
       addObject(new Sensor(), 300, 25);
        addObject(new Light(), 555, 165);
    }
}
i forgot to mention it would work with a parameter light so i did private trafficlight light = new trafficlight but now ive changed it back to how you set out in the sensor class now theres a problem with addObject(Sensor(), it says constructor Sensor in class Sensor cannot be applied to given types; required:Light found:no arguments
Rayray Rayray

2015/3/7

#
without* not with parameter
danpost danpost

2015/3/7

#
Change what you had above to this:
public class TrafficLights extends World
{
    public TrafficLights()
    {    
        super(800, 600, 1); 
        addObject(new Car(), 10, 25);
        Light light = new Light();
        addObject(new Sensor(light), 300, 25);
        addObject(light, 555, 165);
    }
}
Rayray Rayray

2015/3/7

#
the sensor "light" still doesnt match the traffic lights coordinates for some reason
Rayray Rayray

2015/3/7

#
do not worry i didnt see you put addObject(light) i left it as New Light() thank you!!!!!!!!!!!!!
You need to login to post a reply.
1
2