Skip to main content
gamedev.net
🔒 Locked

Sprite sheet [python/pygame]

Started by matkod Oct 31, 2010 at 3:13 PM 1 replies 1.4k views
Original Post
matkod
matkod
Hi,

I know that it's a newbie question, but how can i create animation with a image like this?

http://fc04.deviantart.net/fs71/f/2010/092/9/f/Char_Template___Female_Thin_by_Kiwinuptuo.png

i can animate when i have multiple images, but how i load when they are all in one?


thanks.
karwosts
karwosts
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.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Esys
Esys
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:

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.