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

Re: [pygame] sprite groups and tilesheets



On Tue, 11 Nov 2008 13:27:08 -0800 (PST)
Devon Scott-Tunkin <djvonfunkin@xxxxxxxxx> wrote:

> Here's a basic sprite class with a looping animation:
> 
> class Bob(pygame.sprite.Sprite):
>   def __init__(self):
>     self.frame = 0
>     self.images = load_sprite('bob.png')
>     self.image = self.images[self.frame]
>     self.rect = self.image.get_rect()
>     self.animcounter = 0
>     self.animspeed = 7
>   def update(self):
>     self.animcounter = (self.animcounter + 1)%self.animspeed
>     if self.animcounter == 0:
>       self.frame = (self.frame + 1)%len(self.images)
>     self.image = self.images[self.frame]
> 
> 
> 
> bob = Bob()
> where bob.update() #would be called in the main loop

Thanks, Devon. I finally created a real sprite and i'm updating its
position with self.rect. Only problem is this bit of pseudo-code:

if moving down
	if self.rect.bottom > 3/4 of screen
		scrollpos = 0,-1
	else
		self.rect.move_ip(0,1)

What this does is scrolls the map if the rect is more than 75% down the
screen. But its not keeping track of the rect position when the screen
is scrolling. The player can run past the edge of map and avoid the
collisions because the rect isnt in the player's position since the
background moved. How can I move the rect AND the map like this?