Skip to content

Rendering

Eric Veilleux edited this page Feb 2, 2025 · 7 revisions

About

Rendering allows you to draw objects on screen, which can make debugging and testing your bot so much easier. For example, you could draw the predicted ball path, or draw where the bot wants to go.

The basics

The renderer object is built into the Bot class, so you don't need to import anything other than Bot. Each time you want to render something, you start with self.renderer.begin_rendering() and end with self.renderer.end_rendering(). The rendering code goes in between the begin_rendering() and end_rendering(). Let's take a look at an example:

from rlbot.managers import Bot
from rlbot.flat import GamePacket, ControllerState

class RenderingTutorial(Bot):
    def get_output(self, packet: GamePacket) -> ControllerState:
        controller = ControllerState()

        self.renderer.begin_rendering()
        self.renderer.draw_rect_2d(20, 20, 200, 200, self.renderer.black, True)
        self.renderer.end_rendering()

        return controller

# ...

We can see here that every get_output call, the on-screen drawings get updated. In this example, the draw_rect_2d method is used.

Rendering a large amount

WIP section

The methods of renderer

renderer.create_color and other colors

create_color(red: int, green: int, blue: int, alpha: int = 255) -> Color
  • red, green, blue, and alpha are integers between 0 and 255.

This is used for creating colors that you can use for the other methods that draw on screen. The renderer also has a list of color methods that gives you the most common colors:

renderer.transparent
renderer.black
renderer.white
renderer.grey
renderer.gray
renderer.blue
renderer.red
renderer.green
renderer.lime
renderer.yellow
renderer.orange
renderer.cyan
renderer.pink
renderer.purple
renderer.teal

Lastly, there's the team_color method. Using this your bot renders with different colors depending on which team it is on.

team_color(team: int, alt_color: bool = False) -> Color
  • team - Index of a team (0 for blue, 1 for orange)
  • alt_color - (Optional, False by default) If True, the alternate team color will be used.

renderer.draw_rect_2d

draw_rect_2d(
    self,
    x: float,
    y: float,
    width: float,
    height: float,
    color: Color,
    centered: bool = True,
)
  • x, y - The position of the rectangle. Range is from 0 to 1. (0, 0) is the top left corner of the screen.
  • width, height - The size of the rectangle. Range is from 0 to 1.
  • color - The color of the rectangle.
  • centered - (Optional, True by default) If True, the rectangle will be drawn centered on the x and y coordinates. Otherwise, the top left corner of the rectangle will be drawn on the x and y coordinates.

renderer.draw_string_2d

draw_string_2d(
    self,
    text: str,
    x: float,
    y: float,
    scale: float,
    foreground: Color,
    background: Color = Color(),
    h_align: TextHAlign = TextHAlign.Left,
    v_align: TextVAlign = TextVAlign.Top,
)
  • x, y - The position of the rectangle. Range is from 0 to 1. (0, 0) is the top left corner of the screen.
  • scale - The size of the text. 1 is the "normal" size.
  • foreground - The color of the text.
  • background - (Optional) The color of the background of the text. Transparent by default.
  • h_align - (Optional) The horizontal alignment of the text. Default is left.
  • v_align - (Optional) The vertical alignment of the text. Default is top.

renderer.draw_rect_3d

draw_rect_3d(
    self,
    anchor: RenderAnchor | BallAnchor | CarAnchor | Vector3,
    width: float,
    height: float,
    color: Color,
)
  • anchor - The position of the rectangle. Can be a RenderAnchor, BallAnchor, CarAnchor, or Vector3.
  • width, height - The size of the rectangle.
  • color - The color of the rectangle.

renderer.draw_string_3d

draw_string_3d(
    self,
    text: str,
    anchor: RenderAnchor | BallAnchor | CarAnchor | Vector3,
    scale: float,
    foreground: Color,
    background: Color = Color(),
    h_align: TextHAlign = TextHAlign.Left,
    v_align: TextVAlign = TextVAlign.Top,
)
  • text - The text to draw.
  • anchor - The position of the text. Can be a RenderAnchor, BallAnchor, CarAnchor, or Vector3.
  • scale - The size of the text. 1 is the "normal" size.
  • foreground - The color of the text.
  • background - (Optional) The color of the background of the text. Transparent by default.
  • h_align - (Optional) The horizontal alignment of the text. Default is left.
  • v_align - (Optional) The vertical alignment of the text. Default is top.

renderer.draw_line_3d

draw_line_3d(
    self,
    start: RenderAnchor | BallAnchor | CarAnchor | Vector3,
    end: RenderAnchor | BallAnchor | CarAnchor | Vector3,
    color: Color,
)
  • start - The start of the line. Can be a RenderAnchor, BallAnchor, CarAnchor, or Vector3.
  • end - The end of the line. Can be a RenderAnchor, BallAnchor, CarAnchor, or Vector3.
  • color - The color of the line.

renderer.draw_polyline_3d

draw_polyline_3d(
    self,
    points: Sequence[Vector3],
    color: Color,
)
  • points - A list of Vector3s that make up the polyline.
  • color - The color of the polyline.
Clone this wiki locally