简体   繁体   中英

Sprite Sheets Pygame/Python

So I am making a game in pygame and really need to get sprite sheets working. Every sprite sheet example I've seen however, is either terrible and I have no idea how to use it or is not a class. I thought that by pressing in the direction of the arrow keys(which is the movement in my game) I could just draw it to the player objects x and y values. This works for the first arrow key and if you press another after that it errors with

TypeError: argument 1 must be pygame.Surface, not bool

My code is:

posi=[player.rect.x,player.rect.y]

if left1:
        posi=[player.rect.x,player.rect.y]
        screen.blit(left,posi)

    if right1:
        posi=[player.rect.x,player.rect.y]
        screen.blit(right,posi)

    if down1:
        posi=[player.rect.x,player.rect.y]
        screen.blit(down,posi)

    if up1:
        posi=[player.rect.x,player.rect.y]
        screen.blit(up,posi)

and I pretty much set left1,down1,right1 or up1 equal to true if you press an arrow key

It looks like you are not using screen.blit correctly. The first argument should be the image you are blitting (in other words, the picture of the sprite) and the second argument should be a tuple coordinate.

Go into your code and check what left is: I bet that it is not an image, so substitute it with the sprite's image. The coordinates are fine, though.

Pygame docs (see for help with surfaces): pygame home

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM