Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3
Rendering
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 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:
fromrlbot.managersimportBotfromrlbot.flatimportGamePacket, ControllerStateclassRenderingTutorial(Bot):
defget_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()
returncontroller# ...We can see here that upon every call of get_output, the on-screen drawings get updated.
In this example, the draw_rect_2d method is used.
If you try rendering a lot of things at once, you will start to notice this message:
Too many bytes sent this tick, skipping message
There are a few ways to get around this.
- Reduce the amount of things you are rendering. This is the most straightforward way to reduce the amount of bytes sent. If you're rendering all 720 ball prediction slices, try only rendering 1 of 4 slices or so.
- Use the
renderer.draw_polyline_3dmethod. This method more efficiently sends a large amount of points to be drawn in a continuous line. - Avoid drawing every frame.
If you only need to draw something once, don't draw it every frame.
When calling
start_rendering, you can pass in agroup_idstring. By default, the group id is just"default". Old renders are only cleared when a new render with the same group id is sent. Using this, you can send parts of your render every frame, and that render will persist until the match ends (or a new render from the same process gets sent with the same group id).
defcreate_color(red: int, green: int, blue: int, alpha: int=255) ->Color: ...red,green,blue, andalphaare integers between0and255.
This is used for creating colors that you can use for the other methods that draw on screen. The renderer also has various attributes that gives you the most common colors:
renderer.transparentrenderer.blackrenderer.whiterenderer.greyrenderer.grayrenderer.bluerenderer.redrenderer.greenrenderer.limerenderer.yellowrenderer.orangerenderer.cyanrenderer.pinkrenderer.purplerenderer.tealLastly, there's the team_color method. Using this your bot renders with different colors depending on which team it is on.
defteam_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.
defdraw_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 from0to1.(0, 0)is the top left corner of the screen.width,height: The size of the rectangle. Range is from0to1.color: The color of the rectangle.centered: (Optional,Trueby default) IfTrue, the rectangle will be drawn centered on thexandycoordinates. Otherwise, the top left corner of the rectangle will be drawn on thexandycoordinates.
defdraw_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 from0to1.(0, 0)is the top left corner of the screen.scale: The size of the text.1is 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 isLeft.v_align: (Optional) The vertical alignment of the text. Default isTop.
defdraw_rect_3d(
self,
anchor: RenderAnchor|BallAnchor|CarAnchor|Vector3,
width: float,
height: float,
color: Color,
): ...anchor: The position of the rectangle. Can be aRenderAnchor,BallAnchor,CarAnchor, orVector3.width,height: The size of the rectangle.color: The color of the rectangle.
defdraw_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 aRenderAnchor,BallAnchor,CarAnchor, orVector3.scale: The size of the text.1is 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 isLeft.v_align: (Optional) The vertical alignment of the text. Default isTop.
defdraw_line_3d(
self,
start: RenderAnchor|BallAnchor|CarAnchor|Vector3,
end: RenderAnchor|BallAnchor|CarAnchor|Vector3,
color: Color,
): ...start: The start of the line. Can be aRenderAnchor,BallAnchor,CarAnchor, orVector3.end: The end of the line. Can be aRenderAnchor,BallAnchor,CarAnchor, orVector3.color: The color of the line.
defdraw_polyline_3d(
self,
points: Sequence[Vector3],
color: Color,
): ...points: A list ofVector3s that make up the polyline.color: The color of the polyline.