如何让sprite在python / pygame中移动?

时间:2016-05-20 07:41:37

标签: python-3.x sprite

我有点像乒乓球比赛,但我似乎无法让球拍移动。 所以这是代码:

import pygame
pygame.init()
GameDisplay=pygame.display.set_mode([800,600])
pygame.display.set_caption('GAME')
FPS=pygame.time.Clock()
black=(0,0,0)
white=(255,255,255)
GameDisplay.fill(white)
StopProgram=False
class Paddle(pygame.sprite.Sprite):
def __init__(self,image=pygame.image.load('Paddle.png')):
    super(Paddle,self).__init__()
    self.image=pygame.image.load('Paddle.png')
    self.rect=self.image.get_rect()
    self.speed=(2,2)
def setPosition(self,x,y):
    self.rect.x=x
    self.rect.y=y
def move(self,x,y):
    self.rect.centerx
    self.rect.centery
PaddleGroup=pygame.sprite.Group()
PaddlePlayer1=Paddle()
PaddlePlayer1.setPosition(235,492)
PaddleGroup.add(PaddlePlayer1)
PaddleGroup.draw(GameDisplay)
while not StopProgram:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            StopProgram=True
        if event.type==pygame.KEYDOWN:
            if event.key==pygame.K_LEFT:
                PaddlePlayer1.rect.move_ip(-5,0)
    pygame.display.flip()

    FPS.tick(60)

pygame.quit()
quit()

我希望有人可以帮我解决问题。(抱歉英语不好。)

0 个答案:

没有答案