public override void OnExit()
        {
            base.OnExit();

            HitMeButton.ButtonUpAction -= HandleHitMeButtonButtonUpAction;
            PauseButton.ButtonUpAction -= HandlePauseButtonButtonUpAction;
            QualityManager.MatchScoreDetected -= HandleQualityManagerMatchScoreDetected;
            QualityManager.FailedMatchDetected -= HandleQualityManagerFailedMatchDetected;
            CardManager.Instance.NoMatchesPossibleDetected -= HandleCardManagerInstanceNoMatchesPossibleDetected;
            GameScene.LevelChangeDetected -= HandleGameSceneLevelChangeDetected;
            GroupCrystallonEntity.BreakDetected -= HandleGroupCrystallonEntityBreakDetected;
            PausePanel.QuitButtonPressDetected -= HandlePausePanelQuitButtonPressDetected;
            PausePanel.ResetButtonPressDetected -= HandlePausePanelResetButtonPressDetected;
            CubeCrystallonEntity.CubeCompleteDetected -= HandleCubeCrystallonEntityCubeCompleteDetected;
            CardManager.Instance.CardSpawned -= HandleCardManagerInstanceCardSpawned;
            if(GameScene.currentLevel == 999) {
                GameTimer.BarEmptied -= HandleGameTimerBarEmptied;
                GameTimer.BarFilled -= HandleGameTimerBarFilled;
                if (BonusBar != null) {
                    BonusBar.BarFilled -= HandleBonusBarBarFilled;
                    BonusBar.BarEmptied -= HandleBonusBarBarEmptied;
                }
                (_nextLevelPanel as InfiniteModeEndPanel).RetryDetected -= HandlePausePanelResetButtonPressDetected;
                (_nextLevelPanel as InfiniteModeEndPanel).QuitDetected -= Handle_nextLevelPanelQuitButtonPressDetected;
            } else {
                (_nextLevelPanel as NextLevelPanel).ReplayDetected -= HandlePausePanelResetButtonPressDetected;
                (_nextLevelPanel as NextLevelPanel).NextLevelDetected -= Handle_nextLevelPanelButtonButtonUpAction;
                (_nextLevelPanel as NextLevelPanel).QuitDetected -= Handle_nextLevelPanelQuitButtonPressDetected;
                (_nextLevelPanel as NextLevelPanel).LevelSelectDetected -= Handle_nextLevelPanelLevelSelectDetected;
            }

            _nextLevelPanel = null;
            HitMeButton = null;
            PauseButton = null;
            pausePanel = null;
            levelTitle = null;
            _messagePanel = null;
            _scene = null;

            #if METRICS
            if(ExitCode == LevelExitCode.NULL){
                DataStorage.CollectMetrics();
            }
            DataStorage.RemoveMetric("Goal");
            DataStorage.RemoveMetric("Score");
            DataStorage.RemoveMetric("Time");
            DataStorage.RemoveMetric("No-Match Time");
            DataStorage.RemoveMetric("Met-Goal Time");
            DataStorage.RemoveMetric("Breaks");
            DataStorage.RemoveMetric("Hit Me");
            DataStorage.RemoveMetric("Exit Code");
            #endif
        }
        private void Initialize()
        {
            FontMap map = FontManager.Instance.GetMap( FontManager.Instance.GetInGame("Bariol", 25, "Bold") );
            FontMap bigMap = FontManager.Instance.GetMap( FontManager.Instance.GetInGame("Bariol", 44, "Bold") );

            // CREATE PAUSE MENU
            pausePanel = new PausePanel(_scene);
            _scene.DialogLayer.AddChild(pausePanel);
            pausePanel.Hide();

            // CREATE THE HUD BAR AT THE TOP OF THE SCREEN
            GameHudBar = new Node(){
                Position = new Vector2(0.0f, 473.0f)
            };
            this.AddChild(GameHudBar);

            HudBarMask = Support.UnicolorSprite("white", 255, 255, 255, 255);
            HudBarMask.Color = LevelManager.Instance.BackgroundColor;
            HudBarMask.Scale = new Vector2(60.0f, 4.4375f);
            GameHudBar.AddChild(HudBarMask);

            // CREATE THE LEVEL TITLE HUD
            levelTitle = new LevelTitleMkTwo() {
                SlideInDirection = SlideDirection.RIGHT,
                SlideOutDirection = SlideDirection.LEFT,
                Offset = new Vector2(0.0f, 0.0f),
            //				Lifetime = 4.0f
            };
            this.AddChild(levelTitle, -1);

            // CREATE THE END-OF-LEVEL DROP-DOWN PANEL
            if (GameScene.currentLevel == 999) {
                // INFINITE MODE VERSION
                _nextLevelPanel = new InfiniteModeEndPanel(){
                    Offset = new Vector2(Director.Instance.GL.Context.Screen.Width-248.0f, 0.0f),

                };
            } else {
                // PUZZLE/TUTORIAL MODE VERSION
                _nextLevelPanel = new NextLevelPanel(){
                    Offset = new Vector2(510.0f, 0.0f),

                };
            }
            GameHudBar.AddChild(_nextLevelPanel, -1);

            // CREATE MESSAGE PANEL
            _messagePanel = new MessagePanel(920.0f, 148.0f ){
                SourceObject = this,
                Offset = new Vector2(20.0f, 0.0f),
                Position = new Vector2(0.0f, -148.0f),
                Lifetime = 0.0f
            };
            this.AddChild(_messagePanel);
            _messagePanel.body = GamePhysics.Instance.RegisterPhysicsBody(GamePhysics.Instance.SceneShapes[4], float.MaxValue, 0.0f, _messagePanel.Position / GamePhysics.PtoM);
            _messagePanel.AdHocDraw += () => {
                _messagePanel.body.Position = _messagePanel.Position / GamePhysics.PtoM;
            };

            // SCORE STUFF
            //			ScoreIcon = Support.SpriteFromFile("/Application/assets/images/handIcon.png");
            ScoreIcon = Support.SpriteFromAtlas("crystallonUI", "handIcon.png");
            ScoreIcon.Position = new Vector2(184.0f, 16.0f);
            ScoreIcon.RegisterPalette(1);
            GameHudBar.AddChild(ScoreIcon);

            ScoreTitleText = new Label("score", map);
            ScoreTitleText.Position = new Vector2(287, 25.0f);
            ScoreTitleText.RegisterPalette(1);

            BlueBox = Support.UnicolorSprite("white", 255,255,255,255);
            BlueBox.Scale = new Vector2(6.25f, 4.4375f);
            BlueBox.Position = new Vector2(354.0f, 0.0f);
            BlueBox.RegisterPalette(2);

            ScoreText = new Label("", bigMap) {
                Position = SCORE_TEXT_POS
            };
            ScoreText.RegisterPalette(1);
            GameHudBar.AddChild(ScoreText);

            // CUBE STUFF
            //			CubeIcon = Support.SpriteFromFile("/Application/assets/images/stopIcon.png");
            CubeIcon = Support.SpriteFromAtlas("crystallonUI", "stopIcon.png");
            CubeIcon.Position = new Vector2(20.0f,16.0f);
            CubeIcon.RegisterPalette(2);
            GameHudBar.AddChild(CubeIcon);

            CubesTitleText = new Label("cubes", map);
            CubesTitleText.Position = new Vector2(63.0f, 25.0f);
            CubesTitleText.RegisterPalette(2);

            RedBox = Support.UnicolorSprite("white", 255,255,255,255);
            RedBox.Position = new Vector2(130.0f, 0.0f);
            RedBox.Scale = new Vector2(6.25f, 4.4375f);
            RedBox.RegisterPalette(1);

            CubeText = new Label("", bigMap){
                Position = CUBES_TEXT_POS
            };
            CubeText.RegisterPalette(2);
            GameHudBar.AddChild(CubeText);

            // TIMER & STRIKES STUFF
            GameTimer = new TimerEntity();
            if (GameScene.currentLevel == 999) {	// ------------------- IF CHALLENGE MODE
                if(GameScene.gameTimeLimit > 0.0f) {
                    GameTimer.Position = new Vector2(348.0f, 16.0f);	// ----- ADD THE TIME BAR
                    GameHudBar.AddChild(GameTimer);
                } else {
                    BonusBar = new BonusTimer() {
            //						Position = new Vector2(348.0f, 44.0f)
                        Position = new Vector2(348.0f, 16.0f)
                    };
                    GameHudBar.AddChild(BonusBar);
                }

                Strikes = new StrikeHud() {
                    Position = new Vector2(395.0f, 44.0f)
                };
                GameHudBar.AddChild(Strikes);
            }

            // PAUSE BUTTON
            PauseButton = new BetterButton("/Application/assets/images/UI/BetterButtonTransparent.png", 115.0f, 71.0f) {
                Text = "",
            //				Icon = Support.SpriteFromFile("Application/assets/images/UI/pause.png"),
                Icon = Support.SpriteFromAtlas("crystallonUI", "pause.png"),
            //				Position = new Vector2(845.0f, 473.0f),
                Position = new Vector2(845.0f, 0.0f)
            };
            //			this.AddChild(PauseButton);
            GameHudBar.AddChild(PauseButton);
            PauseButton.background.RegisterPalette(2);
            PauseButton.background.Scale = new Vector2(115.0f/32.0f, 71.0f/16.0f);
            PauseButton.Icon.RegisterPalette(2);
            PauseButton.ButtonUpAction += HandlePauseButtonButtonUpAction;

            // HIT ME BUTTON
            HitMeButton = new BetterButton("/Application/assets/images/UI/BetterButtonTransparent.png", 115.0f, 71.0f) {
                Text = "",
            //				Icon = Support.SpriteFromFile("Application/assets/images/UI/plus.png"),
                Icon = Support.SpriteFromAtlas("crystallonUI", "plus.png"),
            //				Position = new Vector2(720.0f, 473.0f),
                Position = new Vector2(720.0f, 0.0f)
            };
            HitMeButton.On(!LevelManager.Instance.HitMeDisabled);
            //			this.AddChild(HitMeButton);
            GameHudBar.AddChild(HitMeButton);
            HitMeButton.background.RegisterPalette(1);
            HitMeButton.background.Scale = new Vector2(115.0f/32.0f, 71.0f/16.0f);
            HitMeButton.Icon.RegisterPalette(1);
            HitMeButton.ButtonUpAction += HandleHitMeButtonButtonUpAction;

            HudBarLine = Support.UnicolorSprite("white", 255, 255, 255, 255);
            HudBarLine.RegisterPalette(0);
            HudBarLine.Scale = new Vector2(60.0f, 0.125f);
            GameHudBar.AddChild(HudBarLine);

            _initialized = true;
        }
        // METHODS ----------------------------------------------------
        /// <summary>
        /// Initialize this instance.
        /// </summary>
        private void Initialize()
        {
            SlideInDirection = SlideDirection.RIGHT;
            SlideOutDirection = SlideDirection.LEFT;
            Width = Director.Instance.GL.Context.Screen.Width;
            Height = Director.Instance.GL.Context.Screen.Height;

            LevelTitleSlider = new HudPanel(){
                SlideInDirection = this.SlideInDirection,
                SlideOutDirection = this.SlideOutDirection
            };
            this.AddChild(LevelTitleSlider);

            LevelTitleLabel = new Label() {
                Text = "00",
                FontMap = Crystallography.UI.FontManager.Instance.GetMap(Crystallography.UI.FontManager.Instance.GetInGame("Bariol", 44, "Bold")),
                Position = new Vector2(30.0f, 0.75f * 544.0f)
            };
            this.AddChild(LevelTitleLabel);
            LevelTitleLabel.RegisterPalette(0);

            TapToDismissLabel = new Label() {
                Text = "tap to dismiss",
                FontMap = Crystallography.UI.FontManager.Instance.GetMap(Crystallography.UI.FontManager.Instance.GetInGame("Bariol", 25, "Bold")),
                Position = new Vector2( 20.0f, 20.0f)
            };
            TapToDismissLabel.RegisterPalette(0);
            this.AddChild(TapToDismissLabel);
            TapToDismissLabel.Visible = false;

            QualityNames = new List<Label>();

            IconSliders = new HudPanel[4];
            for( int i=0; i < IconSliders.Length; i++ ) {
                IconSliders[i] = new HudPanel() {
                    SlideInDirection = this.SlideInDirection,
                    SlideOutDirection = this.SlideOutDirection,
                    Width = Director.Instance.GL.Context.Screen.Width,
                    Height = Director.Instance.GL.Context.Screen.Height,
                    MoveDuration = ICON_MOVE_DURATION
                };
                float x = ( (float)IconSliders.Length - (float)i ) * 960.0f/( 1.0f + (float)IconSliders.Length );
                IconSliders[i].Position = new Vector2( x, 0.0f );
                IconSliders[i].Offset = new Vector2(x, 0.0f);
                IconSliders[i].Visible = false;
                this.AddChild(IconSliders[i]);
            }

            Icons = new Node[4];
            for( int i=0; i < Icons.Length; i++) {
                Icons[i] = Support.TiledSpriteFromFile("/Application/assets/images/icons/icons.png", 4, 2);
                float y = 544.0f/2.0f - (Icons[i] as SpriteTile).CalcSizeInPixels().Y/2.0f;
                Icons[i].RegisterPalette(i%3);
                Icons[i].Position = new Vector2(0.0f, y);
                IconSliders[i].AddChild(Icons[i]);
            //				Icons[i].Visible = false;
            }
            iconWidth = (Icons[0] as SpriteTile).CalcSizeInPixels().X;
            iconHeight = (Icons[0] as SpriteTile).CalcSizeInPixels().Y;
        }