0
# libGDX GWT Backend
1
2
The 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.
3
4
## Package Information
5
6
- **Package Name**: gdx-backend-gwt
7
- **Package Type**: maven
8
- **Language**: Java
9
- **Installation**: Add dependency `com.badlogicgames.gdx:gdx-backend-gwt:1.13.1`
10
11
## Core Imports
12
13
```java
14
import com.badlogic.gdx.backends.gwt.GwtApplication;
15
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
16
```
17
18
## Basic Usage
19
20
```java
21
import com.badlogic.gdx.ApplicationListener;
22
import com.badlogic.gdx.backends.gwt.GwtApplication;
23
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
24
25
public class MyGameGwt extends GwtApplication {
26
@Override
27
public GwtApplicationConfiguration getConfig() {
28
GwtApplicationConfiguration config = new GwtApplicationConfiguration(800, 600);
29
config.disableAudio = false;
30
config.antialiasing = true;
31
return config;
32
}
33
34
@Override
35
public ApplicationListener createApplicationListener() {
36
return new MyGame();
37
}
38
}
39
```
40
41
## Architecture
42
43
The GWT backend implements the libGDX Application interface through several key components:
44
45
- **Application Core**: Entry point and lifecycle management through `GwtApplication`
46
- **Graphics Subsystem**: WebGL-based rendering through `GwtGraphics` and GL implementations
47
- **Audio Subsystem**: HTML5 Audio and Web Audio API integration
48
- **Input Handling**: DOM event-based mouse, keyboard, and touch input
49
- **File System**: Browser storage and asset management with preloading
50
- **Networking**: HTTP-only network operations through browser APIs
51
52
## Capabilities
53
54
### [Application Setup](./application.md)
55
Core application initialization, configuration, and lifecycle management for web deployment.
56
57
```java
58
public abstract class GwtApplication implements EntryPoint, Application {
59
public abstract GwtApplicationConfiguration getConfig();
60
public abstract ApplicationListener createApplicationListener();
61
}
62
```
63
64
### [Graphics and Rendering](./graphics.md)
65
WebGL-based graphics implementation with OpenGL ES 2.0/3.0 compatibility and browser-specific optimizations.
66
67
```java
68
public class GwtGraphics extends AbstractGraphics {
69
public int getWidth();
70
public int getHeight();
71
public GL20 getGL20();
72
public GL30 getGL30();
73
}
74
```
75
76
### [Audio System](./audio.md)
77
Dual audio implementation supporting both HTML5 Audio and Web Audio API for optimal cross-browser compatibility.
78
79
```java
80
public interface GwtAudio extends Audio {
81
Music newMusic(FileHandle file);
82
Sound newSound(FileHandle file);
83
}
84
```
85
86
### [Input Handling](./input.md)
87
Comprehensive input support for mouse, keyboard, touch, and mobile device sensors with web-specific optimizations.
88
89
```java
90
public interface GwtInput extends Input {
91
// Standard Input methods plus web-specific extensions
92
boolean isKeyPressed(int key);
93
int getX();
94
int getY();
95
boolean isTouched();
96
}
97
```
98
99
### [File System and Assets](./files.md)
100
Browser-compatible file system with asset preloading capabilities and local storage integration.
101
102
```java
103
public class GwtFiles implements Files {
104
FileHandle internal(String path);
105
FileHandle local(String path);
106
boolean isExternalStorageAvailable();
107
}
108
```
109
110
### [Networking](./networking.md)
111
HTTP-based networking implementation using browser APIs for web-compatible network operations.
112
113
```java
114
public class GwtNet implements Net {
115
void sendHttpRequest(HttpRequest httpRequest, HttpResponseListener httpResponseListener);
116
void openURI(String URI);
117
}
118
```
119
120
### [Asset Preloading](./preloader.md)
121
Specialized asset preloading system for web deployment requirements with progress tracking and error handling.
122
123
```java
124
public class Preloader {
125
void preload(String path, PreloaderCallback callback);
126
PreloaderState update();
127
}
128
```
129
130
### [Web Audio API](./webaudio.md)
131
Advanced Web Audio API integration for improved audio performance and capabilities in modern browsers.
132
133
```java
134
public class WebAudioAPIManager implements LifecycleListener {
135
boolean isSupported();
136
void createContext();
137
}
138
```
139
140
### [UI Widgets](./widgets.md)
141
Web-specific UI components for progress indicators, text input dialogs, and browser integration elements.
142
143
```java
144
public interface ResizableWidget {
145
void resize(int width, int height);
146
}
147
```