[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Background ghosts



Hi Jake!

Thanks for responding.

The background that I blit in is the same size as the display surface, so I really am clearing the screen. :-/ I can see this - when I complete a row, I redraw the screen and everything looks fine. Then a new sprite starts making its  way down the board (imagine tetris) and, as soon as it is over top of the highest point where a block had been (even though it isn't there because rows disappeared), that old block  "shows through".

As for the splitting the sprites, I considered that. The problem is that when a row is complete (just like in Tetris), a whole piece that fell wouldn't necessarily disappear, but only part of one. I guess I could separate each piece into multiple sprites, but that would involve dozens of sprites and I don't think that the tracking of it would be any better than what I have right now.

Michael




-----Original Message-----
From: "Jake b" [ninmonkeys@xxxxxxxxx]
Date: 12/31/2008 23:12
To: pygame-users@xxxxxxxx
Subject: Re: [pygame] Background ghosts

It looks like you never clear the screen. try something like:
def drawBoard():
   self.screen.fill( (128,128,128) )
   blit background to display
   for piece in fallenPieces:
        blit piece to display
  display.flip()

Why do you split sprites into two groups? ( stopped, and moving )

(Not sure if that will exactly integrate into how your code, is, but
this is what I mean):

class TetrisMain():
	def __init__(self):
		"""init pygame, surfaces, sprite groups"""
		self.screen = #pygame screen
		self.pieces_list = #sprite group filled with pieces
		
	def draw(self):
		"""clear, blit background, blit pieces, flip."""
		self.screen.fill((128,128,128))
		self.screen.blit( self.background, (0,0))
		self.pieces_list.draw(self.screen)
		pygame.display.flip()
		
	def loop(self):
		"""main loop"""
		self.pieces_list.update() # update using sprite group
		self.draw()

On Wed, Dec 31, 2008 at 8:47 PM, Michael Phipps
<michael.phipps@xxxxxxxxxxx> wrote:
> I am finishing up my first pygame; everything has been fun and easy except this:
>
> The game is a tetris-like game (with a twist). I have the falling piece as a sprite. The background is just a bitmap. The pieces that have already fallen, I blit into place. So I have something like (in pseudo code):
>
> def drawBoard():
>    blit background to display
>    for piece in fallenPieces:
>         blit piece to display
>   display.flip()
>
> while 1: # game loop
>    moveSprite()
>    if sprite.nextLocation == taken
>        fallenPieces.Append(sprite.asPiece())
>        sprite = None
>        removeSolidRows() # This removes fallen pieces that have formed complete rows
>        drawboard()
>
> The problem that I have is that as the sprite is falling, I can see rows that have been removed. I have confirmed that drawBoard() is doing the right thing - when the sprite hits the bottom and the screen redraws, the ghosts disappear. They are only there when the sprite floats over them. It looks like the sprite is getting the data from the old version of the screen (i.e. before the last piece fell and rows were removed) to redraw the screen's dirty regions.
>
> Help!
>
> Michael
>



-- 
Jake