Categories
Blog posts

Depth sorting

App Game Kit offers a function that sets the depth of a sprite. The depth values are used in deciding the order sprites are drawn in. A sprite drawn after another sprite, will be drawn on top of or ‘in front’ of that sprite. This is now applied in such a way that the floor tiles are always drawn first, while the drawing order of the player and the wall tiles is made to depend on their vertical location on the screen. For example, a wall lower on the screen than the player is drawn after the player, so that the wall is in front of the player.

The player walks between the walls

To give the player something to disappear behind the wall tiles were made a bit taller. I have not made them so tall as to completely hide the player and other game characters. The small dot indicating which way the player is looking, is always drawn on top of everything, as it is considered part of the interface.

Categories
Blog posts

Scrolling tiles

As the game will feature levels that are larger than the screen, it now has a scrolling view on the current level. The player will be in the center of the view, except if the view is close to the edge of the level, at which stage the view stops scrolling. The level is made up of 16×16 tiles. Tiles can be walkable or closed. At a later stage the tiles, or what is depicted by them, such as walls, will be drawn in such a way that the player can disappear behind them or walk in front of them, corresponding with the side-on view of the player.

Demonstration of the scrolling tiles making up the viewport

The view upon a portion of the world is implemented as a fixed set of sprites. The image that is assigned to each sprite depends on its corresponding location in the world at that moment. To achieve the effect of a viewport moving to the right, to keep up with the player, all sprites are moved to the left. When the sprites have moved more than the width of a tile to the left, all horizontal sprite positions are reset and their images are reassigned. In this fashion the image of a piece of wall will ‘move’ across the sprites.

This approach is not my own idea, I actually read about it on the App Game Kit forum, for example in this post: ‘Tile Based Map Scrolling – The most efficient way?’ In the demonstration seen above, the viewport was intentionally made smaller than the screen, so that the effect of the tiles being reset is visible. In the final game this effect would fall outside of the screen. (Although in some games such a smaller viewport is of course deliberately used to limit the distance the player can see ahead. I am not sure if my game will do that, but in that case the edge effect would have to be hidden by other means.)