autoTiling
require
sprite()parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
tag | string | 'tile sheet' |
example
autoTiling({ tag: 'tile sheet'}),function autoTiling(p) { const param = { tag: 'tile sheet', ...p, }; return { id: param.tag, require: ['sprite'], add() { requestAnimationFrame(() => { const level = this.getLevel(); const { x, y } = this.tilePos; const hasTile = (x, y) => { if (x < 0 || x >= level.numColumns() || y < 0 || y >= level.numRows()) return false; for (const e of level.getAt({ x, y, })) { if (e.has(param.tag)) return true; } return false; }; const up = hasTile(x, y - 1); const right = hasTile(x + 1, y); const down = hasTile(x, y + 1); const left = hasTile(x - 1, y); const upLeft = up && left && hasTile(x - 1, y - 1); const upRight = up && right && hasTile(x + 1, y - 1); const downRight = down && right && hasTile(x + 1, y + 1); const downLeft = down && left && hasTile(x - 1, y + 1); const index = (up ? 1 : 0) | (upRight ? 2 : 0) | (right ? 4 : 0) | (downRight ? 8 : 0) | (down ? 16 : 0) | (downLeft ? 32 : 0) | (left ? 64 : 0) | (upLeft ? 128 : 0); this.play(index); }); }, };}