Rendering
Learn how to draw text, shapes, and UI elements on the game screen using overlays.
Overlays let you draw on top of the game screen. Think of them like transparent sheets you can draw on that sit above the game.
How Overlays Work
1. Create a class that extends Overlay
2. Implement the render() method
3. Use Graphics2D to draw whatever you want
4. Add the overlay to OverlayManager
5. The render() method is called every frame
The render() Method
The render() method receives a Graphics2D object - this is your drawing tool. For text rendering, prefer PanelComponent and LineComponent over raw graphics.drawString() for better styling and theme support.
You can:
- Draw text: Use PanelComponent + LineComponent (recommended)
- Draw shapes: graphics.drawRect(), graphics.fillOval()
- Set colors: graphics.setColor()
- Set fonts: graphics.setFont()
The method should return a Dimension representing the size of your overlay.
Overlay Layers
Overlays can be drawn on different layers:
- **ABOVE_WIDGETS**: Above game UI
- **UNDER_WIDGETS**: Below game UI but above game
- **ABOVE_MAP**: Above the game map
Positioning
You can position overlays:
- **DYNAMIC**: Moves with the game camera
- **STATIC**: Fixed on screen
- **TOOLTIP**: Follows mouse
Best Practices
- Keep render() fast - it's called every frame
- Don't create new objects in render()
- Use proper overlay layers
- Return correct Dimension size
Code Examples
Example 1
1// Basic overlay with PanelComponent (recommended)
2private class MyOverlay extends Overlay {
3 private MyOverlay() {
4 setLayer(OverlayLayer.ABOVE_SCENE);
5 setPosition(OverlayPosition.TOP_LEFT);
6 }
7
8 @Override
9 public Dimension render(Graphics2D graphics) {
10 PanelComponent panel = new PanelComponent();
11 panel.setPreferredSize(new Dimension(200, 30));
12 panel.setBackgroundColor(new Color(0, 0, 0, 140));
13
14 panel.getChildren().add(
15 LineComponent.builder()
16 .left("Combat Level: " + combatLevel)
17 .leftColor(Color.WHITE)
18 .build()
19 );
20
21 return panel.render(graphics);
22 }
23}
24
25// Add to plugin
26@Inject
27private OverlayManager overlayManager;
28
29private final MyOverlay overlay = new MyOverlay();
30
31@Override
32protected void startUp() {
33 overlayManager.add(overlay);
34}
35
36@Override
37protected void shutDown() {
38 overlayManager.remove(overlay);
39}Example 2
1// Drawing with PanelComponent (includes border support)
2@Override
3public Dimension render(Graphics2D graphics) {
4 PanelComponent panel = new PanelComponent();
5 panel.setPreferredSize(new Dimension(220, 120));
6 panel.setBackgroundColor(new Color(0, 0, 0, 150));
7 panel.setBorderColor(Color.YELLOW); // Built-in border
8
9 panel.getChildren().add(
10 LineComponent.builder()
11 .left("Combat Level: " + combatLevel)
12 .leftColor(Color.WHITE)
13 .build()
14 );
15
16 return panel.render(graphics);
17}