Arcade.SpriteSolidColor
lastmod 2026-11-10created 2022-03-032 edits
SpriteSolidColor is a subclass of Sprite in the Python game library Arcade that creates a rectangular sprite filled with a single color, without an image file. You pass only the width, height, and color, and internally it generates an image of that size with PIL to use as the texture, reusing textures with the same parameters from a cache. Because the hit box is the rectangle itself, it is used to quickly create walls, floors, or placeholder rectangles.
Code
class SpriteSolidColor(Sprite):
"""
This sprite is just a rectangular sprite of one solid color. No need to
use an image file.
:param int width: Width of the sprite
:param int height: Height of the sprite
:param Color color: Color of the sprite
"""
def __init__(self, width: int, height: int, color: Color):
"""
Create a solid-color rectangular sprite.
"""
super().__init__()
cache_name = _build_cache_name("Solid", width, height, color[0], color[1], color[2])
# use existing texture if it exists
if cache_name in load_texture.texture_cache: # type: ignore
texture = load_texture.texture_cache[cache_name] # type: ignore
# otherwise, generate a filler sprite and add it to the cache
else:
image = PIL.Image.new("RGBA", (width, height), color)
texture = Texture(cache_name, image)
load_texture.texture_cache[cache_name] = texture # type: ignore
# apply chosen texture to the current sprite
self.texture = texture
self._points = texture.hit_box_points