我使用pygame得到了一个python程序的问题。我想在太阳系中旋转(旋转)。它部分地起作用:在运行程序时关于太阳的一些奇怪的“口吃”问题。这种口吃一次又一次地出现在一个循环中。继承人的代码:”Pygame口吃对象
# -*- coding: utf-8 -*-
import pygame as pg
import pygame.locals as local
import sys
def rot_center(image, angle):
"""rotate an image while keeping its center and size"""
orig_rect = image.get_rect()
rot_image = pg.transform.rotate(image, angle)
rot_rect = orig_rect.copy()
rot_rect.center = rot_image.get_rect().center
rot_image = rot_image.subsurface(rot_rect).copy()
return rot_image
pg.init()
#deklaration
xres=0
yres=0
#auflösungseinstellungen
try:
xres=int(sys.argv[1]) #auflösung von der kommandozeile, parameter 1
yres=int(sys.argv[2]) #auflösung von der kammondozeile, parameter 2
except IndexError:
xres=800
yres=600
screen = pg.display.set_mode((xres,yres)) #coords nicht hart coden, variablen nutzen
pg.display.set_caption("future rpg prepreprepalphawhatever")
pg.mouse.set_visible(1)
pg.key.set_repeat(1,30)
clock = pg.time.Clock()
running = 1
rotation_stat = 0.0
while running:
planet01 = pg.image.load("grafik/menu/planet02.png")
planet01.set_colorkey((251,0,250), local.RLEACCEL) #load planet01
sun = pg.image.load("grafik/menu/sun.png") #load sun
bg = pg.image.load("grafik/menu/bg.png") #load background
#den hintergrund skalieren, falls auflösung zu hoch
sizedbg = pg.transform.smoothscale(bg, (xres, yres))
rotation_stat += 1
clock.tick(30)
screen.fill((0,0,0))
screen.blit(sizedbg, (0,0))
screen.blit(planet01, (xres/5-planet01.get_width()/2,yres/2-planet01.get_height()/2))
orig_rect = sun.get_rect()
sun = pg.transform.rotate(sun, rotation_stat)
screen.blit(sun, (xres/2-sun.get_width()/2,yres/2-sun.get_height()/2))
rot_rect = orig_rect.copy()
rot_rect.center = sun.get_rect().center
sun = sun.subsurface(rot_rect).copy()
for event in pg.event.get():
if event.type == local.QUIT:
running = 0
if event.type == local.KEYDOWN:
if event.key == local.K_ESCAPE:
pg.event.post(pg.event.Event(local.QUIT))
pg.display.flip()
Thx的答案,但如果我把代码加载的图像循环太阳将分裂和旋转真的很奇怪 – ShadowWolf 2012-03-24 11:32:53
我不完全确定它是否会解决您的问题,但尝试传递DOUBLEBUF set_mode()像这样:self.display_surface = pygame.display.set_mode(self.size,pygame .HWSURFACE | pygame.DOUBLEBUF) – 2012-03-24 13:03:37
ShadowWolf:那是因为你正在旋转之前旋转的图像。旋转后的图像会变大,然后旋转*,使其变大,等等。您的图像似乎会分开。 – imallett 2012-03-24 21:37:53