在 pygame 中进行动画处理时,图像变为像素大小的两倍,并且在显示单个图像时出现故障,这是可以的

发布于 01-17 02:58 字数 1388 浏览 3 评论 0原文

我尝试制作动画,但显示单个图像很好,但动画更多图像法师使图像大小加倍并且出现故障!

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攒一口袋星星2025-01-24 02:58:12

您必须缩放列表中的所有图像:

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))

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))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文