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

2016/9/5

Beam Light Problems

1
2
3
Laurence Laurence

2016/9/5

#
Then what could be possibly creating the lamp object..? I haven't altered it and I'm still getting the object.
danpost danpost

2016/9/5

#
The beam will be added into the world where you placed it. The lamp object still has a rotation which the beam will adjust to. However, you cannot execute the act method of the beam unless the lamp is in the world -- you will get that error if the lamp is not in the world when you execute the act method of the beam. I will presume that the 'setRotation' method is called before calling the 'setLocation' method in the act method of the beam which will allow the rotation to be set before the error occurs.
danpost danpost

2016/9/5

#
Laurence wrote...
Then what could be possibly creating the lamp object..? I haven't altered it and I'm still getting the object.
You are still getting a Lamp object in your world with the last world class code posted? after re-compiling?
Laurence Laurence

2016/9/5

#
import greenfoot.*; 
 
public class Level1 extends World
{
    GifImage gif = new GifImage("Level1.gif");
    boolean colored = false;
    int size;
    GreenfootImage darkness;
 
    public Level1()
    {
        super(600, 400, 1); 
        setPaintOrder(Lamp.class, Beam.class);
        prepare();
    }
 
    public void act()
    {
        setBackground(gif.getCurrentImage());    
    }
    private void prepare()
    {
        Wreckage wreckage = new Wreckage();
        addObject(wreckage,350,295);
        wreckage.setLocation(323,279);
        Lamp lamp = new Lamp(); 
        CrashedShip crashedship = new CrashedShip();
        addObject(crashedship,142,246);
        crashedship.setLocation(34,377);
        crashedship.setLocation(23,379);
        Wau2 wau2 = new Wau2();
        addObject(wau2,181,263);
        wau2.setLocation(29,382);
        Wau2 wau22 = new Wau2();
        addObject(wau22,145,285);
        wau22.setLocation(14,115);
        wau22.setLocation(18,116);
        Wau2 wau23 = new Wau2();
        addObject(wau23,279,192);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(29,230);
        wau23.setLocation(3,317);
        Wau2 wau24 = new Wau2();
        addObject(wau24,259,265);
        wau24.setLocation(46,236);
        Wau2 wau25 = new Wau2();
        addObject(wau25,170,274);
        wau25.setLocation(31,274);
        Wau2 wau26 = new Wau2();
        addObject(wau26,201,296);
        wau26.setLocation(89,384);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(5,180);
        wau26.setLocation(6,308);
        wau26.setLocation(10,178);
        addObject(lamp, 300, 10);
        lamp.setRotation(90);
        addObject(new Beam(lamp, 40), 300, 10);
        Beam beam = new Beam(lamp, 40);
        addObject(beam, 300, 10);
        beam.act();
        
    }
}
I changed the code for the lamp to be in the middle of the room but weirdly enough no light is projected. I believe it's the 'Beam beam = new Beam(lamp, 40);' specifically the '40' part but I'm not sure what to change it to.
Laurence Laurence

2016/9/5

#
danpost wrote...
Laurence wrote...
Then what could be possibly creating the lamp object..? I haven't altered it and I'm still getting the object.
You are still getting a Lamp object in your world with the last world class code posted? after re-compiling?
Yes, I am but I put in the Lamp code you provided on the code just to make sure nothing messes up.
danpost danpost

2016/9/6

#
Remove line 91 from the code just given.
Laurence Laurence

2016/9/6

#
You don't have to explain this if you don't want to - but for me wanting to learn - why was removing line 91 able to fix it just by removing it? Did we not need it in the first place?
danpost danpost

2016/9/6

#
The lines following it does the same thing, as well as adjusts its position/rotation. When that line was in, you were creating two separate Beam objects for the same Lamp object. Both were being added into the world; but the first one was not being set rotationally until the scenario was started.
Laurence Laurence

2016/9/6

#
Okay, seems easy to understand why then, thanks!
Laurence Laurence

2016/9/6

#
Is there a way to put multiple beams? When I put two -
 lamp.setRotation(135);
        Beam beam = new Beam(lamp, 40);
        addObject(beam, 300, 5);
        beam.act();
        addObject(lamp, 600, 5);
        lamp.setRotation(100);
        addObject(beam, 300, 5);
        beam.act();
They all morph into a singular one which only follows the direction of the first command 'Lamp.setRotation(135);'
danpost danpost

2016/9/6

#
The class was not created with the intention of multiple beam object. The beam works by blocking out non-beam areas. This means that only beam areas are transparent. With two beams, only the intersecting areas of the beams will be lightened up. You might get away with changing the ambience of the beams, but then no area will be totally blocked out, just darker where no beam projects and lighter where beams intersect.
danpost danpost

2016/9/6

#
Laurence wrote...
When I put two - < Code Omitted > They all morph into a singular one which only follows the direction of the first command 'Lamp.setRotation(135);'
You need to create a separate Beam object for each source -- as well as create a separate source.
Laurence Laurence

2016/9/6

#
Ah, the general idea I'm trying to get at is widening the light source, maybe that's a more possible feat?
Laurence Laurence

2016/9/6

#
http://imgur.com/a/GyYof This is an image of the first level and what I've managed to accomplish! (The introduction, menu, and all that is done but this is the first level start background). It has alot of moving imagery which is sadly not displayed in the image. The backstory is responding to a unintelligible distress call only to be struck down (which is why the room seems to be bent with rain pouring in) and your ship is quickly overcome by an infectious substance. (Which is the black and blue stuff on the faintly-recognisable ship to the left).
danpost danpost

2016/9/6

#
Laurence wrote...
Ah, the general idea I'm trying to get at is widening the light source, maybe that's a more possible feat?
Try increasing the '40' to a larger number, maybe something like this:
Beam beam = new Beam(lamp, 60);
There are more replies on the next page.
1
2
3