Driftwood2D / Driftwood

Driftwood 2D Tiling Game Engine and Development Suite
http://tileengine.org/
MIT License
24 stars 1 forks source link

Tiles on the same layer as an entity in pixel mode need special treatment. #162

Closed seisatsu closed 7 years ago

seisatsu commented 7 years ago

If a bush is on the same layer as the player, and they stand in front of it, they render on top of it, as expected. However if they stand behind it, they still render on top of it! While this makes perfect sense programmatically, it makes no sense aesthetically. Some special treatment is needed.

Suggested solution: While an entity's xy position is overlapping any part of the lower half of a tile on the same layer, the entity draws on top. Otherwise, it draws underneath. Once an entity's y position is further north than the halfway point of the tile, it "passes through".

The only other clean way I can think of to fix this issue is to not allow entities to overlap nowalk tiles at all in pixel mode, and I think we already decided against that.

pmer commented 7 years ago

This reminds me of Paper Mario style graphics.

Wouldn't a game would just want to keep tiles and entities on separate layers?

Although there is still the problem of entities overlapping each other which we might want to solve by sorting entities by Y-position before rendering.

pmer commented 7 years ago

Here's some psuedocode for your idea of entities “passing through” tiles.

# Iterate backward. Start with the bottom row & move our way up.
for z in range(len(self.layers)-1, -1):
    # Get all entities on this layer.
    entities = self.entities[z]
    # Sort the entities by Y-position. FYI, sorted() returns a copy of the original list.
    entities = sorted(by_y, entities)

    for y in range(self.height):
        # Draw a row of tiles.
        for x in range(self.width):
            draw_tile(x, y, z)

        # Draw entities on this row.
        while len(entities) > 0 and entities[0].y >= y:
            entities[0].draw()
            entities.shift()

    # Pump remaining entities. They are all above the first tile row.
    while len(entities) > 0:
        entities[0].draw()
        entities.shift()
seisatsu commented 7 years ago

Try walking along the side of the building toward the roof in the testing world to see where the problem is a problem.

pmer commented 7 years ago

What's the relationship between this issue and #137?

My intuition says that fixing #137 would also fix the roof problem.

pmer commented 7 years ago

Do you think “pass through” tiles will provide a solution to the side/roof behavior?

seisatsu commented 7 years ago

Ok, on second thought, pass-through tiles will not fix the roof behavior. You are right that fixing #137 will fix this issue, rather this kind of situation just won't happen anymore with smart pixel-based collisions. Best to just fix #137.

pmer commented 7 years ago

Closing this issue as a duplicate of #137.