Walking animation.

Walking animation.

Postby spamynator_1 » Wed Sep 18, 2013 11:40 pm

Hi, i have been trying to make a way so that when you press a movement key, in a 2d rpg style game, that the sprites image changes based one what movement key you are pressing. So if you are pressing up it loads images char4, char42, and char43 as a walking animation, and it would use side angles for left and right and a front angle for down. creating a stepping effect based on the direction you are moving. This is the cluster fluff i came up with:
Code: Select all
def movement(self):
        if self.state == "PLAY":
            if self.chariable > 3:
                self.chariable = 1
            for event in pg.event.get():
                pg.key.set_repeat(1,50)
                if event.key == pg.K_w:
                    y -= 3
                    if self.chariable == "1":
                        self.screen.blit(CHAR1,(x,y))
                    elif self.chariable == "2":
                        self.screen.blit(CHAR12,(x,y))
                    elif self.chariable == "3":
                        self.screen.blit(CHAR13,(x,y))
                    self.chariable += 1
                   
                elif event.key == pg.K_s:
                    y += 3
                    if self.chariable == "1":
                        self.screen.blit(CHAR2,(x,y))
                    elif self.chariable == "2":
                        self.screen.blit(CHAR22,(x,y))
                    elif self.chariable == "3":
                        self.screen.blit(CHAR23,(x,y))
                    self.chariable += 1
                   
                elif event.key == pg.K_a:
                    x -= 3
                    if self.chariable == "1":
                        self.screen.blit(CHAR3,(x,y))
                    elif self.chariable == "2":
                        self.screen.blit(CHAR32,(x,y))
                    elif self.chariable == "3":
                        self.screen.blit(CHAR33,(x,y))
                    self.chariable += 1
                   
                elif event.key == pg.K_d:
                    x += 3
                    if self.chariable == "1":
                        self.screen.blit(CHAR4,(x,y))
                    elif self.chariable == "2":
                        self.screen.blit(CHAR42,(x,y))
                    elif self.chariable == "3":
                        self.screen.blit(CHAR43,(x,y))
                    self.chariable += 1


This does not bring up any errors, but it does not blit any picture on to the screen, thanks for the help.
spamynator_1
 
Posts: 63
Joined: Sun Mar 03, 2013 12:45 am

Re: Walking animation.

Postby Hissing Cockroach » Sun Oct 06, 2013 6:26 pm

I'm no expert, but I think you'r problem is that you
haven't defined what CHAR is in you'r code.
User avatar
Hissing Cockroach
 
Posts: 108
Joined: Sat Sep 14, 2013 2:35 pm
Location: Earth

Re: Walking animation.

Postby metulburr » Sun Oct 06, 2013 8:49 pm

try checking out mekire's code here
New Users, Read This
version Python 3.3.2 and 2.7.5, tkinter 8.5, pyqt 4.8.4, pygame 1.9.2 pre
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
User avatar
metulburr
 
Posts: 1103
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Walking animation.

Postby Mekire » Mon Oct 07, 2013 7:01 am

User avatar
Mekire
 
Posts: 816
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan


Return to Game Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron