Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I get rid of the line following the sprites?
#1
So I've been following along with a tutorial I found online, basically this code allows me to spawn in sprites and have them move across the screen. I'm trying to figure out how to remove the lines following the sprites, is there a way to do so?

import pygame,random
 
 
class Player(pygame.sprite.Sprite):
    def __init__(self, *groups):
        super(Player, self).__init__(*groups)
        self.image = pygame.image.load('images/zombie.png')
        self.rect = pygame.rect.Rect((screen_width, (random.randrange(0,screen_height))), self.image.get_size())
        self.dx = -3
        self.pos = random.randrange(0,screen_height)
       
    def update(self):
       self.rect.centerx += self.dx
 
       if self.rect.right < 0:
           self.kill()
 
       
 
class Game(object):
    def main(self, screen):
        clock = pygame.time.Clock()
 
        sprites = pygame.sprite.Group()
        self.player = Player(sprites)
 
        while 1:
            clock.tick(40)
            numberAlien = 5

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    return
                if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    return


                sprites.update()
                sprites.draw(screen)


                drone = Player()
                if sprites.__len__() < numberAlien:
                    self.y = random.randrange(0,screen_height)
                    sprites.add(drone)

                pygame.display.flip()

if __name__ == '__main__':
   pygame.init()
   screen_width = 700
   screen_height = 500
   screen = pygame.display.set_mode((screen_width, screen_height))
   Game().main(screen)

Quote
#2
Two main problems.  You aren't clearing the screen (this is causing the "lines") and you are updating and drawing in the event loop.

Here is a quick rough fix:
Also please look here for an example of a base pygame program:
Pygame Template
hsunteik and metulburr like this post
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [PyGame] move randomly sprites reutB 4 320 Mar-29-2017, 01:12 PM
Last Post: metulburr

Forum Jump:


Users browsing this thread: 1 Guest(s)