简体   繁体   English

在Pygame中平铺的地图

[英]Tiled Map in Pygame

I'm working on my first game in Pygame and I want to make a Tiled Map. 我正在Pygame上进行我的第一场比赛,我想制作一张Tiled Map。 How would one properly go about do this? 如何正确地做到这一点?
What I'm thinking of is just loading a tile and keep blitting it next to one another using a loop. 我在想的只是加载一个图块,并使用循环将其并排连续发送。

If you are good in javascript, then I would strongly advise in porting polymaps , which is tiny javascript based mapping/tiling library into python. 如果您精通javascript,那么我强烈建议您将polymaps移植,这是一个基于javascript的小映射/平铺库,集成到python中。 You just need code which handles creating a proper tile, then you could load data inside tile in any way you see fit, here is a good example http://polymaps.org/ex/tiles.html 您只需要用于处理创建适当图块的代码,然后就可以按照您认为合适的任何方式将数据加载到图块中,这是一个很好的示例http://polymaps.org/ex/tiles.html

You can use tiled editor ( www.mapeditor.pl ) to make a tiled map from prepared earlier tiles (choosing "new map" in tiled you can specified map and tiles size), than you can export your map to tmx format and load it to python using pytmx . 您可以使用图块编辑器( www.mapeditor.pl )从准备的较早图块制作图块地图(在图块中选择“新地图”,即可指定地图和图块大小),而不是将地图导出为tmx格式并加载它使用pytmx进行python 转换 You can also export your map to ascii file and write parser which load your map and render tiles. 您还可以将地图导出到ascii文件,并编写解析器以加载地图并渲染图块。

Not sure if this is much of a help now but you could try this: 不确定现在是否有很大帮助,但是您可以尝试以下方法:

for x in range(20): # Creates 20 tiles
    for y in range(20:
        surface.blit(tile, (x,y), 2)

this will create 20 X 20 box's then you just need to figure out how to move the rows and columns 这将创建20 X 20的盒子,那么您只需要弄清楚如何移动行和列即可

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM