这样试试import pygame
from sys import *
pygame.init()
myscreen = pygame.display.set_mode((800,600))
class horse(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("girl.png")#被移动的图片
self.rect = self.image.get_rect()
self.rect.left = 8
self.rect.top = 10
speed = [4,0]
self.speed = speed
def move(self):
self.rect = self.rect.move(self.speed)
bgimage = pygame.image.load("girl.png")#背景图片
bgposition = bgimage.get_rect()
myscreen.blit(bgimage,bgposition)
horse1 = horse()
horseposition = horse1.rect
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
myscreen.blit(bgimage,bgposition)
myscreen.blit(horse1.image,horseposition)
horse1.move()
horseposition = horse1.rect
pygame.display.flip()
pygame.time.Clock().tick(3)
|