Beispiel #1
0
        /// <summary>
        /// Loads a texture from file.
        /// </summary>
        /// <returns>The texture.</returns>
        public static Texture LoadTexture(string fileName, bool smooth = false)
        {
            Texture res;

            if (IoManager.textures.TryGetValue(fileName, out res) == false)
            {
                try {
                    var path = IoManager.GetAssetPath(fileName);
                    res        = new Texture(path);
                    res.Smooth = smooth;
                    IoManager.textures.Add(fileName, res);
                }
                catch (Exception ex) {
                    // TODO log exception
                    Logger.Warning("IoManager", "LoadTexture", "Unable to load " + fileName + ": " + ex.ToString());
                    res = null;
                }
            }
            return(res);
        }
Beispiel #2
0
        /// <summary>
        /// Loads a sound effect from file.
        /// </summary>
        /// <returns>The sfx.</returns>
        public static Sound LoadSound(string fileName)
        {
            Sound res;

            if (IoManager.sounds.TryGetValue(fileName, out res) == false)
            {
                try {
                    var path = IoManager.GetAssetPath(fileName);
                    res        = new Sound(new SoundBuffer(path));
                    res.Volume = 5;
                    IoManager.sounds.Add(fileName, res);
                }
                catch (Exception ex) {
                    // TODO log exception
                    Console.Write(ex.ToString());
                    res = null;
                }
            }
            return(res);
        }
Beispiel #3
0
 /// <summary>
 /// Loads the background music. The music is streamed from file.
 /// </summary>
 /// <param name="fileName">File name.</param>
 public static BackgroundMusic LoadMusic(string fileName)
 {
     try {
         if (IoManager.music != null && IoManager.music.FileName == fileName)
         {
             Logger.Info("IoManager", "LoadMusic", "Already loaded " + fileName);
         }
         else
         {
             var path = IoManager.GetAssetPath(fileName);
             var mus  = new Sound();
             mus.SoundBuffer = new SoundBuffer(path);
             mus.Volume      = 15;
             IoManager.music = new BackgroundMusic(mus, fileName);
             Logger.Info("IoManager", "LoadMusic", "loaded music " + fileName);
         }
         return(IoManager.music);
     } catch (Exception ex) {
         Logger.Warning("IoManager", "LoadMusic", "Unable to load " + fileName + ": " + ex.ToString());
         return(null);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Loads a font from file.
        /// </summary>
        /// <returns>The font.</returns>
        /// <param name="fileName">Font file.</param>
        /// <param name="size">The font Size, it is in fact used to set the smoothin for a specific mipmap.</param>
        public static Font LoadFont(string fileName, int size = 24)
        {
            Font res;

            try {
                if (IoManager.fonts.TryGetValue(fileName, out res) == false)
                {
                    var path = IoManager.GetAssetPath(fileName);
                    res = new Font(path);
                    IoManager.fonts.Add(fileName, res);
                    if (IoManager.fonts.Count == 1)
                    {
                        IoManager.DefaultFontId = fileName;
                    }
                }
                res.GetTexture((uint)size).Smooth = false;
            } catch (Exception ex) {
                Logger.Warning("IoManager", "LoadFont", "Unable to load " + fileName + ": " + ex.ToString());
                res = null;
            }
            return(res);
        }