Renderování textu, jumpscary, win a lose screen
This commit is contained in:
parent
9bfe63a166
commit
e6128dc9f5
21 changed files with 360 additions and 84 deletions
54
FNAF_Clone/GUI/TextUIElement.cs
Normal file
54
FNAF_Clone/GUI/TextUIElement.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MonoGameLibrary.Graphics;
|
||||
|
||||
namespace FNAF_Clone.GUI;
|
||||
|
||||
public class TextUIElement : UIElement {
|
||||
public SpriteFont Font { get; set; }
|
||||
public string Text{ get; set; } = "";
|
||||
public Color Color{ get; set; } = Color.White;
|
||||
private Vector2 origin;
|
||||
|
||||
public TextUIElement(Point corner1, SpriteFont font, Alignment alignment = Alignment.LEFT) : base(corner1, corner1) {
|
||||
Font = font;
|
||||
Align(alignment);
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch spriteBatch) {
|
||||
base.Draw(spriteBatch);
|
||||
align();
|
||||
spriteBatch.DrawString(Font, Text, screenSpaceBounds.Item1.ToVector2(), Color, 0, origin, ScaleMultiplier, SpriteEffects.None, 0);
|
||||
}
|
||||
|
||||
public void Align(Alignment alignment) {
|
||||
switch (alignment){
|
||||
case Alignment.LEFT:
|
||||
AlignLeft();
|
||||
break;
|
||||
case Alignment.RIGHT:
|
||||
AlignRight();
|
||||
break;
|
||||
case Alignment.CENTER:
|
||||
AlignCenter();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void AlignLeft() {
|
||||
align = () => origin = Vector2.Zero;
|
||||
}
|
||||
private void AlignRight() {
|
||||
align = () => origin = Font.MeasureString(Text);
|
||||
}
|
||||
private void AlignCenter() {
|
||||
align = () => origin = Font.MeasureString(Text) / 2;
|
||||
}
|
||||
|
||||
private Action align;
|
||||
|
||||
public enum Alignment {
|
||||
LEFT, RIGHT, CENTER
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue