#๐Ÿ”’ pygame/pycharm Character flipping problem

8 messages ยท Page 1 of 1 (latest)

rustic surge
#

Character keep flipping back rather than 1 flip

class Fighter():
    def __init__(self,x,y, data, sprite_sheet, animation_steps, flip):
        self.size = data[0]
        self.image_scale = data[1]
        self.offset = data[2]
        self.rect = pygame.Rect((x,y,80,180))
        self.animation_list = self.load_images(sprite_sheet, animation_steps)
        self.action = 0 # 0=idle / 1=run / 2=jump / 3=attack1 / 4=attack2 / 5=hit / 6=miss
        self.frame_index = 0
        self.image = self.animation_list[self.action][self.frame_index]
        self.flip = flip
        self.vel_y = 0
        self.x = x
        self.y = y
        self.jump = False
        self.attacking = False
        self.health = 150

    def load_images(self,sprite_sheet, animation_steps):
        animation_list = []
        for y, animation in enumerate(animation_steps):
            temp_img_list = []
            for i in range(animation):
                temp_img = sprite_sheet.subsurface (i * self.size, y * self.size, self.size, self.size)
                temp_img_list.append(pygame.transform.scale(temp_img, (self.size * self.image_scale, self.size * self.image_scale)))
            animation_list.append(temp_img_list)
        print(animation_list)
        return animation_list



    def move(self, Screen_width, Screen_height,surface, target):
        Sp = 8
        dx = 0
        Gravity = 2
        dy = 0

        #keypress
        key = pygame.key.get_pressed()
        #endlag
        if self.attacking == False:
            #flipping
            if key[pygame.K_q]:
                self.flip = False
            else:
                self.flip = True

    def draw(self,surface):
        img = pygame.transform.flip(self.image,self.flip,False)
        pygame.draw.rect(surface, (255,0,0), self.rect) #image flip
        surface.blit(img,(self.rect.x - (self.offset[0] * self.image_scale), self.rect.y - (self.offset[1]*self.image_scale)))
errant carbonBOT
#

@rustic surge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

rustic surge
#

i

#

!e

errant carbonBOT
#
Missing required argument

code

errant carbonBOT
#

@rustic surge

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.