在 pygame 中使用精灵

问题描述

对于我的最终项目。我必须用 pygame 制作游戏,我没有太多问题,但是当我试图弄清楚如何使用精灵表时,我观看的每个视频都略有不同,这让我很困惑

    # Import and initiliaze pygame
import pygame
pygame.init()

#Create window
screen = pygame.display.set_mode((500,500))

#Create name
pygame.display.set_caption("Crashlanding")


#Charecter creation
x = 50
y = 50
width = 40
height = 60
vel = 5

#Jumps
jumping = False
jumpcount = 10

#Main event loop

run = True

while run:
    pygame.time.delay(100) # (100 milisecond) 0.1 second delay

    for event in pygame.event.get():
        if event.type == pygame.QUIT: #if the red x is clcked kill the loop and end the game
            run = False



#Creates controls and movement accordingly
    keys = pygame.key.get_pressed()

    if keys[pygame.K_LEFT] and x > vel:
        x -= vel

    if keys[pygame.K_RIGHT] and x < 500 - vel - width:
        x += vel

    if not (jumping):
        if keys[pygame.K_UP] and y > vel:
            y-= vel

        if keys[pygame.K_DOWN] and y < 500 - height - vel:
            y += vel

        if keys[pygame.K_SPACE]:
            jumping = True
    else:
        if jumpcount >= -10:
            y -= (jumpcount * abs(jumpcount)) * 0.5
            jumpcount -= 1
        else:
            jumpcount = 10
            jumping = False
    screen.fill((30,23,40))
    pygame.draw.rect(screen,(250,0),(x,y,width,height))

    pygame.display.update()


pygame.quit()

我想要做的是利用这个精灵表动画,用于我们正在尝试制作的 2d 平台游戏My sprite sheet

我对 pygame 知之甚少,但似乎有些直截了当。任何帮助

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)