Browse Source

update

main
Justin Senn 2 years ago
parent
commit
30ee3005f7
  1. 27
      src/main/java/Snake/TextView.java

27
src/main/java/Snake/TextView.java

@ -27,11 +27,38 @@ public class TextView implements Drawable
this.anchor = AnchorType.Center;
}
public void setText(String newText)
{
text = newText;
}
public void setVisibility(boolean visibility)
{
visible = visibility;
}
public void setAnchor(AnchorType newAnchor)
{
anchor = newAnchor;
}
@Override
public void draw(Graphics g)
{
if(visible)
{
FontMetrics fontMetrics = g.getFontMetrics();
int x = position.x;
int y = position.y + fontMetrics.getHeight();
if (anchor == AnchorType.Center)
x -= fontMetrics.stringWidth(text);
else if (anchor == AnchorType.Right)
x -= fontMetrics.stringWidth(text);
g.setColor(Color.WHITE);
g.drawString(text, x, y);
}
}
}
Loading…
Cancel
Save