回溯(最近一次呼叫): 文件“***/Pcprojects/pygameKCC/kcc-shmup.py公司“,第49行,in 全部_精灵.更新()
我遵循一个教程,有工作代码(为他),和我的生活,我不能得到这个精灵渲染。有人能告诉我我做错了什么吗?这是我第一次用精灵而不是一个基本的弹跳球屏幕保护程序类型的东西。谢谢!你知道吗
import pygame
import random
import sys
import math
#global constants
WIDTH = 360
HEIGHT = 480
FPS = 30
#define colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
#YELLOW = (X, X, X)
class Player(pygame.sprite.Sprite):
#sprite for the player.
def __init__(self):
pygame.sprite.Sprite.__init__(self)
#required image and collision rectangle
self.image = pygame.Surface((50, 50))
self.image.fill(GREEN)
self.rect = self.image.get_rect()
self.rect.center = (WIDTH / 2, HEIGHT / 2)
#itialize pygame
#itialize music mixer
pygame.init()
pygame.mixer.init()
#create screen
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("My Game")
clock = pygame.time.Clock()
#create a group for all sprites to belong to
all_sprites = pygame.sprite.Group()
player = Player()
all_sprites.add(player)
running = True
while running:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
#更新:
all_sprites.update()
screen.fill(BLACK)
all_sprites.draw(screen)
pygame.display.flip()
pygame.quit()
您必须首先使用
fill()
清除屏幕,然后绘制精灵-draw()
。然后你可以在监视器上发送缓冲区-flip()
顺便说一句:要将元素集中在
screen
上,可以使用后来呢
同样的方法,你可以集中其他东西-即文本按钮。你知道吗
相关问题 更多 >
编程相关推荐