[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] possible to get rid of ghost image after rotating a line?
Paul!
beautiful stuff. just what i needed.
thanks very much.
Tom Arnall
.....
âOnce you can accept the universe as matter expanding into nothing
that is something, wearing stripes with plaid comes easy.â Albert
Einstein
On 8/25/15, Paul Vincent Craven <paul@xxxxxxxxxxxxxxxx> wrote:
> I'm not sure why you are creating a new surface everytime. Or why you
> create one at all?
>
> Is this similar to what you are looking for?
>
> http://programarcadegames.com/python_examples/f.php?file=radar_sweep.py
>
> Paul Vincent Craven
>
> On Tue, Aug 25, 2015 at 3:57 PM, tom arnall <kloro2006@xxxxxxxxx> wrote:
>
>> 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)
>>
>
--