如何解决在 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 举报,一经查实,本站将立刻删除。