Original Post
🔒 Locked
Sprite sheet [python/pygame]
Advertisement
In your api you should be able to switch the UV coordinates of your image on your tile. To draw the top left tile, you just draw a quad with uv's from (0,0) to (.25,.25). To draw the next frame in the animation (say the tile to the right), just change the UV coordinates to (.25,0)/(.5,.25).
Each time you render you only want to draw 1/16th of the image, so you just choose which part to render depending on your animation frame.
Each time you render you only want to draw 1/16th of the image, so you just choose which part to render depending on your animation frame.
if you know the offset of the topleft corner of each image, and the width and height of each image, you can use a loop and blit each image to a temporary surface, then append the surface to a image list.
so for a sprite sheet that's, say for simplicty's sake, 4 images at 16x16 each:
so for a sprite sheet that's, say for simplicty's sake, 4 images at 16x16 each:
def loadPics(): imgList = [] for i in range(4): tmp = pygame.Surface((16,16)) tmp.blit(sheet, (0,0), ((16*i,0), (16,16))) imgList.append(tmp)Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement