Sets the color used for the background of your game.
This function is typically used within draw() to reset the display window at the beginning of each frame.
The color parameter can take one of two forms. It can be:
rgb()
command.The default background color is white.
// Draw a blue background background("blue");
Use the mouse pointer position to change the color of the background.
// Use the mouse pointer position to change the color of the background. function draw() { background(rgb(World.mouseX, World.mouseY, 0)); }
Using the rgb
block, create a background using RGB colors.
// Use RGB numbers to set a background color. background(rgb(63, 127, 255));
background(color)
Name | Type | Required? | Description |
---|---|---|---|
color | String | The color used for the background or a call to the rgb() command. |
No return value. Changes output to the display only.
rgb()
as a parameter to background instead of a color name.rect()
because it will fill the screen regardless of how big the screen is.draw()
function, you need to redraw the entire image, back to front, not just the part that is moving.Found a bug in the documentation? Let us know at documentation@code.org