Hallo geehrte Community
,
großer Aufwand - kleines Problem - denke ich. Also ich habe folgendes Problem :
Ich möchte per Unicode font einen Text auf meinen Bildschirm zeichnen, dies funktioniert wunderbar - bis ich dann in verschiedenen Größen zeichnen möchte - dann nämlich wird nur eine der beiden Fontsizes auf alle Fonts der Klasse angewandt, ziemlich nervig hier sind sowohl Fontklasse als auch die Aufrufende Klasse, btw ich bin quasi ein Programmier - Neuling, daher bin ich immer offen für Verbesserungen
FONTMANAGER :
INTRO
EDIT die Rotation dient dazu die Schrift auf die richtige Position zu bringen
großer Aufwand - kleines Problem - denke ich. Also ich habe folgendes Problem :
Ich möchte per Unicode font einen Text auf meinen Bildschirm zeichnen, dies funktioniert wunderbar - bis ich dann in verschiedenen Größen zeichnen möchte - dann nämlich wird nur eine der beiden Fontsizes auf alle Fonts der Klasse angewandt, ziemlich nervig hier sind sowohl Fontklasse als auch die Aufrufende Klasse, btw ich bin quasi ein Programmier - Neuling, daher bin ich immer offen für Verbesserungen
FONTMANAGER :
Java:
import java.awt.Color;
import org.newdawn.slick.*;
import org.newdawn.slick.font.effects.ColorEffect;
public class FontManager {
private String fontName = "";
private int fontSize = 0;
private Color fontColor;
private static UnicodeFont font;
public String getFontName() {
return fontName;
}
public void setFontName(String fontName) {
this.fontName = fontName;
}
public int getFontSize() {
return fontSize;
}
public void setFontSize(int fontSize) {
this.fontSize = fontSize;
}
public Color getFontColor() {
return fontColor;
}
public void setFontColor(Color fontColor) {
this.fontColor = fontColor;
}
public FontManager() {
fontName = "ActionMan.ttf";
fontSize = 40;
fontColor = Color.white;
initFont();
}
public FontManager(String fontName, int fontSize, Color fontColor) {
this.fontColor = fontColor;
this.fontName = fontName;
this.fontSize = fontSize;
initFont();
}
public void write(int x, int y, String text) {
font.drawString(x, y, text);
}
private void initFont() {
java.awt.Font awtFont = new java.awt.Font(fontName, java.awt.Font.BOLD,
fontSize);
try {
font = new UnicodeFont("res/" + fontName, fontSize, false, false);
} catch (SlickException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
font.getEffects().add(new ColorEffect(fontColor));
font.addAsciiGlyphs();
try {
font.loadGlyphs();
} catch (SlickException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
INTRO
Java:
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glRotatef;
import static org.lwjgl.opengl.GL11.glTranslatef;
import java.awt.Color;
import managerTools.Properties;
import org.lwjgl.input.Keyboard;
import de.Jannik.Tools.FontManager;
public class Intro extends Gamestate {
public static Intro instance;
public static boolean end = false;
FontManager font = new FontManager();
FontManager kleineSchrift = new FontManager("ActionMan.ttf", 20,
Color.white);
public static Intro getInstance() {
if (instance == null) {
instance = new Intro();
end = false;
}
return instance;
}
public static void deleteInstance() {
instance = null;
}
@Override
public boolean end() {
// TODO Auto-generated method stub
return end;
}
@Override
public void update(int delta) {
glPushMatrix();
glTranslatef(30, 50, 0);
glRotatef(180, 1, 0, 0);
kleineSchrift.write(100, -Properties.HEIGHT / 7,
"special Thanks to ***** *****");
font.write(100, -Properties.HEIGHT / 2, "INTRO");
glPopMatrix();
while (Keyboard.next()) {
if (Keyboard.getEventKey() == Keyboard.KEY_RETURN
&& Keyboard.getEventKeyState()) {
end = true;
}
}
}
}
EDIT die Rotation dient dazu die Schrift auf die richtige Position zu bringen
Zuletzt bearbeitet: