在 pygame 中进行动画处理时,图像变为像素大小的两倍,并且在显示单个图像时出现故障,这是可以的
我尝试制作动画,但显示单个图像很好,但动画更多图像法师使图像大小加倍并且出现故障!
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)
在 pygame 中进行动画处理时,图像的像素大小变为两倍,并且在显示单个图像时出现故障,
我尝试制作动画,但图像变得翻转且大小变为双倍,我无法找到什么错误,请给我解决方案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

您必须缩放列表中的所有图像:
You have to scale all the images in the list: