public override GameFont LoadFont(string filename) { //Get font size from filename, format should be name_size.xnb or whatever var name = GameContentManager.RemoveExtension(filename) .Replace(Path.Combine("resources", "fonts"), "") .TrimStart(Path.DirectorySeparatorChar); var parts = name.Split('_'); if (parts.Length >= 1) { if (int.TryParse(parts[parts.Length - 1], out var size)) { name = ""; for (var i = 0; i <= parts.Length - 2; i++) { name += parts[i]; if (i + 1 < parts.Length - 2) { name += "_"; } } return(new MonoFont(name, filename, size, mContentManager)); } } return(null); }
public MonoFont(string fontName, string fileName, int fontSize, ContentManager contentManager) : base( fontName, fontSize ) { try { fileName = GameContentManager.RemoveExtension(fileName); mFont = contentManager.Load <SpriteFont>(fileName); } catch (Exception ex) { Log.Trace(ex); } }
//Music public static void PlayMusic(string filename, float fadeout = 0f, float fadein = 0f, bool loop = false) { if (string.IsNullOrWhiteSpace(filename)) { //Entered a map with no music selected, fade out any music that's already playing. StopMusic(3f); return; } ClearQueue(); filename = GameContentManager.RemoveExtension(filename); if (sMyMusic != null) { if (fadeout < 0.01 || sMyMusic.State == GameAudioInstance.AudioInstanceState.Stopped || sMyMusic.State == GameAudioInstance.AudioInstanceState.Paused || sMyMusic.GetVolume() == 0) { StopMusic(); StartMusic(filename, fadein, loop); } else { //Start fadeout if (!string.Equals(sCurrentSong, filename, StringComparison.CurrentCultureIgnoreCase) || sFadingOut) { sFadeRate = sMyMusic.GetVolume() / fadeout; sFadeTimer = Globals.System.GetTimeMs() + (long)(sFadeRate / 1000); sFadingOut = true; sQueuedMusic = filename; sQueuedFade = fadein; sQueuedLoop = loop; } } } else { StartMusic(filename, fadein, loop); } }
public Sound(string filename, bool loop) { if (String.IsNullOrEmpty(filename)) { return; } mFilename = GameContentManager.RemoveExtension(filename).ToLower(); mLoop = loop; var sound = Globals.ContentManager.GetSound(mFilename); if (sound != null) { mSound = sound.CreateInstance(); mSound.IsLooping = mLoop; mSound.SetVolume(Globals.Database.SoundVolume); mSound.Play(); Loaded = true; } }
public MonoShader(string shaderName, ContentManager content) : base(shaderName) { mShader = content.Load <Effect>(GameContentManager.RemoveExtension(shaderName)); }