Closed jefpadfi closed 10 years ago
are you using pygame sprites and groups, or do you have your own thing going on? If you can link or paste the code you are working with, that will help me out a lot.
Here is how i have the code for the sprite.
#pyganim sprite creation
# step one: load the "standing" sprites (these are single images, not animations)
self.front_standing = pygame.image.load('data/images/sprites/crono_front.gif')
self.back_standing = pygame.image.load('data/images/sprites/crono_back.gif')
self.left_standing = pygame.image.load('data/images/sprites/crono_left.gif')
self.right_standing = pygame.transform.flip(self.left_standing, True, False)
self.playerWidth, self.playerHeight = self.front_standing.get_size()
# creating the PygAnimation objects for walking/running in all directions
animTypes = 'back_run back_walk front_run front_walk left_run left_walk'.split()
self.animObjs = {}
for animType in animTypes:
imagesAndDurations = [('data/images/sprites/crono_%s.%s.gif' % (animType, str(num).rjust(3, '0')), 0.1) for num in range(6)]
self.animObjs[animType] = PygAnimation(imagesAndDurations)
# create the right-facing sprites by copying and flipping the left-facing sprites
self.animObjs['right_walk'] = self.animObjs['left_walk'].getCopy()
self.animObjs['right_walk'].flip(True, False)
self.animObjs['right_walk'].makeTransformsPermanent()
self.animObjs['right_run'] = self.animObjs['left_run'].getCopy()
self.animObjs['right_run'].flip(True, False)
self.animObjs['right_run'].makeTransformsPermanent()
So it is multiple files instead of a sprite sheet. The entire code can be found at
https://github.com/TheDocter/The-World-Engine/blob/master/Player/Player.py
Thanks for that. I'm going to close this issue since animation isn't really a goal of the pyscroll project; I want to keep it simple. I will leave you will a couple comments and an open invite to contact me on the #pygame channel at freenode.net.
I've looked over your world engine project and it seems to me that you would be better off using standard pygame sprites and sprite groups. You've duplicated a lot of the functionality of sprites/groups and there isn't a lot of consistency.
If you created a subclass of pygame.sprite.Sprite and created a property for both Sprite.image and Sprite.rect, you could very easily reuse pygame Sprite Groups.
Here's a quick example:
class MySprite(pygame.sprite.Sprite):
# normal __init__(), update(), etc
@property
def image(self):
return self.current_animation.getCurrentFrame()
@property
def rect(self):
self._update_rect()
return self._rect
def _update_rect(self):
self._rect = self.current_animation.getRect()
self._rect.topleft = self.position
I've left out a lot of code, but I think that you will be able to fill in the rest. If you have a working Sprite subclass, then you can use it with pyscroll's PyscrollGroup for fast, layered scrolling. Take a look at the Hero class in the quest demo for ideas.
With the demo you just a sprite moving around. Right now I have my sprite animated using http://inventwithpython.com/pyganim/
I was wondering how I could modify pyscroll to work with that. I have the map displaying but it is not centered on the player nor will it scroll due to how I have the sprite set up for animation. Any suggestions or thoughts would be great.