为什么精灵图像会闪烁/闪烁?

时间:2012-01-12 14:20:14

标签: python pygame

如何防止精灵图像无法控制地闪烁? (图像名称是水管工)。当你运行程序时,唯一的图像闪烁是精灵。

import pygame
import os, sys
import itertools
import pygame
from pygame.sprite import Sprite

cloud_background = pygame.image.load('clouds.bmp')
brick_tile = pygame.image.load('brick_tile.png')
plumbers = pygame.image.load('Mario_sideways_sprite_2xL.png')

pink = (255, 64, 64)
w = 640
h = 480
screen = pygame.display.set_mode((w, h))
running = 1

def setup_background():
    screen.fill((pink))
    screen.blit(cloud_background,(0,0))
    brick_width, brick_height = brick_tile.get_width(), brick_tile.get_height()
    for x,y in itertools.product(range(0,640,brick_width),
                                 range(390,480,brick_height)):
        # print(x,y)
        screen.blit(brick_tile, (x,y))


def show_sprites():
    screen.blit(plumbers,(50,337))
    pygame.display.flip()



while running:
    show_sprites()
    setup_background()
    pygame.display.flip()
    event = pygame.event.poll()
    if event.type == pygame.QUIT: sys.exit()

1 个答案:

答案 0 :(得分:0)

我真的不知道pygame,但是当你等待在这个领域有更多经验的人的回答时。我可以提供可能有用的建议。

每次从头开始设置背景,这是一个处理器密集型过程。最好的方法是实际上只重新渲染所需的背景部分。即你的管道工精灵占用的部分。

通常,您可以通过创建两个名为old X,old Y的变量来完成此操作。渲染过程耗尽。

目前,您在每个循环周期中渲染整个屏幕。

相关问题