Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pygame规模搞乱了精灵_Python_Pygame - Fatal编程技术网

Python Pygame规模搞乱了精灵

Python Pygame规模搞乱了精灵,python,pygame,Python,Pygame,我正在制作一个2d自上而下的游戏,当我放大/缩小和更改分辨率时遇到问题 下面是我用来操纵图像(精灵)的代码: 这一行: self.screen.blit(self.char, (self.w/2- self.char_size*self.unit/self.h/2-self.char_size*self.unit/2)) 元组中左上方之间似乎缺少逗号: self.screen.blit(self.char, (self.w/2- self.char_size*self.unit, sel

我正在制作一个2d自上而下的游戏,当我放大/缩小和更改分辨率时遇到问题

下面是我用来操纵图像(精灵)的代码:

这一行:

self.screen.blit(self.char, (self.w/2- self.char_size*self.unit/self.h/2-self.char_size*self.unit/2))
元组中左上方之间似乎缺少逗号:

self.screen.blit(self.char, (self.w/2- self.char_size*self.unit, self.h/2-self.char_size*self.unit/2))
此外,您已经缩放了字符,因此只需向
char
查询其大小的
rect
,位于屏幕中央:

self.screen.blit(self.char, self.char.get_rect(center=(self.w/2, self.h/2)))

好吧,我知道怎么了。我需要保留我的原始加载图像,并在我想缩放我的精灵时使用该图像,否则,如果我有20x20加载图像,并将其缩放到10x10,然后再缩放到100x100,它将是一个10x10图像,拉伸到100x100

self.screen.blit(self.char, self.char.get_rect(center=(self.w/2, self.h/2)))