screen = pygame.display.set_mode((WIDTH,HEIGHT))
canvas = pygame.Surface((WIDTH,HEIGHT))def makefunnytiles(saice):
global WIDTH
global HEIGHT
global screen
global roomdata
global tiledefinitions
print("Baking Tiles")
print(roomdata)
index = 0
index2 = 0
for symbolic in saice:
index2 = 0
symbolic = symbolic.strip()
print("sanity")
for symbol in list(symbolic):
print(symbol)
if symbol in tiledefinitions:
canvas.blit(pygame.image.load("sprites/" + str(roomdata['area']) + "/" + str(tiledefinitions[symbol]) + ".png").convert_alpha(), ((32 * index2),(32 * index)))
index2 += 1
index += 1
screen.blit(canvas, (0,0))
pygame.display.flip()
print("drew screen")
print(str(canvas.get_width))我有个问题,因为某种原因,画布在屏幕中央被切断了。

我遇到的另一个问题是文件末尾的pgzrun.go(),这个错误导致程序崩溃:
Traceback (most recent call last):
File "C:\Users\RushVisor\Documents\Glamore\main.py", line 100, in <module>
pgzrun.go()
File "E:\Python39\lib\site-packages\pgzrun.py", line 31, in go
run_mod(mod)
File "E:\Python39\lib\site-packages\pgzero\runner.py", line 113, in run_mod
PGZeroGame(mod).run()
File "E:\Python39\lib\site-packages\pgzero\game.py", line 217, in run
self.mainloop()
File "E:\Python39\lib\site-packages\pgzero\game.py", line 225, in mainloop
self.reinit_screen()
File "E:\Python39\lib\site-packages\pgzero\game.py", line 73, in reinit_screen
self.mod.screen.surface = self.screen
AttributeError: 'pygame.Surface' object has no attribute 'surface'我已经尝试修改画布和屏幕的分辨率值,甚至雪碧的位置本身。我将画布缩到屏幕上,而不是直接绘制到屏幕上,因为如果我是对的,应该可以更容易地添加滚动。
我很感激任何人能给我的任何帮助。
发布于 2022-01-08 00:35:54
错误
self.mod.screen.surface = self.screen变量self.mod.screen接缝是类pygame.Surface的一个对象。这个类的对象没有一个名为surface的变量,这就是AttributeError: 'pygame.Surface' object has no attribute 'surface'似乎来自的错误。
这将解决问题,如果您不想实现一个带有表面属性的额外类:self.mod.screen = self.screen。但是,不要忘记,如果您想要这样的东西:self.screen:self.mod.screen = self.screen.copy(),这不会复制表面的self.mod.screen = self.screen.copy()。
滚动
您的想法是实现滚动的一种可能的方法。另一个就是你的商店,某种来源和blit瓷砖的基础之一。如果您现在想滚动,您只需更改您以前定义的原点。
原产地定义
origin = [10,10] # or use pygame.math.Vector2 or something elseBlit码
index = 0
index2 = 0
for symbolic in saice:
index2 = 0
symbolic = symbolic.strip()
print("sanity")
for symbol in list(symbolic):
print(symbol)
if symbol in tiledefinitions:
screen.blit(pygame.image.load("sprites/" + str(roomdata['area']) + "/" + str(tiledefinitions[symbol]) + ".png").convert_alpha(), ((32 * index2)+origin[0],(32 * index)+origin[1]))
index2 += 1
index += 1现在,您只需调用blit代码一次每帧。如果您现在想滚动,只需执行如下操作:origin[0] += 10 (将所有符号移动到右侧)。
上面的blit代码并不是最快的,因为它需要加载每个帧上的所有图像,但是这只是一个例子,滚动可以与另一个想法一起工作
编辑:我不太熟悉Pygame Zero,所以这只是基于我对standart Pygame的了解。
https://stackoverflow.com/questions/67666309
复制相似问题