public override void AllocResources()
    {
      Dispose();
      using (Settings xmlreader = new MPSettings())
      {
        _hidePngAnimations = (xmlreader.GetValueAsBool("general", "hidepnganimations", false));
      }

      if (_filenames == null)
      {
        _filenames = new ArrayList();

        foreach (string filename in _textureNames.Split(';'))
        {
          if (filename.IndexOfAny(new char[] {'?', '*'}) != -1)
          {
            foreach (string match in Directory.GetFiles(GUIGraphicsContext.GetThemedSkinFile(@"\media\" + filename)))
            {
              _filenames.Add(Path.GetFileName(match));
            }
          }
          else
          {
            _filenames.Add(filename.Trim());
          }
        }
      }

      _images = new GUIImage[_filenames.Count];

      int w = 0;
      int h = 0;

      if (_images != null)
      {
        for (int index = 0; index < _images.Length; index++)
        {
          _imageId++;
          _images[index] = new GUIImage(ParentID, _imageId + index, 0, 0, Width, Height, (string) _filenames[index], 0);
          _images[index].ParentControl = this;
          _images[index].ColourDiffuse = ColourDiffuse;
          _images[index].DimColor = DimColor;
          _images[index].KeepAspectRatio = _keepAspectRatio;
          _images[index].Filtering = Filtering;
          _images[index].RepeatBehavior = _repeatBehavior;
          _images[index].DiffuseFileName = _diffuseFileName;
          _images[index].MaskFileName = _maskFileName;
          _images[index].OverlayFileName = _overlayFileName;
          _images[index].FlipX = _flipX;
          _images[index].FlipY = _flipY;
          _images[index].SetBorder(_strBorder, _borderPosition, _borderTextureRepeat,
            _borderTextureRotate, _borderTextureFileName, _borderColorKey, _borderHasCorners,
            _borderCornerTextureRotate);
          _images[index].TileFill = _tileFill;
          _images[index].AllocResources();
          //_images[index].ScaleToScreenResolution(); -> causes too big images in fullscreen


          if (_images.Length > index) w = Math.Max(w, _images[index].Width);
          if (_images.Length > index) h = Math.Max(h, _images[index].Height);
          if (_images.Length > index) _renderWidth = Math.Max(_renderWidth, _images[index].RenderWidth);
          if (_images.Length > index) _renderHeight = Math.Max(_renderHeight, _images[index].RenderHeight);
          if (_images.Length > index) _textureWidth = Math.Max(_textureWidth, _images[index].TextureWidth);
          if (_images.Length > index) _textureHeight = Math.Max(_textureHeight, _images[index].TextureHeight);
        }
      }

      int x = _positionX;
      int y = _positionY;

      if (_horizontalAlignment == HorizontalAlignment.Center)
      {
        x = x - (w / 2);
      }
      else if (_horizontalAlignment == HorizontalAlignment.Right)
      {
        x = x - w;
      }

      if (_verticalAlignment == VerticalAlignment.Center)
      {
        y = y - (h / 2);
      }
      else if (_verticalAlignment == VerticalAlignment.Bottom)
      {
        y = y - h;
      }

      for (int index = 0; index < _images.Length; index++)
      {
        _images[index].SetPosition(x, y);
      }
    }
    public override void Dispose()
    {
      base.Dispose();
      if (_images == null)
      {
        return;
      }

      _images.DisposeAndClear();
      _images = null;

      if (_filenames != null)
      {
        _filenames = null;
      }
    }
        //da initialisieren wir alles für den GuiHandler
        public Gui(RenderContext RC, RenderCanvas rCanvas, GameHandler gameHandler)
        {
            #region Variablen
            _rCanvas = rCanvas;
            var height = _rCanvas.Height;
            var width = _rCanvas.Width;

            _gameHandler = gameHandler;
            _guiHandler = new GUIHandler(RC);
            _mainmenuHandler = new GUIHandler(RC);
            _inGameHandler = new GUIHandler(RC);
            _highScoreHandler = new GUIHandler(RC);

            _guiDiffs = new GUIButton[4];
            _guiImageTomato = new GUIImage[10];
            _guiImages = new GUIImage[9];
            _highscoreBretter = new GUIImage[5];

            float textwidth;
            float texthight;
            _highscore = false;
            _neustart = true;
            _pause = true;
            _level = 1;

              #endregion

            #region Bilder
            //Hintergrund Startscreen
            _guiImages[(int)_btnimages.Startbild] = new GUIImage("Assets/startbild.png", 0, 0,-3, width, height);

            //Hintergrund Endscreen
            _guiImages[(int)_btnimages.Endbild] = new GUIImage("Assets/endbild.png", 0, 0, -3, width, height);

            //Maus-Nutzerinfo in Mainmenü einblenden
            _guiImages[(int)_btnimages.btniMouse] = new GUIImage("Assets/Mouse.png", width / 4, 0, -1, (int)(height / 1.322), height);

            //Fadenkreuz flexibel (Falls es zwecks Schwierigkeitsstufe kleiner werden soll)
            _aimimage = 80;
            _guiImages[(int)_btnimages.btniFadenkreuz] = new GUIImage("Assets/Fadenkreuz.png", width / 2 - _aimimage / 2, height / 2 - _aimimage / 2, -2, _aimimage, _aimimage);

            // Credits Klohaus
            _guiImages[(int)_btnimages.btniCreditsA] = new GUIImage("Assets/kloClosed.png", width - height, 0, -1, height, height);
            _guiImages[(int)_btnimages.btniCreditsB] = new GUIImage("Assets/kloOpen.png", width - height, 0, -1, height, height);

            #endregion

            #region Beschriftungen
            //Schriften
            _guiFontCabin12 = RC.LoadFont("Assets/Cabin.ttf", 12);
            _guiFontCabin14 = RC.LoadFont("Assets/Cabin.ttf", 14);
            _guiFontCabin18 = RC.LoadFont("Assets/Cabin.ttf", 18);
            _guiFontCabin100 = RC.LoadFont("Assets/Cabin.ttf", 100);
            _guiFontWESTERN30 = RC.LoadFont("Assets/WESTERN.ttf", 30);

            //Credits
            texthight = GUIText.GetTextHeight("So hoch.", _guiFontCabin18);
            textwidth = GUIText.GetTextWidth("Sooooooooo laaaaaang", _guiFontCabin14);
            _guiTextCredits1 = new GUIText("Ramazan Gündogdu", _guiFontCabin14, (width) - (int)(textwidth), (height / 3)+ (int)(texthight/2), new float4(1, 1, 1, 1));
            _guiTextCredits2 = new GUIText("Kathleen Hübel", _guiFontCabin14, (width) - (int)(textwidth), (int)(_guiTextCredits1.PosY + texthight), new float4(1, 1, 1, 1));
            _guiTextCredits3 = new GUIText("Linda Schey", _guiFontCabin14, (width) - (int)(textwidth), (int)(_guiTextCredits2.PosY + texthight), new float4(1, 1, 1, 1));
            _guiTextCredits4 = new GUIText("Susanne Schmidt", _guiFontCabin14, (width) - (int)(textwidth), (int)(_guiTextCredits3.PosY + texthight), new float4(1, 1, 1, 1));
            _guiTextCredits5 = new GUIText("Tobias Winterhalder ", _guiFontCabin14, (width) - (int)(textwidth), (int)(_guiTextCredits4.PosY + texthight), new float4(1, 1, 1, 1));

            //Eingabetext Name für Highscore
            texthight = GUIText.GetTextHeight("Lorem ipsum", _guiFontCabin18);
            textwidth = GUIText.GetTextWidth("Write name: ", _guiFontCabin18);
            _name = new GUIText("Write name: ", _guiFontCabin18, (width / 2) - (int)(textwidth), (height / 2), new float4(0, 0, 0, 1));
            nameInput = new GUIText("", _guiFontCabin18, (width / 2), (height / 2), new float4(1, 1, 1, 1));

            //Text Mainmenü: Scha(r)fschießen
            textwidth = GUIText.GetTextWidth("Scha(r)fschießen", _guiFontWESTERN30);
            _guiTextTitel = new GUIText("Scha(r)fschießen", _guiFontWESTERN30, (width/2) - (int) (textwidth/2), (height/3));
            _guiTextTitel.TextColor = new float4(0, 0, 0, 1);

            // Text InGame
            textwidth = GUIText.GetTextWidth("Time: ", _guiFontCabin18);
            texthight = GUIText.GetTextHeight("Time: ", _guiFontCabin18);
            _guiText1 = new GUIText("Time: " + _countdown, _guiFontCabin18, (int)textwidth, (int)(texthight*2));
            _guiText1.TextColor = new float4(0, 0, 0, 1);
            textwidth = GUIText.GetTextWidth("Time: ", _guiFontCabin18);
            _guiText2 = new GUIText("Points: " + _points, _guiFontCabin18, width - (int)(textwidth * 3), (int)(texthight*2));
            _guiText2.TextColor = new float4(0, 0, 0, 1);

            //Text LevelUp
            textwidth = GUIText.GetTextWidth("Level Up!", _guiFontCabin100);
            _guiText7 = new GUIText("Level Up!", _guiFontCabin100, (width / 2) - (int)(textwidth/2), (height / 2));
            _guiText7.TextColor = new float4(1, 0, 0, 0.5f);

            #endregion

            #region Buttons
            // Button MainMenü: Starten
            textwidth = GUIText.GetTextWidth("Start", _guiFontWESTERN30);
            texthight = GUIText.GetTextHeight("Start", _guiFontWESTERN30);
            _guiText3 = new GUIText("Start", _guiFontWESTERN30, width / 2 - (int)(textwidth / 2), (int)(height / 1.5));
            _guiText3.TextColor = new float4(1, 1, 1, 1);
            _guiDiffs[(int)_buttons.btnStart] = new GUIButton(_guiText3.PosX - (int)(texthight / 2), _guiText3.PosY - (int)texthight, -2,
                (int)(textwidth * 1.5), (int)(texthight * 1.5));
            _guiImages[(int)_btnimages.btniStart] = new GUIImage("Assets/holz.png", _guiText3.PosX - (int)textwidth / 2,
                _guiText3.PosY - (int)(texthight * 1.5), -1, (int)textwidth * 2, (int)texthight * 2);

            // Button HighscoreMenü: Nochmal spielen
            textwidth = GUIText.GetTextWidth("Play again", _guiFontCabin18);
            _guiText5 = new GUIText("Play again", _guiFontCabin18, (width / 2) - (int)(textwidth * 1.5),
                (height / 2 + height / 3));
            _guiText5.TextColor = new float4(1, 1, 1, 1);
            texthight = GUIText.GetTextHeight("Play again", _guiFontCabin18);
            _guiDiffs[(int) _buttons.btnNochmal] = new GUIButton(_guiText5.PosX, _guiText5.PosY - (int) texthight, -2,
                (int) textwidth, (int) texthight);
            _guiImages[(int) _btnimages.btniNochmal] = new GUIImage("Assets/holz.png",
                _guiText5.PosX - (int) textwidth/2, _guiText5.PosY - (int) (texthight*1.5), -1, (int) textwidth*2,
                (int) texthight*2);

            // Button HighscoreMenü: Highscore
            textwidth = GUIText.GetTextWidth("Enter in Highscore", _guiFontCabin18);
            _guiText6 = new GUIText("Enter in Highscore", _guiFontCabin18, (width / 2) + (int)(textwidth / 5), (height / 2 + height / 3));
            _guiText6.TextColor = new float4(1, 1, 1, 1);
            texthight = GUIText.GetTextHeight("Enter in Highscore", _guiFontCabin18);
            _guiDiffs[(int) _buttons.btnHighscore] = new GUIButton(_guiText6.PosX, _guiText6.PosY - (int) texthight, -2, (int) textwidth, (int) texthight);
            _guiImages[(int) _btnimages.btniHighscore] = new GUIImage("Assets/holz.png",_guiText6.PosX - (int)textwidth / 8, _guiText6.PosY - (int)(texthight * 1.5), -1, (int)(textwidth * 1.2), (int) texthight*2);

            //Button Credits
            textwidth = GUIText.GetTextWidth("Credits", _guiFontCabin18);
            texthight = GUIText.GetTextWidth("Credits", _guiFontCabin18);
            _guiCredits = new GUIText("Credits", _guiFontCabin18, width - (int)(textwidth*1.5), (height / 2), new float4(1, 1, 1, 1));
            _guiDiffs[(int)_buttons.btnCredits] = new GUIButton(_guiCredits.PosX, _guiCredits.PosY - (int)texthight, -2,
               (int)textwidth, (int)texthight);
            #endregion
        }