Я пытаюсь сделать пользовательский, кликабельный шрифт для своей игры (для меню, например: PLAY -> идет в playcreen), я пытался использовать FreeType, но когда я создаю новый текст с он, он использует много памяти на Android. Можете ли вы предложить мне правильный способ создания интерактивных текстов из файлов .ttf? Я сделал таким образом:Пользовательский шрифт, который можно щелкнуть
У меня есть класс Box:
public class Box {
protected float x;
protected float y;
protected float width;
protected float height;
public boolean contains(float x, float y) {
return x > this.x - width/2 &&
x < this.x + width/2 &&
y > this.y - height/2 &&
y < this.y + height/2;
}
}
Тогда тексты класса и его расширяет поле, поэтому, когда я создать новый текст, я могу назвать .Contains (х, у), так что я могу сделать текст кликабельным:
public class Texts extends Box{
private String text;
private int size;
private float density;
private int dpSize;
private BitmapFont font;
private FreeTypeFontGenerator generator;
private FreeTypeFontParameter parameter;
public Texts(String text, int size, float x ,float y){
this.text = text;
this.size = size;
generator = new FreeTypeFontGenerator(Gdx.files.internal("myfont.ttf"));
parameter = new FreeTypeFontParameter();
parameter.size = size;
dpSize = parameter.size;
font = generator.generateFont(parameter);
generator.dispose();
this.x = x;
this.y = y;
this.width = font.getBounds(text).width;
this.height = font.getBounds(text).height;
}
public void render(SpriteBatch sb){
font.draw(sb, text, x - width/2 , y + height /2);
}
public void renderNoCenter(SpriteBatch sb){
font.draw(sb, text, x , y);
}
public float getWidth(){
return this.width;
}
public float getHeight(){
return this.height;
}
public void setText(String text){
this.text = text;
}
public void setXY(float x, float y){
this.x = x;
this.y = y;
}
public void update(float dt){
}
public int getDpSize(){
return dpSize;
}
public void dispose(){
font.dispose();
}
}
Но когда я создать новые тексты, как это, приложение потреблять + 12mb RAM/тексты:
Texts play = new Texts("PLAY", 200, 200, 80);
Texts options= new Texts("OPTIONS", 200, 200, 20);
Так что это моя проблема, спасибо за помощь!
Если вы просто хотите нарисовать какую-то рамку, вы можете использовать paint.extends textview для лучшей производительности. – NightCrawler
Мне не жаль. Я новичок в libgdx. – KERiii