pixel-perfect rendering, all sprites have same 1:1 scale
This commit is contained in:
@@ -1,24 +1,21 @@
|
||||
import { Container, Sprite, type Application } from 'pixi.js';
|
||||
import { Container, Sprite } from 'pixi.js';
|
||||
import type { GameStore } from '../../game/GameStore';
|
||||
import type { NodeKind } from '../../game/types';
|
||||
import { BUSH_SPRITE, TREE_SPRITE, type PixelGrid } from '../../game/sprites';
|
||||
import { chopShakeOffset } from '../animations';
|
||||
import { createShadow } from '../shadow';
|
||||
import { applySpriteSize, getSpriteTexture } from '../textures';
|
||||
import { getSpriteTexture } from '../textures';
|
||||
|
||||
const NODE_SPRITES: Record<NodeKind, PixelGrid> = { tree: TREE_SPRITE, bush: BUSH_SPRITE };
|
||||
const NODE_SIZES: Record<NodeKind, number> = { tree: 64, bush: 40 };
|
||||
// .entity.tree-shadow: width 64 height 32, margin (26, 0, 0, -11) -> center offset (-11, +26).
|
||||
// .entity.bush-shadow: width 40 height 20, margin (16, 0, 0, -6) -> center offset (-6, +16).
|
||||
const SHADOW_OFFSET: Record<NodeKind, { x: number; y: number; radiusX: number; radiusY: number }> = {
|
||||
tree: { x: -11, y: 26, radiusX: 32, radiusY: 16 },
|
||||
bush: { x: -6, y: 16, radiusX: 20, radiusY: 10 },
|
||||
tree: { x: -3, y: 7, radiusX: 8, radiusY: 4 },
|
||||
bush: { x: -2, y: 5, radiusX: 7, radiusY: 3 },
|
||||
};
|
||||
// .entity.tree/.bush click padding (padding: Npx; margin: -Npx) expands the clickable area beyond
|
||||
// the sprite's own box — approximated here as a circle for hit-testing (see GameCanvas).
|
||||
// Expands the clickable area beyond the sprite's own box — approximated here as a circle for
|
||||
// hit-testing (see GameCanvas).
|
||||
export const NODE_CLICK_RADIUS: Record<NodeKind, number> = {
|
||||
tree: NODE_SIZES.tree / 2 + 12,
|
||||
bush: NODE_SIZES.bush / 2 + 8,
|
||||
tree: 11,
|
||||
bush: 9,
|
||||
};
|
||||
|
||||
interface NodeVisual {
|
||||
@@ -30,11 +27,9 @@ interface NodeVisual {
|
||||
* live node) — entities are added/removed as nodes are chopped down or grown in. */
|
||||
export class NodesView {
|
||||
private readonly visuals = new Map<string, NodeVisual>();
|
||||
private readonly app: Application;
|
||||
private readonly entities: Container;
|
||||
|
||||
constructor(app: Application, entities: Container) {
|
||||
this.app = app;
|
||||
constructor(entities: Container) {
|
||||
this.entities = entities;
|
||||
}
|
||||
|
||||
@@ -79,10 +74,9 @@ export class NodesView {
|
||||
const offset = SHADOW_OFFSET[kind];
|
||||
const shadow = createShadow(offset.radiusX, offset.radiusY);
|
||||
|
||||
const info = getSpriteTexture(this.app, NODE_SPRITES[kind]);
|
||||
const info = getSpriteTexture(NODE_SPRITES[kind]);
|
||||
const sprite = new Sprite(info.texture);
|
||||
sprite.anchor.set(0.5);
|
||||
applySpriteSize(sprite, info, NODE_SIZES[kind]);
|
||||
|
||||
this.entities.addChild(shadow, sprite);
|
||||
const visual: NodeVisual = { shadow, sprite };
|
||||
|
||||
Reference in New Issue
Block a user