diff options
author | Livio Recchia <recchialivio@libero.it> | 2020-02-10 23:06:34 +0100 |
---|---|---|
committer | Livio Recchia <recchialivio@libero.it> | 2020-02-10 23:06:34 +0100 |
commit | 9a13903a2f7d3a65fdf15a65fb59cccd622e2066 (patch) | |
tree | 9403b7dff39eb5e5d7fa0f79efb69b496add4c4b /external/pytmx/util_pyglet.py | |
parent | 11cc316b74d5f3f283413a33e7693b314741aa4a (diff) | |
download | manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.gz manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.bz2 manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.tar.xz manachat-9a13903a2f7d3a65fdf15a65fb59cccd622e2066.zip |
Initial commit
Diffstat (limited to 'external/pytmx/util_pyglet.py')
-rw-r--r-- | external/pytmx/util_pyglet.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/external/pytmx/util_pyglet.py b/external/pytmx/util_pyglet.py new file mode 100644 index 0000000..6b4a38a --- /dev/null +++ b/external/pytmx/util_pyglet.py @@ -0,0 +1,59 @@ +import logging + +logger = logging.getLogger(__name__) +ch = logging.StreamHandler() +ch.setLevel(logging.INFO) +logger.addHandler(ch) +logger.setLevel(logging.INFO) + +try: + import pyglet +except ImportError: + logger.error('cannot import pyglet (is it installed?)') + raise + +import pytmx + + +def pyglet_image_loader(filename, colorkey, **kwargs): + """basic image loading with pyglet + + returns pyglet Images, not textures + + This is a basic proof-of-concept and is likely to fail in some situations. + + Missing: + Transparency + Tile Rotation + + This is slow as well. + """ + if colorkey: + logger.debug('colorkey not implemented') + + image = pyglet.image.load(filename) + + def load_image(rect=None, flags=None): + if rect: + try: + x, y, w, h = rect + y = image.height - y - h + tile = image.get_region(x, y, w, h) + except: + logger.error('cannot get region %s of image', rect) + raise + else: + tile = image + + if flags: + logger.error('tile flags are not implemented') + + return tile + + return load_image + + +def load_pyglet(filename, *args, **kwargs): + kwargs['image_loader'] = pyglet_image_loader + kwargs['invert_y'] = True + return pytmx.TiledMap(filename, *args, **kwargs) |