BlueGit

timfa questward

Files

questward / shared / render / pivot.js

pivot.js

1823a2b4 History
pivot.js 979 B Download Raw
1import { PIVOT_FROM_BOTTOM_PX } from "../protocol/constants.js";
2
3export function tilePivot (tileX, tileY, tileSize)
4{
5 return {
6 x: tileX * tileSize + tileSize / 2,
7 y: tileY * tileSize + tileSize / 2
8 };
9}
10
11export function spriteCenterFromPivot (pivotX, pivotY, spriteHeight, zoom)
12{
13 const height = spriteHeight * zoom;
14 return {
15 x: pivotX,
16 y: pivotY - (height / 2 - PIVOT_FROM_BOTTOM_PX * zoom)
17 };
18}
19
20export function spriteDrawSize (spriteWidth, spriteHeight, zoom)
21{
22 return {
23 w: spriteWidth * zoom,
24 h: spriteHeight * zoom
25 };
26}
27
28export function ySortLayer (sortY, subOrder)
29{
30 return 10000 + Math.round(sortY) * 4 + subOrder;
31}
32
33/**
34 * Free-flight sprites (e.g. pigeons) must draw above all ground y-sorted
35 * blocks/entities. Bias sits well above {@link ySortLayer} for any in-view tile.
36 */
37export const FLIGHT_SORT_BIAS = 2_000_000;
38
39export function flightSortLayer (sortY, subOrder = 0)
40{
41 return FLIGHT_SORT_BIAS + Math.round(sortY) * 4 + (subOrder | 0);
42}