Package game.scenes

Source Code of game.scenes.DebugOverlay

package game.scenes;

import engine.classes.Colour;
import engine.geometry.Rectangle;
import engine.geometry.Vector;
import engine.hierarchy.DefaultScene;
import engine.interfaces.Clock;
import engine.interfaces.Font;
import engine.interfaces.Keyboard;
import engine.interfaces.Keyboard.Key;
import engine.interfaces.Mouse;
import engine.interfaces.RenderTarget;

public final class DebugOverlay extends DefaultScene {
    private int currentFps;
    private int targetFps;
    private Colour textColour;
    private Vector position;
    private Rectangle rectangle;
    private Colour rectColour;
    private Font font;

    @Override
    public void onAdd() {
        textColour = new Colour(255, 255, 255);
        position = new Vector(2, 12);
        font = getStage().getLibrary().findFont("Debug");
        rectangle = new Rectangle(0, 0, 640, 16);
        rectColour = new Colour(0, 0, 0, 128);
    }

    @Override
    public void onBeforeMove(final Keyboard keyboard, final Mouse mouse, final Clock clock) {
        currentFps = clock.getCurrentFps();
        targetFps = clock.getTargetFps();

        if (getStage().getSceneAbove(this) == null || getStage().getSceneAbove(this).getClass() != ConsoleScene.class) {
            if (keyboard.wasReleased(Key.VK_BACK_QUOTE)) {
                // Open console
                getStage().insertSceneAbove(new ConsoleScene(), this);
            }
        }
    }

    @Override
    public void onDraw(final RenderTarget target) {
        target.transformPush();
        target.transformIdentity();
        target.fillRectangle(rectangle, rectColour);
        target.drawString(currentFps + "/" + targetFps, font, textColour, position);
        target.transformPop();
    }
}
TOP

Related Classes of game.scenes.DebugOverlay

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.