public TextButton(Font2D font, string text) { m_Font = font; m_Rectangle = new Rectangle(); Text = text; m_OriginalColor = font.Color; HoverColor = Color.Red; ShadowColor = new Color(0, 0, 0, 127); }
public static void Add(string fontLabel, Font2D font) { if (fontLabel != null && !fonts.ContainsKey(fontLabel)) { fonts.Add(fontLabel, font); GameConsole.Add("FontManager", "New font added '" + fontLabel + "'"); } else { GameConsole.Add("FontManager", "Font '" + fontLabel + "' already exists in the dictionnary"); } }
public CandyRushHero() { m_CurrentHealth = 100; m_MaxHealth = 100; m_CandyCorn = 100; m_PrevPositions = new Vector2[10]; base.Sprite = new Sprite(); base.Sprite.Texture = ContentLoader.Instance.Load<Texture2D>(ContentContainer.Game, @"Content\\h_idle"); base.Sprite.Rotation = (float)Math.PI; base.Sprite.CenterImage(); m_HudSprites = new Sprite(); m_HudSprites.Texture = ContentLoader.Instance.Load<Texture2D>(ContentContainer.UI, @"Content\\Hud"); m_HudSprites.Position = ExperiaHelper.Instance.PositionByVirtualResolution(new Vector2(0.0f, 60.0f)); m_HudText = new Font2D(@"Content\\Chiller"); m_PistolSmoke = new Sprite(); m_PistolSmoke.Texture = ContentLoader.Instance.Load<Texture2D>(ContentContainer.Game, @"Content\\Firearm Smoke\\Pistol Smoke"); m_ShotgunSmoke = new Sprite(); m_ShotgunSmoke.Texture = ContentLoader.Instance.Load<Texture2D>(ContentContainer.Game, @"Content\\Firearm Smoke\\Shotgun Smoke"); }
public static void Draw(Font2D font, string text, Vector2 position, Color4 color, float size = 1) { if (font == null) { throw new Exception("Font doesn't exist."); } if (text == null) { return; } //bool newLine = true; Vector2 overallPosition = Vector2.Zero; Rectangle source; Rectangle destination; Vector2 charPosition; int lastChar = 0; for (int i = 0; i < text.Length; i++) { // Work out current character char character = text[i]; switch (character) { case '\t': { i++; // skip # float r = Byte.Parse(text[i++].ToString(), System.Globalization.NumberStyles.AllowHexSpecifier); float g = Byte.Parse(text[i++].ToString(), System.Globalization.NumberStyles.AllowHexSpecifier); float b = Byte.Parse(text[i].ToString(), System.Globalization.NumberStyles.AllowHexSpecifier); color = new Color4(r / 15, g / 15, b / 15, 1); break; } case '\n': { //newLine = true; overallPosition.X = 0.0f; overallPosition.Y += (font.LineSpacing) * size; break; } default: { int realIndex = font.GetCharacterIndex(character); int characterIndex = realIndex; if (characterIndex == -1) { characterIndex = font.GetCharacterIndex('?'); } //float charKerning = font.kerning.Find(letter => letter.X==lastChar && letter.Y==characterIndex).Z; charPosition = overallPosition + position; source = font.glyphData[characterIndex]; Rectangle cropData = font.croppingData[characterIndex]; destination = new Rectangle(); destination.Left = (int)Math.Ceiling(charPosition.X + cropData.X * size); destination.Top = (int)Math.Ceiling(charPosition.Y + cropData.Y * size); destination.Right = (int)Math.Ceiling(source.Width * size); destination.Bottom = (int)Math.Ceiling(source.Height * size); QuadRenderer.Draw(font.textureValue, destination, source, color); overallPosition.X += cropData.Width * size; //newLine = false; lastChar = characterIndex; break; } } } }