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

Re: [pygame] how to bind surface rects without subsurface (need help with bug)

Yep, changing the layer order is just a quick fix, not a real
solution.  You can keep the layer order you had before, and add a
move_layers function to the map.  Give the player a reference to the
map instead of the two layers, and call move_layers in the spots you
are setting the background.move and foreground.move.  Map.move_layers
would look something like this:

def move_layers(self, amount):
    for layer in [self.background, self.foreground]:
        layer.dirty = 1

Actually, it might be even better to just make move a function instead
of an attribute on TileLayer.  You will have to change less code (but
will still have the ugly bg/fg references in player).

class TileLayer(pygame.sprite.DirtySprite):
	def __init__(self, screen, layer, w, numx, h, numy):
		self.screen = screen
		if layer == 'fg':
			self.image = pygame.Surface((w*numx,h*numy), SRCALPHA, 32).convert_alpha()
			self.image = pygame.Surface((w*numx,h*numy)).convert()
		self.rect = self.image.get_rect()
        def move(self):
                self.dirty = 1

Then in player you would say:
self.background.move([self.movement, 0])
self.foreground.move([self.movement, 0])

etc.  Instead of assigning to those values.

The real problem is that you are delaying an action until the update
functions when it is really (in this case) an in-place action.