[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] possible to get rid of ghost image after rotating a line?
- To: pygame-users <pygame-users@xxxxxxxx>
- Subject: [pygame] possible to get rid of ghost image after rotating a line?
- From: tom arnall <kloro2006@xxxxxxxxx>
- Date: Tue, 25 Aug 2015 13:57:44 -0700
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Tue, 25 Aug 2015 16:57:48 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=3NKZONWZtHnWoPEiQdUNlaHI+z49jCol1f5s+nuhsec=; b=WgNarEcHwDzYKByWVBEDzh0IuDkBj1pa0TVSB7bWF2AH9I6Ydr9IS9YSHEQIO2THVW geL9ajslIwKNzI0Ed5eefY3XrLbam+444XWezugSBjcgFb8BtXJg3eA1fExWbX8EOKga g/L+SajflxVQH59I6BKJsDnBdsLmkJ4mUDqNJxlQTrtu+E9ewbgx9RNcLO/k5jBSFenk kYesA35N8y8Mn8IykWNqUkyPbTfbl3+pNhlb3iPxT/RjO8WjytplKkG3ACtL41uFhmDV x2Nz8I4+BtSLGc1UOANNwbmMIUbu6OmlLxYnwmveQF8SR+ATjracDzyaF9ddl0Atqjub x98A==
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
I want to rotate a line around a point. The code that follows does
this, BUT when it draws a line, it leaves next to the line its ghost.
Is this a problem with pygame, or is there a change I can make in the
code which will make the problem go away?
import pygame, sys
from pygame.locals import *
import time
pygame.init()
#create a surface that will be seen by the user
screen = pygame.display.set_mode((400, 400))
#create a varible for degrees pf rotation
degree = 0
while True:
for event in pygame.event.get():
# quit the game if escape is pressed
if event.type == QUIT:
sys.exit()
elif event.type == KEYDOWN and\
event.key == K_ESCAPE:
sys.exit()
#clear screen at the start of every frame
screen.fill((40, 40, 40))
#create new surface with white BG
surf = pygame.Surface((1000, 5))
surf.fill((255, 255, 255))
#set a color key for blitting
surf.set_colorkey((255, 0, 0))
##ORIGINAL UNCHANGED
#where will the static image be placed:
where = (0,200)
#draw surf to screen and catch the rect that blit returns
blittedRect = screen.blit(surf, where)
##ROTATED
#get center of surf for later
oldCenter = blittedRect.center
#rotate surf by DEGREE amount degrees
rotatedSurf = pygame.transform.rotate(surf, degree)
#get the rect of the rotated surf and set it's center to the oldCenter
rotRect = rotatedSurf.get_rect()
rotRect.center = oldCenter
#draw rotatedSurf with the corrected rect so it gets put in the proper spot
screen.blit(rotatedSurf, rotRect)
#change the degree of rotation
degree += 5
if degree > 360:
degree = 0
#show the screen surface
pygame.display.flip()
#wait 60 ms until loop restart
pygame.time.wait(60)