GWT backend for libGDX enabling Java game development for web browsers through JavaScript compilation
npx @tessl/cli install tessl/maven-com-badlogicgames-gdx--gdx-backend-gwt@1.13.0The libGDX GWT Backend enables Java-based libGDX games to run in web browsers by transpiling Java code to JavaScript using Google Web Toolkit (GWT). It provides complete implementations of all core libGDX interfaces optimized for web browser environments, including WebGL graphics rendering, HTML5/Web Audio API audio playback, DOM-based input handling, and browser-compatible file system access.
com.badlogicgames.gdx:gdx-backend-gwt:1.13.1import com.badlogic.gdx.backends.gwt.GwtApplication;
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.backends.gwt.GwtApplication;
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
public class MyGameGwt extends GwtApplication {
@Override
public GwtApplicationConfiguration getConfig() {
GwtApplicationConfiguration config = new GwtApplicationConfiguration(800, 600);
config.disableAudio = false;
config.antialiasing = true;
return config;
}
@Override
public ApplicationListener createApplicationListener() {
return new MyGame();
}
}The GWT backend implements the libGDX Application interface through several key components:
GwtApplicationGwtGraphics and GL implementationsCore application initialization, configuration, and lifecycle management for web deployment.
public abstract class GwtApplication implements EntryPoint, Application {
public abstract GwtApplicationConfiguration getConfig();
public abstract ApplicationListener createApplicationListener();
}WebGL-based graphics implementation with OpenGL ES 2.0/3.0 compatibility and browser-specific optimizations.
public class GwtGraphics extends AbstractGraphics {
public int getWidth();
public int getHeight();
public GL20 getGL20();
public GL30 getGL30();
}Dual audio implementation supporting both HTML5 Audio and Web Audio API for optimal cross-browser compatibility.
public interface GwtAudio extends Audio {
Music newMusic(FileHandle file);
Sound newSound(FileHandle file);
}Comprehensive input support for mouse, keyboard, touch, and mobile device sensors with web-specific optimizations.
public interface GwtInput extends Input {
// Standard Input methods plus web-specific extensions
boolean isKeyPressed(int key);
int getX();
int getY();
boolean isTouched();
}Browser-compatible file system with asset preloading capabilities and local storage integration.
public class GwtFiles implements Files {
FileHandle internal(String path);
FileHandle local(String path);
boolean isExternalStorageAvailable();
}HTTP-based networking implementation using browser APIs for web-compatible network operations.
public class GwtNet implements Net {
void sendHttpRequest(HttpRequest httpRequest, HttpResponseListener httpResponseListener);
void openURI(String URI);
}Specialized asset preloading system for web deployment requirements with progress tracking and error handling.
public class Preloader {
void preload(String path, PreloaderCallback callback);
PreloaderState update();
}Advanced Web Audio API integration for improved audio performance and capabilities in modern browsers.
public class WebAudioAPIManager implements LifecycleListener {
boolean isSupported();
void createContext();
}Web-specific UI components for progress indicators, text input dialogs, and browser integration elements.
public interface ResizableWidget {
void resize(int width, int height);
}