| Exploring the Dark Room Using the Masking Property in Action Script 3 |
|
|
|
| Written by Waleed Al-Bahrawy | ||
| Tuesday, 10 February 2009 12:09 | ||
|
Using the masking property in Action Script 3 an object can mask the content of another object. The masking object will show only the content of the masked object that is in it's range. Many game developers are using this property in their games and I used it in my game Sky MazezZ (starting from level 15), where the level will be dark and the player can only see a limited area of the maze and doesnt know what is coming.
The above example has the same idea and this is what i did to make it : 1-I drew a map and converted it to a symbol movie clip and called it map.
2- I drew two circles, one for masking and called it maskBall and the other is the visible one and called it you. So you will move in the dark and maskBall will show the area around it!!
3- Then I did the masking part using Action Script.
Here is the code I used to make it.
Description of the code:
Line 1: This is the most important line in the code because it will do the masking for us. map.mask=maskBall;
This code means that the mask of map is maskBall. So all the parts of the map will not be visible except the parts the mask covers.
Line 2: This line has the variables for the movement of the ball. Their values will be changed by two functions keyPressedUp and keyPressedDown. Lines 8-28: These lines have the moveIt function that is resposible for the movement of you and maskBall.
Lines 26-27: Are assigning the position of you to the position of maskBall. So they will move together as one part.
Lines 30-43: These lines have the keyPressedDown which will detect the user's keyboard presses using the KeyboardEvent event.
Lines 45-58: These lines have the keyPressedUp which will detect if the user released the key using the KeyboardEvent event.Thats It!!!
You will find the source file in the attachments below.
Related Articles
|
||
| Last Updated on Thursday, 12 February 2009 01:07 |
Copyright © 2009 FreshNova, by Talha Kalim and Waleed Al-Bahrawy






Comments