how to load an image to a grid using pygame, instead of just using a fill color?

半世苍凉 提交于 2019-11-28 01:45:36
ninMonkey

Here's an example I wrote. It uses a numpy to store tile data. The code plus image is downloadable at: http://code.google.com/p/ninmonkey/source/.../maptiles (If that fails, use this url: https://storage.googleapis.com/google-code-archive-source/v2/code.google.com/ninmonkey/source-archive.zip )

  • Press S to toggle mouse scrolling.
  • Map.tiles is a 2d numpy.array that stores tile's id

If you want to add units/sprites that are on top of the tilemap: (Your buildings might count as this)

  • store location using world coordinates
  • draw them using a world2screen coordinate function.

The function will add the map offset to their world coordinates. So if the map offset is (-100,0) and your unit's world coordinate is (0,0), you render at (-100,0) placing them a the top left part of the map, as expected, even though you are scrolled.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!