2 Replies - 6031 Views - Last Post: 30 July 2012 - 11:34 PM Rate Topic: -----

#1 jephindavis  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 19
  • Joined: 13-November 09

Sprite sheet and character animation

Posted 30 July 2012 - 02:29 PM

Hi guys!
In my game i have a character that is to be animated. If I'm pressing the right arrow,
the character moves right with the walking animation. I have used some 10 frames and is updating the picture
sequentially, which actually is dirty coding. So it would really help me if you guys could shed some light on
sprite sheets and character animation using sprite sheets.
Is This A Good Question/Topic? 0
  • +

Replies To: Sprite sheet and character animation

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Sprite sheet and character animation

Posted 30 July 2012 - 07:53 PM

Can you show us the dirty code you have thus far? Also, it'll probably help if you upload the image too.
Was This Post Helpful? 0
  • +
  • -

#3 jephindavis  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 19
  • Joined: 13-November 09

Re: Sprite sheet and character animation

Posted 30 July 2012 - 11:34 PM

View Postatraub, on 31 July 2012 - 08:23 AM, said:

Can you show us the dirty code you have thus far? Also, it'll probably help if you upload the image too.



import pygame,os
from pygame import *
import random

pygame.init()
pygame.key.set_repeat(1,1)

pygame.mixer.music.load("music.ogg")
pygame.mixer.music.play(-1)
pygame.mixer.music.set_volume(0.3)
class Shadow(pygame.sprite.Sprite):
      def __init__(self):
          pygame.sprite.Sprite.__init__(self)
          self.image=pygame.image.load("frames/Stand1.png")
          self.rect=self.image.get_rect()
          self.rect.x=20
          self.rect.y=510
      def update(self):
          self.image=pygame.image.load("frames/Frame0.png")
      def update0(self):
          self.image=pygame.image.load("frames/Stand1.png")
          self.rect=self.image.get_rect()
          self.rect.x=26
          self.rect.y=510
      def update1(self):
          self.image=pygame.image.load("frames/Frame1.png")
          self.rect=self.image.get_rect()
          self.rect.x=20
          self.rect.y=510
      def update2(self):
          self.image=pygame.image.load("frames/Frame2.png")  
      def update3(self):
          self.image=pygame.image.load("frames/Frame3.png")  
      def update4(self):
          self.image=pygame.image.load("frames/Frame4.png")  
      def update5(self):
          self.image=pygame.image.load("frames/Frame5.png")  
      def update6(self):
          self.image=pygame.image.load("frames/Frame6.png")  
      def update7(self):
          self.image=pygame.image.load("frames/Frame7.png")  
      def update8(self):
          self.image=pygame.image.load("frames/Frame8.png")  
      def update9(self):
          self.image=pygame.image.load("frames/Frame9.png")  
      def update10(self):
          self.image=pygame.image.load("frames/Frame10.png")  
      def update11(self):
          self.image=pygame.image.load("frames/Frame11.png")  
      def update12(self):
          self.image=pygame.image.load("frames/Frame12.png")  
      def update13(self):
          self.image=pygame.image.load("frames/Frame13.png")
def main():
            
      background = pygame.Surface(screen.get_size())
      background=pygame.image.load("backclothwithclose.jpg")
      close=pygame.image.load("backclothwithcloseup.jpg")
      screen.blit(background,(0,0))
      clock =pygame.time.Clock()
      shadow = Shadow()
      allSprites = pygame.sprite.Group(shadow)
      keepGoing = True
      while keepGoing:
          clock.tick(30)
          x,y=pygame.mouse.get_pos()
          if x>1052 and x<1166 and y>35 and y<64:
                screen.blit(close,(0,0))
          else:
                screen.blit(background,(0,0))
          for event in pygame.event.get():
              if event.type == pygame.QUIT:
                    keepGoing = False
              elif event.type==pygame.KEYDOWN and event.key==pygame.K_ESCAPE: 
                    keepGoing = False
              elif event.type==pygame.MOUSEBUTTONDOWN:
                    x,y=pygame.mouse.get_pos()
                    if x>1052 and x<1166 and y>35 and y<64:
                          keepGoing = False
              
              elif event.type==pygame.KEYDOWN and event.key==pygame.K_RIGHT :
                    allSprites.update()
                    allSprites.draw(screen)
                    pygame.display.flip()
                    pygame.time.delay(30)
                    #
                    shadow.update1()
                    allSprites.draw(screen)
                    pygame.display.flip()
                    pygame.time.delay(30)
                    #
                    shadow.update2()
                    allSprites.draw(screen)
                    pygame.display.flip()
                    pygame.time.delay(30)
                    #
                    shadow.update3()
                    allSprites.draw(screen)
                    pygame.display.flip()
                    pygame.time.delay(30)
                    #
                    shadow.update4()
                    allSprites.draw(screen)
                    pygame.display.flip()
                    pygame.time.delay(30)
                    #
                    shadow.update5()
                    allSprites.draw(screen)
                    pygame.display.flip()
                    pygame.time.delay(30)
                    #
                    shadow.update6()
                    allSprites.draw(screen)
                    pygame.display.flip()
                    pygame.time.delay(30)
                    #
                    shadow.update7()
                    allSprites.draw(screen)
                    pygame.display.flip()
                    pygame.time.delay(30)
                    #
                    shadow.update8()
                    allSprites.draw(screen)
                    pygame.display.flip()
                    pygame.time.delay(30)
                    #
                    shadow.update9()
                    allSprites.draw(screen)
                    pygame.display.flip()
                    pygame.time.delay(30)
                    #
                    shadow.update10()
                    allSprites.draw(screen)
                    pygame.display.flip()
                    pygame.time.delay(30)
                    #
                    shadow.update11()
                    allSprites.draw(screen)
                    pygame.display.flip()
                    pygame.time.delay(30)
                    #
                    shadow.update12()
                    allSprites.draw(screen)
                    pygame.display.flip()
                    pygame.time.delay(30)
                    #
                    shadow.update13()
                    allSprites.draw(screen)
                    pygame.display.flip()
                    pygame.time.delay(30)
if __name__ == "__main__":
      main()



The sprite image is attached

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1