Reputation: 11
I try to animate but displaying single image is good but animating more image mage double the size of image and glitching!
import pygame,sys
class dog(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.list=[]
self.list.append(pygame.image.load("sword of stones\mm.png"))
self.list.append(pygame.image.load("sword of stones\mn.png"))
self.list.append(pygame.image.load("sword of stones\mm.png"))
self.list.append(pygame.image.load("sword of stones\mm.png"))
self.list.append(pygame.image.load("sword of stones\mn.png"))
self.count = 0
self.image =self.list[self.count]
self.image=pygame.transform.scale(self.image,(32,32))
self.rect=self.image.get_rect(topleft=(200,200))
def update(self):
self.count +=1
if self.count >= len(self.list):
self.count=0
self.image =self.list[self.count]
pygame.init()
clock=pygame.time.Clock()
windows =pygame.display.set_mode((500,500))
tiles =pygame.sprite.Group()
dog1 =dog()
tiles.add(dog1)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
windows.fill((255,255,255))
tiles.draw(windows)
tiles.update()
pygame.display.flip()
clock.tick(60)
while animating in pygame image become twice the pixel size and glitching while displaying single image its ok
I tried make animation but image are become flippering and size become double I not able to find what error pls give me solutions.
Upvotes: 1
Views: 60
Reputation: 211258
You have to scale all the images in the list:
class dog(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.list=[]
self.list.append(pygame.image.load("sword of stones\mm.png"))
self.list.append(pygame.image.load("sword of stones\mn.png"))
self.list.append(pygame.image.load("sword of stones\mm.png"))
self.list.append(pygame.image.load("sword of stones\mm.png"))
self.list.append(pygame.image.load("sword of stones\mn.png"))
# v INSERT v
self.list = [pygame.transform.scale(img, (32,32)) for img in self.list]
self.count = 0
self.image = self.list[self.count]
# v DELETE v
# self.image=pygame.transform.scale(self.image,(32,32))
self.rect=self.image.get_rect(topleft=(200,200))
Upvotes: 1