scenes.Debug.java Source code

Java tutorial

Introduction

Here is the source code for scenes.Debug.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package scenes;

import com.badlogic.gdx.Application;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import networking.GameClient;

/**
 * 
 * @author <a href="mailto:kevin.vanderburg@student.fontys.nl">Kevin van der Burg</a>
 */
public class Debug extends ApplicationAdapter {
    private SpriteBatch batch;
    private BitmapFont font30;
    private GlyphLayout layout;

    public Debug() {
        create();
        Gdx.app.setLogLevel(Application.LOG_DEBUG);
    }

    @Override
    public void create() {
        layout = new GlyphLayout();
        batch = new SpriteBatch();

        //initialize fonts
        FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/MunroSmall.ttf"));
        FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
        parameter.size = 30;
        font30 = generator.generateFont(parameter);
        font30.setColor(Color.BLACK);
    }

    @Override
    public void render() {
        batch.begin();

        //Write Circle
        layout.setText(font30, "" + Gdx.graphics.getFramesPerSecond());
        int x = (int) (50);
        int y = (int) (Gdx.graphics.getHeight() - 50);
        font30.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), x, y);

        //Write Circle
        layout.setText(font30, "" + GameClient.ms);
        y = (int) (Gdx.graphics.getHeight() - 100);
        font30.draw(batch, "Ping: " + GameClient.ms, x, y);

        batch.end();

    }

}