所以我正在制作一款平台游戏。您将看到的代码只是它的开头。问题是由于某种原因,pygame拒绝将我的对象绘制到屏幕上。一切似乎都没问题,我甚至没有任何错误。非常感谢帮助。 :)
import pygame
from pygame.locals import *
pygame.init()
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
black = (0,0,0)
white = (255,255,255)
width = 1280
height = 720
score = 0
'create window'
screen = pygame.display.set_mode((width,height))
clock = pygame.time.Clock()
'sprite groups'
all_sprites = pygame.sprite.Group()
blocks = pygame.sprite.Group()
class Player(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((32,32))
self.image.fill(green)
self.rect = self.image.get_rect()
self.rect.x = 640
self.rect.y = 360
self.speed = 0
def update(self):
pass
class Block(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((32,32))
self.image.fill(blue)
self.rect = self.image.get_rect()
self.rect.x = 640
self.rect.y = 395
p = Player()
all_sprites.add(p)
running = True
while running:
all_sprites.draw(screen)
答案 0 :(得分:2)
在循环内部,您需要包含screen.update()
,以便屏幕实际刷新的每一帧:
while running:
all_sprites.draw(screen)
screen.update()