Game Development Reference
In-Depth Information
player.bitmapData = player.animationList[0];
render();
dispatchEvent(new CustomEventLevelScreenUpdate(CustomEventLevelScreenUpdate.
UPDATE_TEXT, String(level)));
dispatchEvent(new CustomEventSound(CustomEventSound.PLAY_SOUND,
Main.SOUND_MUSIC_IN_GAME, true, 999, 8, 1));
customScoreBoardEventLevel.value = level.toString();
dispatchEvent(customScoreBoardEventLevel);
}
The newLevel function does a lot of game logic. Let's step through the major actions of this function:
1.
First, it adds 1 to the current level value. If the current level is greater than maxLevel ,
it will be set back to 1 .
2. Using the current level integer value, we pull a color from the levelColors array and
set the levelColor class variable. This will be used for the Mine glow, the Particle
glow, and for a glow around the entire level. Here is the levelColors Array from the
variable definition section.
private var levelColors:Array = [NaN, 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0x00ffff,
0xffaa00, 0xaaff00, 0x00ffaa, 0x00aaff];
3.
The spriteGlowFilter is set with the new levelColor value, and then the mine,
particle, and background assets are drawn for the level with their respective creation
functions. The particle pool is also created.
4.
The special glow filter for the entire canvasBitmap is set to the levelColor , and then it
is applied by adding to the filters array for the cavasBitmap .
5.
The player object is initialized to the center of the screen and it set to the 0 frame
(facing up).
6.
The render function is called to ensure that the screen is drawn for the level transition
fade in.
7.
Events are fired off to set the levelScreen text, play the in-game music, and change
the level value text on the scoreBoard . Notice that we are using the class-level shared
event for the scoreBoard update.
Note that we have only created class level shared events for the scoreBoard updates, but we
could actually make them for the soundManager events and even the levelScreen update if we
wanted to continue to utilize these optimizations.
Let's take a look at the createLevelBackground function now:
private function createLevelbackground():void {
//*** background
drawingCanvas.filters = [spriteGlowFilter];
//draw symbol on background
Search WWH ::




Custom Search