Note that there are some explanatory texts on larger screens.

plurals
  1. POPygame: Why Won't My Player Animation Play?
    primarykey
    data
    text
    <p>Hello I am currently working on a survival shooter game and I am currently getting frustrated at a few things. One being my player animation not working. I have the code for the player class right here:</p> <pre><code>import pygame from zombie import * # Player class Player(pygame.sprite.Sprite): def __init__(self, x, y, gravity): # Player dimensions and position # Player image and animation self.images = [] self.images.append(pygame.image.load('images/Sprites/player.png')) self.images.append(pygame.image.load('images/Sprites/player2.png')) #~ self.images.append(pygame.image.load('ball1.png')) #~ self.images.append(pygame.image.load('ball2.png')) self.maxImage = len(self.images) self.currentImage = 0 #~ self.rect = pygame.Rect(x, y, 80, 80) self.rect = self.images[0].get_rect() self.rect.x = x self.rect.y = y self.timeTarget = 10 self.timeNum = 1 self.velX = 0 self.velY = 0 self.health = 100 # Jump and gravity self.jumping = False self.on_ground = False self.origJumpVel = 15 self.jumpVel = self.origJumpVel self.gravity = 0.5 # Jump inputs def do_jump(self): if self.jumping and not self.on_ground: self.velY = -self.jumpVel self.jumpVel -= self.gravity if self.on_ground: self.jumping = False self.jumpVel = self.origJumpVel self.velY = 0 self.on_ground = True def handle_events(self, event): if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: if not self.jumping: self.jumping = True self.on_ground = False elif event.key == pygame.K_a: self.velX = -5 elif event.key == pygame.K_d: self.velX = +5 elif event.type == pygame.KEYUP: if event.key in (pygame.K_a, pygame.K_d): self.velX = 0 # PLayer updates def update(self): # Animations if self.timeNum == self.timeTarget: self.currentImage += 1 if self.currentImage &gt;= self.maxImage: self.currentImage = 0 self.timeNum = 1 # Health #if self.rect.x == zombie.rect.x: #self.health -= 10 # Screen wrap if self.rect.right &gt; 1280: self.rect.left = 0 elif self.rect.left &lt; 0: self.rect.right = 1280 # Player rendering def render(self, surface): surface.blit(self.images[self.currentImage], self.rect) </code></pre> <p>If you want to know about any of my other problems/frustrations just say so. Any help will be greatly appreciated. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload