Je parie sérieusement que j'ai fait quelque chose de stupide et que je n'arrive pas à le remarquer.Comment dessiner un BitmapFont dans LibGDX?
package com.me.mygdxgame;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class Locked implements ApplicationListener
{
private OrthographicCamera camera;
private SpriteBatch batch;
private Texture texture;
private Sprite sprite;
private BitmapFont font;
private CharSequence str = "Hello World!";
private float width;
private float height;
@Override
public void create()
{
width = Gdx.graphics.getWidth();
height = Gdx.graphics.getHeight();
camera = new OrthographicCamera(1, height/width);
batch = new SpriteBatch();
texture = new Texture(Gdx.files.internal("data/libgdx.png"));
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
TextureRegion region = new TextureRegion(texture, 0, 0, 512, 275);
sprite = new Sprite(region);
sprite.setSize(0.9f, 0.9f * sprite.getHeight()/sprite.getWidth());
sprite.setOrigin(sprite.getWidth()/2, sprite.getHeight()/2);
sprite.setPosition(-sprite.getWidth()/2, -sprite.getHeight()/2);
font = new BitmapFont(Gdx.files.internal("data/digib.fnt"),
Gdx.files.internal("data/digib.png"), false);
}
@Override
public void dispose()
{
batch.dispose();
texture.dispose();
}
@Override
public void render()
{
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(camera.combined);
batch.begin();
font.setColor(0.0f, 0.0f, 0.0f, 1.0f);
//sprite.draw(batch);
font.draw(batch, str, width*0.5f, height*0.5f);
batch.end();
}
@Override
public void resize(int width, int height)
{
}
@Override
public void pause()
{
}
@Override
public void resume()
{
}
}
Le projet a été généré avec l'outil de modèle qu'ils fournissent GDX-setup-ui.jar Comme vous pouvez le voir dans le code, je ne l'ai pas pris la peine de se débarrasser des codes par défaut (Juste un peu codes de dessin simples pour afficher le logo LibGDX).
Ainsi, le projet généré proprement, je suivais ce guide ici http://code.google.com/p/libgdx-users/wiki/addingText2D
et d'arriver enfin avec le code fourni ci-dessus.
Le problème est, pourquoi le texte! @ # $ Ing ne s'affichera-t-il pas? J'ai changé la position tellement de fois et toujours pas de chance: \
Ai-je manqué quelque chose?
FYI: Les polices sont très bien, je les ai déposées dans un autre jeu et cela fonctionne.
Je ne peux pas utiliser generator.generateFont (int); parce que ça n'existe pas. Vous pouvez seulement passer un FreeTypeFontParameter – Eames
Il y a un tutoriel sur l'utilisation de FreeTypeFontGenerator ici> https://libgdx.info/basic-label/ – Julien