def add_image(self, base_path, file):
if not os.path.exists(file):
file = os.path.join(base_path, file)
texture = Image(source=file).texture
print('loading', file)
texture.mag_filter = 'nearest'
if texture is None:
sys.exit('failed to locate image file %r' % file)
id = self.firstgid
th = self.tile_height + self.spacing
tw = self.tile_width + self.spacing
for j in range(texture.height // th):
for i in range(texture.width // tw):
x = (i * tw) + self.margin
# convert the y coordinate to OpenGL (0 at bottom of texture)
y = texture.height - ((j + 1) * th)
tile = texture.get_region(x, y, self.tile_width, self.tile_height)
self.tiles.append(Tile(id, tile, self))
id += 1
评论列表
文章目录