protected virtual void DrawText(SpriteBatch spriteBatch) { if (Assetmanager.GetFont(font) == null) { return; } if (sprite is SlicedSprite) { if (root is IRenderDelegator) { ((IRenderDelegator)root).Delegate(new DelegatableFont() { FontName = font }, new FontSettings() { Color = hover ? foregroundHover : foreground, Position = textLocation, Text = text }); } } else { spriteBatch.DrawString(Assetmanager.GetFont(font), text, textLocation, hover ? foregroundHover : foreground); } }
public void Generate(int textureID, Point frame, float threshold) { threshold = MathHelper.Clamp(threshold, 0, 1); Texture2D texture = Assetmanager.GetTexture(textureID); Color[] data = new Color[tilesize * tilesize]; texture.GetData(0, new Rectangle(frame.X, frame.Y, tilesize, tilesize), data, 0, data.Length); float[,] translation = new float[tilesize, tilesize]; for (int y = 0; y < tilesize; y++) { for (int x = 0; x < tilesize; x++) { translation[x, y] = data[x + y * tilesize].A / 255f; } } bool[] collides = new bool[16]; for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { collides[x + y * 4] = translation.SubArray(x * quarterTileSize, quarterTileSize, y * quarterTileSize, quarterTileSize).Median() > threshold; } } for (int i = 0; i < collides.Length; i++) { if (collides[i]) { value = value | Parts[i]; } } Recalculate(); }
protected override void DrawText(SpriteBatch spriteBatch) { if (Assetmanager.GetFont(font) == null) { return; } spriteBatch.DrawString(Assetmanager.GetFont(font), text, new Vector2(bounds.Right + labelDistance, textLocation.Y), hover ? foregroundHover : foreground); }
protected virtual void MeasureString() { if (text == null) { text = string.Empty; } textDimension = Assetmanager.GetFont(font).MeasureString(text); textLocation = new Vector2(bounds.Center.X, bounds.Center.Y) - textDimension * 0.5f; }
private void DrawText(SpriteBatch spriteBatch) { if (Assetmanager.GetFont(font) == null) { return; } spriteBatch.DrawString(Assetmanager.GetFont(font), text, position, foreground); }
public void Draw(SpriteBatch spriteBatch) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Tile t = tiles[y * width + x]; spriteBatch.Draw(Assetmanager.GetTexture(t.Texture), new Rectangle(x * tileSize.X, y * tileSize.Y, tileSize.X, tileSize.Y), t.Frame, Color.White); } } }
public void Draw(SpriteBatch spriteBatch, IDelegateDrawSettings settings) { if (!(settings is FontSettings)) { return; } FontSettings f = (FontSettings)settings; spriteBatch.DrawString(Assetmanager.GetFont(font), f.Text, f.Position, f.Color); }
private void MeasureBounds() { SpriteFont font = Assetmanager.GetFont(this.font); if (font == null) { return; } Vector2 dimension = font.MeasureString(text); bounds.X = (int)position.X; bounds.Y = (int)position.Y; bounds.Width = (int)dimension.X; bounds.Height = (int)dimension.Y; }
public MainMenu(string name, StateMachine statemachine) : base(name, statemachine) { ui = new UIManager(); Localizer.CultureChanged += Localizer_CultureChanged; buttonSprite = new SlicedSprite("button_texture", "Textures/UI/Button"); buttonSprite.Top = 18; buttonSprite.Left = 18; buttonSprite.Right = 46; buttonSprite.Bottom = 46; Assetmanager.AquireFont("Fonts/default"); btnQuit = new Button(ui, ui); btnQuit.Sprite = buttonSprite; btnQuit.Font = "Fonts/default"; btnQuit.Position = new Vector2(Game1.Graphics.PreferredBackBufferWidth / 2 - 100, 400); btnQuit.Dimension = new Point(200, 100); btnQuit.Click += BtnQuit_Click; RefreshLocalization(); }
public override void Draw(SpriteBatch spriteBatch, Rectangle bounds, Color color) { int width = (bounds.Width < this.bounds.Width) ? this.bounds.Width : bounds.Width; int height = (bounds.Height < this.bounds.Height) ? this.bounds.Height : bounds.Height; int centerWidth = width - left - rightWidth; int centerHeight = height - top - bottomHeight; Texture2D tex = Assetmanager.GetTexture(texture); spriteBatch.Draw(tex, new Rectangle(bounds.Left, bounds.Top, left, top), source[(int)Handle.TopLeft], color); spriteBatch.Draw(tex, new Rectangle(bounds.Left + left, bounds.Top, centerWidth, top), source[(int)Handle.TopCenter], color); spriteBatch.Draw(tex, new Rectangle(bounds.Left + left + centerWidth, bounds.Top, rightWidth, top), source[(int)Handle.TopRight], color); spriteBatch.Draw(tex, new Rectangle(bounds.Left, bounds.Top + top, left, centerHeight), source[(int)Handle.MiddleLeft], color); spriteBatch.Draw(tex, new Rectangle(bounds.Left + left, bounds.Top + top, centerWidth, centerHeight), source[(int)Handle.Center], color); spriteBatch.Draw(tex, new Rectangle(bounds.Left + left + centerWidth, bounds.Top + top, rightWidth, centerHeight), source[(int)Handle.MiddleRight], color); spriteBatch.Draw(tex, new Rectangle(bounds.Left, bounds.Top + top + centerHeight, left, bottomHeight), source[(int)Handle.BottomLeft], color); spriteBatch.Draw(tex, new Rectangle(bounds.Left + left, bounds.Top + top + centerHeight, centerWidth, bottomHeight), source[(int)Handle.BottomCenter], color); spriteBatch.Draw(tex, new Rectangle(bounds.Left + left + centerWidth, bounds.Top + top + centerHeight, rightWidth, bottomHeight), source[(int)Handle.BottomRight], color); }
/// <summary> /// Draws the sprite in a given area and with a given frame /// </summary> /// <param name="spriteBatch">allows rendering the sprite to the screen</param> /// <param name="bounds">the rendered area</param> /// <param name="color">the color of the sprite</param> /// <param name="frame">the frame that should be rendered (defaults to 0)</param> public void Draw(SpriteBatch spriteBatch, Rectangle bounds, Color color, int frame = 0) { spriteBatch.Draw(Assetmanager.GetTexture(texture), bounds, frames[frame], color, rotation, origin, SpriteEffects.None, 0); }
/// <summary> /// Draws the sprite at a given location and with a given frame /// </summary> /// <param name="spriteBatch">allows rendering the sprite to the screen</param> /// <param name="position">the position of the sprite</param> /// <param name="color">the color of the sprite</param> /// <param name="frame">the frame that should be rendered (defaults to 0)</param> public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color, int frame = 0) { spriteBatch.Draw(Assetmanager.GetTexture(texture), position, frames[frame], Color.White, rotation, origin, 1, SpriteEffects.None, 0); }
/// <summary> /// Creates a new Sprite with the given values. /// </summary> /// <param name="name">The name of the sprite. Used to retrieve other data from memory.</param> /// <param name="texture">The name of the Texture2D that can be processed via the ContentManager.</param> /// <param name="frameSize">The size of one single frame within a spritesheet.</param> public Sprite(string name, string texture) { this.name = name; this.texture = Assetmanager.AquireTexture(texture); bounds = Assetmanager.GetTexture(this.texture).Bounds; }
/// <summary> /// Draws the sprite in a given area /// </summary> /// <param name="spriteBatch">allows rendering the sprite to the screen</param> /// <param name="bounds">the rendered area</param> /// <param name="color">the color of the sprite</param> public virtual void Draw(SpriteBatch spriteBatch, Rectangle bounds, Color color) { spriteBatch.Draw(Assetmanager.GetTexture(texture), bounds, null, color, rotation, origin, SpriteEffects.None, 0); }
/// <summary> /// Draws the sprite at a given location /// </summary> /// <param name="spriteBatch">allows rendering the sprite to the screen</param> /// <param name="position">the position of the sprite</param> /// <param name="color">the color of the sprite</param> public void Draw(SpriteBatch spriteBatch, Vector2 position, Color color) { spriteBatch.Draw(Assetmanager.GetTexture(texture), new Rectangle((int)position.X, (int)position.Y, bounds.Width, bounds.Height), null, color, rotation, origin, SpriteEffects.None, 0); }