So, I'm trying to do a basic counter on libgdx, it's basically a float that adds the delta time, but even if the log shows the code works, libgdx don't render it.
Here it's the code:
public class Clicker_Counter {
BitmapFont font;
float counter = 0;
public Clicker_Counter()
{
font = new BitmapFont();
font.setColor(Color.RED);
counter = 0;
}
public void Increase()
{
counter += 1 * Gdx.graphics.getDeltaTime();
Gdx.app.log("MYDEBUG", Float.toString(counter));
}
public void Draw(SpriteBatch sprite)
{
font.draw(sprite, Float.toString(counter), 0, 0);
}
public void Dispose()
{
font.dispose();
}
public void Reset()
{
counter = 0;
}
}
Here is the update function of the main update loop:
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
counter.Increase();
if (Gdx.input.isTouched())
{
counter.Reset();
}
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
counter.Draw(batch);
batch.end();
}
您可能正在使用OrthographicCamera,请尝试使用与DesktopLauncher相同的视口宽度和高度实例化它,例如:
camera = new OrthographicCamera(200, 400);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.