When enemy is comes into site dont tween sprite from (0,0) to correct location, instead just create at correct location

This commit is contained in:
Peter Stockings
2026-01-06 17:59:56 +11:00
parent a6bcf24cd0
commit 57fb85f62e
2 changed files with 53 additions and 17 deletions

View File

@@ -209,4 +209,34 @@ describe('DungeonRenderer', () => {
const ratSpriteCall = mockScene.add.sprite.mock.calls.find((call: any) => call[2] === 'rat');
expect(ratSpriteCall).toBeDefined();
});
it('should initialize new enemy sprites at target position and not tween them', () => {
renderer.initializeFloor(mockWorld, 1);
// Position 5,5 -> 5*16 + 8 = 88
const TILE_SIZE = 16;
const targetX = 5 * TILE_SIZE + TILE_SIZE / 2;
const targetY = 5 * TILE_SIZE + TILE_SIZE / 2;
mockWorld.actors.set(999, {
id: 999,
category: "combatant",
isPlayer: false,
type: "rat",
pos: { x: 5, y: 5 },
stats: { hp: 10, maxHp: 10 } as any,
} as any);
(renderer as any).fovManager.visibleArray[5 * mockWorld.width + 5] = 1;
mockScene.add.sprite.mockClear();
mockScene.tweens.add.mockClear();
renderer.render([]);
// Check spawn position
expect(mockScene.add.sprite).toHaveBeenCalledWith(targetX, targetY, 'rat', 0);
// Should NOT tween because it's the first spawn
expect(mockScene.tweens.add).not.toHaveBeenCalled();
});
});