What I m trying to do in order to implement the Frustum Culling algorithm is to start the nested for loop in the render() function from a position that will depend on the player x and y position, such that the code will only loop through a small portion of the .tmx file the portion that has to render. Now the question is, How do I start the loop from a position that will depend from my Player coordinates? Thanks in advance for the help.
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