【发布时间】:2014-01-16 19:43:31
【问题描述】:
所以我试图在 Pygame 中绘制一个简单的火炬图像。但问题是这个精灵和我所有的其他精灵都在 10x10 左右。所以我使用比例来实验性地绘制它:
import pygame, sys
class sprites:
class torch(pygame.sprite.Sprite):
def __init__(self, image_file, location):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(image_file)
self.rect = self.image.get_rect()
self.rect.left, self.rect.top = location
self.image = pygame.transform.scale(self.image, ((100, 100)))
window = pygame.display.set_mode((300, 300))
width, height = window.get_size()
pygame.mouse.set_visible(True)
window.fill([0, 0, 0])
sprites.torch("torch.png", (50, 50))
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
sys.exit()
我是 pygame 的新手,所以我不确定我做错了什么。这个问题的另一个解决方案是,如果我可以将分辨率设置为 100x100 但尺寸设置为 500x500 提前谢谢你们! https://www.dropbox.com/s/38cy7a15jynes7c/torch.png
好的,根据cmets我没有画出精灵,那我该怎么做呢?就像我说的,我是全新的,对不起。
【问题讨论】:
-
此外,您永远不会将精灵绘制到窗口(或将其添加到组或对其进行任何其他操作)。
-
好吧,抱歉看起来完全愚蠢,但我对 pygame 完全陌生。你能为这个程序写一个修复程序吗?我用什么函数来绘制精灵?我怎样才能扩大规模?
-
@abarnert 没有。我希望它占用 100x100。我想我太从字面上看位置了。透明?是的,它们对黑色看起来是透明的,但它们实际上并不透明。并不是说它有什么不同
-
那你是说会画出尺寸比例?我不确定那个争论实际上在做什么。
-
好的,50x50 的东西是我的错;我没注意。您正在以默认大小加载 3x5 图像并将其缩放到 100x100,这应该非常难看,但完全可见。所以我会删除我的第一条评论。
标签: python image pygame sprite