PDA

View Full Version : about masking



farban
March 8th, 2009, 07:03 PM
I am using masks to create a flashlight effect. I have managed to mask the floor of the room but cant seem to mask the aliens as im unsure what code will mask the aliens. Here is the swf so you can see :) btw bugs is the aliens that i want to mask as well if that makes any sense.

here is the engine.as


private var thelight:light;
private var theplayer:player;
private var theroom:room;
//private var thebug:bug;
public static var enemyList:Array = new Array();
private var theHUD:HUD;

// private var numbugs:int = 1;



//private var intSwarm = setInterval(addSwarm, 10000);




//our constructor function. This runs when an object of
//the class is created

public function engine()
{

//private var theplayer:player = new player(stage);
//add it to the display list


//private var thelight:light = new light(stage);
//add it to the display list

//thebug = new bug(stage, bx , by);
thelight = new light(stage);
theplayer = new player(stage);
theroom = new room();
theroom.mask = thelight;
theHUD = new HUD(stage); //create our HUD







//stage.addChild(thebug);
stage.addChild(theroom);
stage.addChild(thelight);
stage.addChild(theplayer);
stage.addChild(theHUD); //and display it.

cbeech
March 9th, 2009, 10:33 AM
a simple way to do this would be to add the bugs as children of the floor, in that way you are masking the parent object rather than each of the bugs.

GrndMasterFlash
March 9th, 2009, 10:43 AM
or you could have an all black movie clip and a mask over it with the middle or "light" area empty and you could just keep that on a top layer.

farban
March 9th, 2009, 10:49 AM
what code would i have to use to add the bugs as a child of the floor ?

cbeech
March 9th, 2009, 12:53 PM
@GMF - yeah man perfectly simple way to do it as well, good call.

@farban - to add the bugs as members of the floor use something like:

theroom.addChild(thebug);

however, this will also depend on the structure of your classes. it seems as though bugs are being added regularly to the environment, and this 'may' be controlled in your thebug class. it seems as though you also must pass the scope of the parent to the class, most likely for propagation and removal(?) if so you should pass thefloor as this scope. you will also need to account for any other calculations being made during hitTesting and inter-class communications.