1. Home
  2. /
  3. Libgdx
  4. /
  5. FPS Display

FPS Display - Libgdx Typing CST Test

Loading…

FPS Display — Libgdx Code

Shows frames per second on screen.

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class FpsDemo extends ApplicationAdapter {
	private SpriteBatch batch;
	private BitmapFont font;

	@Override
	public void create() {
		batch = new SpriteBatch();
		font = new BitmapFont();
	}

	@Override
	public void render() {
		int fps = Gdx.graphics.getFramesPerSecond();
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		batch.begin();
		font.draw(batch, "FPS: " + fps, 30, 150);
		batch.end();
	}
}

Libgdx Language Guide

LibGDX is a powerful, open-source Java game framework for building high-performance 2D and 3D games that run on desktop, Android, iOS, and web through a single shared codebase.

Primary Use Cases

  • ▸Cross-platform 2D and 3D games
  • ▸Android-first game development
  • ▸Custom in-house engines
  • ▸Scientific/physics simulations
  • ▸Desktop games with OpenGL rendering

Notable Features

  • ▸Single Java/Kotlin codebase -> multiple platforms
  • ▸Scene2D UI and Scene2D stage/actors
  • ▸Built-in physics via Box2D
  • ▸OpenGL-based rendering pipeline
  • ▸Powerful math + linear algebra library

Origin & Creator

LibGDX was created by Mario Zechner and maintained by a global open-source community focused on flexible, high-performance Java game development.

Industrial Note

LibGDX thrives in Android game development, indie 2D/3D engines, simulation-heavy games, and education-especially for teams needing full control without being locked into heavy engines.

Quick Explain

  • ▸LibGDX uses Java and offers cross-platform deployment through a shared core module.
  • ▸It includes robust APIs for graphics, audio, input, physics, math, and file management.
  • ▸Rendering is powered by OpenGL (desktop/mobile) and WebGL via GWT for browser builds.
  • ▸Developers have full low-level control while benefiting from higher-level utilities like Scene2D.
  • ▸LibGDX is ideal for multiplatform 2D/3D games, mobile games, desktop titles, and custom engine development.

Core Features

  • ▸Application lifecycle (create, render, dispose)
  • ▸Texture, sprite, camera utilities
  • ▸Input handling for all platforms
  • ▸File I/O with virtual filesystem
  • ▸Audio engine with music/sound support

Learning Path

  • ▸Week 1: Application lifecycle, SpriteBatch
  • ▸Week 2: Scene2D basics
  • ▸Week 3: Box2D physics + collisions
  • ▸Week 4: Shaders + cameras
  • ▸Week 5: AssetManager, optimization, deployment

Practical Examples

  • ▸2D platformer with Box2D
  • ▸Top-down shooter
  • ▸Turn-based tactics game
  • ▸3D first-person prototype
  • ▸Android casual game

Comparisons

  • ▸LibGDX vs Unity: LibGDX is code-first; Unity is editor-first.
  • ▸LibGDX vs Godot: LibGDX gives lower-level control; Godot gives easier UX.
  • ▸LibGDX vs Phaser: LibGDX for native/mobile; Phaser for browser-based games.
  • ▸LibGDX vs Cocos2d-x: LibGDX easier for Java developers.
  • ▸LibGDX excels in Android + desktop 2D/3D with high control.

Strengths

  • ▸True cross-platform with 1 codebase
  • ▸Extremely performant
  • ▸Gives full control over rendering + logic
  • ▸Huge ecosystem of extensions (AI, Box2D, Ashley ECS)
  • ▸Amazing for Android & desktop games

Limitations

  • ▸No built-in visual editor
  • ▸Larger learning curve (engine-code heavy)
  • ▸3D features not as advanced as Unreal/Unity
  • ▸GWT web export can require tweaking
  • ▸Asset management fully manual unless using community tools

When NOT to Use

  • ▸Pure HTML5 browser games
  • ▸AAA 3D productions
  • ▸Teams needing visual editor workflows
  • ▸Zero-code development
  • ▸Projects requiring heavy asset pipelines

Cheat Sheet

  • ▸`create()`: initialize
  • ▸`render()`: game loop
  • ▸`SpriteBatch.begin()/end()`
  • ▸Use AssetManager for async loading
  • ▸Stage + Actors for UI

FAQ

  • ▸Is LibGDX free?
  • ▸Yes, fully open-source under Apache 2.0.
  • ▸Does it support 3D?
  • ▸Yes, but not as advanced as Unreal/Unity.
  • ▸Can it export to iOS?
  • ▸Yes, using RoboVM/MobiDevelop.
  • ▸Is Java required?
  • ▸Yes, though Kotlin works extremely well.
  • ▸Is it beginner-friendly?
  • ▸Yes, for programmers; not ideal for no-code users.

30-Day Skill Plan

  • ▸Rewrite small games in Scene2D
  • ▸Learn GLSL shaders
  • ▸Use Box2D extensively
  • ▸Build custom rendering pipelines
  • ▸Create and use TextureAtlases

Final Summary

  • ▸LibGDX is a versatile, high-performance Java game framework for 2D and 3D.
  • ▸It provides deep control over rendering, physics, and input across all platforms.
  • ▸Ideal for Android, desktop, indie games, and technical teams.
  • ▸No editors - pure code flexibility.
  • ▸Perfect for developers who want power, portability, and full engine control.

Project Structure

  • ▸core/ (shared game logic)
  • ▸desktop/ (launcher)
  • ▸android/ (Android project)
  • ▸ios/ (RoboVM/MobiDevelop)
  • ▸html/ (GWT Web build)

Monetization

  • ▸Android in-app purchases
  • ▸Rewarded ads via platform SDKs
  • ▸Steam integration for desktop
  • ▸Premium paid apps
  • ▸Licensing to publishers

Productivity Tips

  • ▸Use Scene2D for UI instead of custom rendering
  • ▸Reuse SpriteBatch + camera
  • ▸Use TexturePacker atlases
  • ▸Write debug overlays early
  • ▸Profile memory frequently

Basic Concepts

  • ▸ApplicationListener controls app lifecycle
  • ▸Batch and SpriteBatch render images
  • ▸OrthographicCamera manages viewport
  • ▸Scene2D uses Stage + Actors
  • ▸AssetManager loads resources safely

Official Docs

  • ▸https://libgdx.com/
  • ▸https://github.com/libgdx/libgdx/wiki
  • ▸https://github.com/libgdx/libgdx

More Libgdx Typing Exercises

LibGDX Simple Counter GameLibGDX Sprite MovementLibGDX Clear Screen ColorLibGDX Animation ExampleLibGDX Keyboard Text InputLibGDX Timer EventLibGDX Mouse TrackerLibGDX Sound PlaybackLibGDX Touch ExampleLibGDX Random Walker

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher