Adafruit_Learning_System_Gu.../CircuitPython_displayio/displayio_sprite_sheet/code.py
2023-11-06 10:35:43 -06:00

42 lines
1.1 KiB
Python

# SPDX-FileCopyrightText: 2019 Carter Nelson for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import board
import displayio
import adafruit_imageload
display = board.DISPLAY
# Load the sprite sheet (bitmap)
sprite_sheet, palette = adafruit_imageload.load("/cp_sprite_sheet.bmp",
bitmap=displayio.Bitmap,
palette=displayio.Palette)
# Create a sprite (tilegrid)
sprite = displayio.TileGrid(sprite_sheet, pixel_shader=palette,
width = 1,
height = 1,
tile_width = 16,
tile_height = 16)
# Create a Group to hold the sprite
group = displayio.Group(scale=1)
# Add the sprite to the Group
group.append(sprite)
# Add the Group to the Display
display.root_group = group
# Set sprite location
group.x = 120
group.y = 80
# Loop through each sprite in the sprite sheet
source_index = 0
while True:
sprite[0] = source_index % 6
source_index += 1
time.sleep(2)