static private void LoadBackgroundMusic(XmlNode widget, XmlNode page) { //return; //var music = new SFML.Audio.Music("Assets\\" + XmlUtilities.GetString (widget, "file")); //music.Play (); Logger.Info("UiFactory", "LoadBackgroundMusic", "loaded music: " + "Assets\\" + XmlUtilities.GetString(widget, "file")); var music = IoManager.LoadMusic(XmlUtilities.GetString(widget, "file")); if (music != null) { Logger.Info("UiFactory", "LoadBackgroundMusic", "loaded music"); try { var loops = widget.ChildNodes; for (var i = 0; i < loops.Count; i++) { var xloop = loops[i]; music.AddLoop( XmlUtilities.GetString(xloop, "name"), XmlUtilities.GetInt(xloop, "start"), XmlUtilities.GetInt(xloop, "end") ); } } catch (Exception ex) { Logger.Warning("UiFactory", "LoadBackgroundMusic", ex.ToString()); } } }
public Icon(string iconFileName, IntRect sprite) : base() { var tex = IoManager.LoadTexture(iconFileName); this.sprite = new Sprite(tex); this.sprite.TextureRect = sprite; this.size = new Vector2f(sprite.Width, sprite.Height); }
public LightLayer(int width, int height) : base(width, height) { this.AmbientLight = new Color(255, 255, 255); this.layerTexture = new RenderTexture((uint)this.Width, (uint)this.Height); this.layerSprite = new Sprite(this.layerTexture.Texture); this.lightTexture = IoManager.CreateShadedCircle(); this.Blend = BlendMode.Add; }
public Icon(string iconFileName, int x, int y, int w, int h) : base() { var tex = IoManager.LoadTexture(iconFileName); this.sprite = new Sprite(tex); this.sprite.TextureRect = new IntRect(x, y, w, h); this.size = new Vector2f(w, h); }
public void SetTilemask(int gridWidth, int gridHeight, int cellWidth, int cellHeight, string texture) { this.refCellSize.X = cellWidth; this.refCellSize.Y = cellHeight; this.cellSize.X = (int)(cellWidth * this.TileScale); this.cellSize.Y = (int)(cellHeight * this.TileScale); this.GridWidth = gridWidth; this.GridHeight = gridHeight; maskMap = new _Tile[gridHeight, gridWidth]; this.tileset = IoManager.LoadTexture(texture); this.AdjustLayer(); }
public Label(string text, int size = 16, string fontFile = null) { if (fontFile != null) { var font = IoManager.LoadFont(fontFile); this.text = new Text(text, font, (uint)size); } else if (IoManager.DefaultFontId != null) { this.text = new Text(text, IoManager.DefaultFont, (uint)size); } }
public static Inputs GetInputs() { IoManager.window.DispatchEvents(); //IoManager.window.WaitAndDispatchEvents (); IoManager.CheckKeyboard(); // KeyPressed is unrealiable, it inserts delays inputRes.Command = inputs.Command; inputRes.Unicode = inputs.Unicode; inputRes.MouseX = inputs.MouseX; inputRes.MouseY = inputs.MouseY; inputs.Command = InputCommands.NONE; inputs.Unicode = ""; return(inputRes); }
override public void SetBackground(string texture) { if (texture == "") { this.DrawBackground = false; this.bgSprite = new Sprite(); } else { this.bgTexture = IoManager.LoadTexture(texture, true); this.bgSprite = new Sprite(this.bgTexture); this.DrawBackground = true; this.AdjustLayer(); } }
override public void Update(Widget parent) { this.currRef += IoManager.DeltaTime; var icon = parent as Icon; if (this.currRef > this.endRef) { //var sprite = ((Icon)parent).sprite; this.currFrame = this.frames.Count - 1; icon.Sprite = this.frames [this.frames.Count - 1].rect; icon.Padding = this.frames [this.frames.Count - 1].offset; if (this.Looping == false) { this.hasEnded = true; return; } else { this.currRef -= this.endRef; } } try { if (this.frames [this.currFrame].millis < this.currRef) { this.currFrame += 1; var sprite = icon.Sprite; icon.Sprite = this.frames [this.currFrame].rect; icon.Padding = this.frames [this.currFrame].offset; if (this.frames[this.currFrame].sfx != "") { IoManager.PlaySound(this.frames[this.currFrame].sfx); } } } catch { this.hasEnded = true; } var p = parent as OutObject; if (p != null) { p.CurrentAnimationFrame = this.currFrame; } }
/// <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); }
/// <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); }
/// <summary> /// Append the sprite. /// </summary> /// <param name="sprite">Sprite.</param> /// <param name="duration">Duration of the sprite in milliseconds. /// Note that it is different from when instancing the Animation directly</param> public void AppendSprite(IntRect sprite, Vector2f soffset, int duration, string sfx = "") { var end = duration + this.endRef; if (sfx != "") { if (IoManager.LoadSound(sfx) == null) { // cannot load the sound, useless to set it sfx = ""; } } var kf = new KeyFrame() { millis = end, rect = sprite, offset = soffset, sfx = sfx }; //Console.WriteLine ("Appending sprite " + kf.rect.ToString() + " ending at " + end.ToString()); this.frames.Add(kf); this.endRef += duration; }
/// <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); } }
/// <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); }
static public WorldView LoadPage(string xmlfile, string pageId = "page_0") { IoManager.Clear(); XmlDocument xdoc = new XmlDocument(); xdoc.Load(xmlfile); WorldView res = null; try { XmlNode pageNode = xdoc.SelectSingleNode("//page[@id='" + pageId + "']"); var widgets = pageNode.ChildNodes; for (var i = 0; i < widgets.Count; i++) { var widget = widgets[i]; switch (widget.Name) { case "backgroundmusic": LoadBackgroundMusic(widget, pageNode); break; case "icon": IoManager.AddWidget(UiFactory.LoadIcon(widget, pageNode)); break; case "worldView": res = UiFactory.LoadWorldView(widget, pageNode); IoManager.AddWidget(res); break; default: break; } } } catch (Exception ex) { Logger.Error("UiFactory", "LoadPage", ex.ToString()); } return(res); }
public SfxSpawner(string sfx) { this.sfx = sfx; IoManager.LoadSound(sfx); }
/// <summary> /// Sets the background. /// </summary> /// <param name="texture">The file name of the texture.</param> virtual public void SetBackground(string texture) { this.bgTexture = IoManager.LoadTexture(texture, true); this.bgSprite = new Sprite(this.bgTexture); this.AdjustLayer(); }
public void SetLightTexture(string texture, int u, int v, int w, int h) { this.lightTexture = IoManager.LoadTexture(texture); //TODO }
static public void Clear() { IoManager.ClearWidgets(); IoManager.ClearAssets(); }
override public void Apply(Particle particle) { IoManager.PlaySound(this.sfx); }