PyGame 不渲染形状?
我编写了以下代码来使用图块渲染地图,它循环遍历文件并将字母转换为图块(矩形);
currtile_x = 0
currtile_y = 0
singlerun = 1
if singlerun == 1:
singlerun = 0
with open('townhall.map', 'r') as f:
for line in f:
for character in line:
if character == "\n":
currtile_y += 10
else:
if character == "x":
pygame.draw.rect(screen, (1,2,3), (currtile_x, currtile_y, 10, 10), 0)
currtile_x += 10
else:
if character == "a":
pygame.draw.rect(screen, (0,255,255), (currtile_x, currtile_y, 10, 10), 0)
currtile_x += 10
这是townhall.map 文件:
xxxxx
xaaax
xaaax
xaaax
xxxxx
I have made the following code to render the map using tiles, it loops through the file and translates letters into tiles (rectangles);
currtile_x = 0
currtile_y = 0
singlerun = 1
if singlerun == 1:
singlerun = 0
with open('townhall.map', 'r') as f:
for line in f:
for character in line:
if character == "\n":
currtile_y += 10
else:
if character == "x":
pygame.draw.rect(screen, (1,2,3), (currtile_x, currtile_y, 10, 10), 0)
currtile_x += 10
else:
if character == "a":
pygame.draw.rect(screen, (0,255,255), (currtile_x, currtile_y, 10, 10), 0)
currtile_x += 10
Here is the townhall.map file:
xxxxx
xaaax
xaaax
xaaax
xxxxx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当添加事件循环代码时,您的代码可以很好地工作。由于您还没有发布整个程序,我所能做的就是发布一个包含您的代码的工作程序。
Your code works well when event loop code is added to it. Since you haven't posted the whole program, everything I can do is to post a working program that contains your code.