【发布时间】:2020-01-04 02:33:17
【问题描述】:
为了实现 Frustum Culling 算法,我试图做的是从取决于玩家 x 和 y 位置的位置开始 render() 函数中的嵌套 for 循环,这样代码只会循环遍历 .tmx 文件的一小部分必须渲染的部分。 现在的问题是,如何从取决于我的 Player 坐标的位置开始循环? 提前感谢您的帮助。
import pygame
import pytmx
pygame.init()
class Map():
def __init__(self,filename):
tm=pytmx.load_pygame(filename,pixelalpha=True)
self.width=tm.width * tm.tilewidth
self.height=tm.height*tm.tileheight
self.tmxdata=tm
def render(self,surface):
ti=self.tmxdata.get_tile_image_by_gid
for layer in self.tmxdata.visible_layers:
if isinstance(layer,pytmx.TiledTileLayer):
for x,y,gid in layer:
tile = ti(gid)
if tile
surface.blit(tile,(x*self.tmxdata.tilewidth,y*self.tmxdata.tileheight))
def make_map(self):
temp_surface=pygame.Surface((self.width,self.height))
self.render(temp_surface)
return temp_surface
【问题讨论】:
-
如果您有答案,请接受。不需要浮动答案。