import pygame,sys
from pygame.locals import *
pygame.init()
FPS = 30 #frames per second setting
fpsClock = pygame.time.Clock()
#set up the window
DISPLAYSURF = pygame.display.set_mode((400,300),0,32)
pygame.display.set_caption('Animation')
GREEN = (0,255,0)
catImg = pygame.image.load('cat.png')
catx=10
caty=10
direction='right'
while True:
	DISPLAYSURF.fill(GREEN)
	if direction == 'right':
		catx+=5
		if catx == 280:
			direction = 'down'
	elif direction=='down':
		caty+=5
		if caty == 220:
			direction='left'
	elif direction == 'left':
		catx-=5
		if catx==10:
			direction='up'
	elif direction == 'up':
		caty -=5
		if caty==10:
			direction = 'right'
	DISPLAYSURF.blit(catImg,(catx,caty))
	for event in pygame.event.get():
		if event.type == QUIT:
			pygame.quit()
			sys.exit()
	pygame.display.update()
	fpsClock.tick(FPS)

pygame使用之第一个简单的动画效果实现

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
  • 2022-01-08
  • 2022-12-23
  • 2022-01-21
  • 2021-10-30
猜你喜欢
  • 2021-10-18
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案