Skip to content

Engine Design

JimmySnails edited this page Apr 10, 2020 · 7 revisions

Tile Drawing

Tiles have both a srcRect and destRect property. The srcRect property determines, which portion of the Spritesheet will be used. (clipped) The destRect determines, where the sprite will be drawn on the screen.
Also see https://wiki.libsdl.org/SDL_RenderCopy

Tile Selection

Isometric math can't convert screen to isometric coordinates, since we don't have access to node height information. We can only convert screen coordinates without height information.

To compensate this, we perform a basic hitcheck first. the screencoordinates are tested, if they're in the destrect of a texture. For performance, we don not perform a hitcheck on ALL tiles, but only on those which which are in the same column as the click

heightdescription-image

As you can see in the graphic, the calculated iso coord is below the clicked iso coord. we traverse this column upwards, until the hitcheck finds a point.

If this happens, a detailed check is performed. Here the screen coordinate is offset to on the spritesheet and if an opaque pixel is hit, the function returns true. The next check is, if the Z-level is higher than the current, to only return the foremost sprite.

hitcheck-image