[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?



Hi Tom,

Further resources for doing the work in maths and rendering the results:
I wrote a framework thing called PyStroke a couple of years ago, intended to avoid sprites altogether and only use collections of lines. Perhaps it would be useful for you?Â
https://github.com/PROGRAM-IX/pystroke
Examples of how it might be used are here:
https://github.com/PROGRAM-IX/vectorwars
https://github.com/PROGRAM-IX/identithief

I always meant to share it here, but I never quite got around to writing a tutorial I was happy with (it was my final year project at university). If it looks useful and you have any questions I'd be happy to help.

Good luck with your project,

James


On 26 August 2015 at 07:16, bw <stabbingfinger@xxxxxxxxx> wrote:
Hi, Tom,

Have you considered dealing with space mathematically, and rendering the results to screen?
https://pypi.python.org/pypi/euclid

Here is a different collection of spatial algorithms.
https://bitbucket.org/gummbum/gummworld2/src/6071c5f05c0f2526f5951a08581aefe61d5e4909/gamelib/gummworld2/geometry.py

Gumm


On 8/25/2015 4:25 PM, tom arnall wrote:
I spoke too soon. the use of draw.line() won't work for my application.

I need to be able to easily detect when the line touches a moving
target. Therefore AFIK I need the line to be either a surface or drawn
on a surface, so I can use the surface Rect to check when the line
collides with a target. I can't see a way to use a line created by
draw.line() to do this.

I also would like the line to behave like the example you referenced,
i.e. to rotate around one of its endpoints, not its center, but this
is a nice-to-have feature; it would also work if the line surface just
rotated around its center.

Tom Arnall

.....
âI have no special talents, only a passionate and stubborn curiosity.â
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)