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

Report as inappropriate.

danpost presents ...


Light Beam Class Demo

A demonstration of a class that follows a 'light source' object that emits a beam of light. The 'Beam' class is fully documented with instructions on use (which is very easy). Includes methods to vary different aspects of the object.

Note: only one object of this class should be used at any time.

3462 views / 12 in the last 7 days

7 votes | 0 in the last 7 days

Tags: demo with-source class light danpost support support-class dark ambiance

This scenario is a member of: Support Classes by danpost

open in greenfoot
Your browser does not support the canvas tag.
i did this for a blue-green glow: image.setColor(new Color(20, 200, 100, 255-intensity));


Thanks for your help!
no problem


Would it be possible for this to follow an actor and point in the direction of the cursor?


@Laurence, if the actor points in the direction of the cursor, then the beam will also. The beam will always follow the "source" actor and point in the same direction that actor faces.


public class Lamp extends Actor { int dir = 0; /** * Act - do whatever the Lamp wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { setRotation(90); } } I've made a simple 'lamp' image and indeed it turns 90 degrees but the beam stares straight forward weirdly enough.


@Laurence, start a discussion thread on this. Show your complete world class and Lamp class codes and explain the problem and what the fix should do.


A new version of this scenario was uploaded on 2016-12-07 05:02:42 UTC Some "collision" methods added.
A new version of this scenario was uploaded on 2016-12-07 05:03:07 UTC Some "collision" methods added.

See all comments

Want to leave a comment? You must first log in.

Who likes this?

JetLennit FlyingRabidUnicornPig birdy funkyflappy davemib123 miles7191 nooby123