Skip to content

Scene Manager and Tilemap Rework #891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Jun 6, 2021
Merged

Scene Manager and Tilemap Rework #891

merged 36 commits into from
Jun 6, 2021

Conversation

Cleptomania
Copy link
Member

Tilemap Module

This contains a re-worked tilemap module.

It has been moved into a package rather than being a single module. It still only consists of one module, but it's been moved into a package to make it easier to break apart or add modules to later on.

The tilemap module has been re-worked to be object oriented as opposed to before where it was completely static.

Previously, a map was loaded in using the read_map function and then you would load in each layer as SpriteLists individually using that map object.

With the re-worked module, there is a new TileMap class, and a load_tilemap function which returns that class to load in a map.

Now when you pass in the map, all layers are automatically loaded in, including both Tile layers and Object layers. Objects are loaded in as a new type found in arcade_types.py called TiledObject. This contains the name of the object, it's properties, and a "shape" which uses Arcades existing types for Points, PointLists, and Rect.

All of the layers are then stored in OrderedDicts. One for the SpriteLists from tile layers, and one for the TiledObjects from the object layers. The keys for these dicts are their names, and they are ordered according to their order in the Tiled map.

The platformer tutorial has been updated to work with the new module, but all other Tiled documentation still needs updated.

One challenge this presented was how to deal with per layer options, like for instance using spatial hash to load one layer and not for another. Since they are all being loaded automatically, it means users can no longer specify these things on a per layer basis when loading them in.

To solve this, you can now pass a layer_options dictionary to either the __init__ of the TileMap class or the load_tilemap function. This dictionary can be used to pass those options based on the layer name, see below for an example:

Any of the options that could previously be used, can be passed through this dictionary. Right now that consists of use_spatial_hash, scaling, hit_box_algorithm, and hit_box_detail.

layer_options = {
    "Platforms": {
        "use_spatial_hash": True,
    },
}

my_map = load_tilemap(my_map_file, layer_options=layer_options)

Scene Manager

The new scene manager module contains a Scene class which essentially stores SpriteLists and provides functions to update/draw them.

The Scene class maintains a list and a dictionary. They both contain the same SpriteLists, the list is what is used to draw from, to maintain the draw order of SpriteLists. The dictionary is used by most of the helper functions to provide users with a way to name their SpriteLists and work on them easily without having to maintain what index they're in.

It also provides a classmethod helper function to create a Scene from a TileMap object. This will take in all of the SpriteLists from a TileMap and put them in the proper draw order and name them according to the Tiled layer name.

The platformer tutorial has been updated to use the Scene class, but other documentation and examples specific to the scene class still needs created.

The Scene is entirely optional, you can still maintain and draw SpriteLists manually as has been done previously, but this provides a very streamlined process for handling a larger number of SpriteLists, and the integration with the TileMap makes loading in and drawing a Tilemap extremely trivial.

@pvcraven pvcraven merged commit 6d64946 into development Jun 6, 2021
@einarf einarf deleted the scene-graph branch July 30, 2022 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants