nexus-2d 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,158 @@
1
+ export class Sprite extends Node {
2
+ /**
3
+ *
4
+ * @param {string} name
5
+ * @param {SpriteAtlas} atlas
6
+ * @param {*} options
7
+ */
8
+ constructor(name: string, atlas: SpriteAtlas, options?: any);
9
+ atlas: SpriteAtlas;
10
+ frameWidth: any;
11
+ frameHeight: any;
12
+ frame: any;
13
+ offset: {
14
+ x: any;
15
+ y: any;
16
+ };
17
+ flipH: boolean;
18
+ flipV: boolean;
19
+ modulate: any;
20
+ opaque: any;
21
+ framesPerRow: number;
22
+ /**
23
+ * convert frame index to atlas coordinates
24
+ *
25
+ * Example: 32x32 sprites in 256x256 atlas = 8 frames per row
26
+ * Frame 0 = (0, 0)
27
+ * Frame 5 = (160, 0) // 5 * 32 = 160
28
+ * Frame 8 = (0, 32) // wraps to next row
29
+ */
30
+ getFrameRect(frameIndex: any): {
31
+ x: number;
32
+ y: number;
33
+ width: any;
34
+ height: any;
35
+ };
36
+ /**
37
+ * draw sprite to canvas
38
+ *
39
+ *
40
+ * 1. Calculate world position (Node system handles this)
41
+ * 2. Apply offset (pivot point)
42
+ * 3. Get source rect from frame index
43
+ * 4. Blit pixels using tessera's drawAtlasRegionToCanvas
44
+ *
45
+ * Note: We're NOT handling rotation/scale YET. That requires
46
+ * per-pixel transforms which is slow in pure JS. For now,
47
+ * rotation/scale affects position but not the sprite pixels.
48
+ *
49
+ * Future optimization: pre-render rotated sprites to cache,
50
+ *
51
+ *
52
+ * If your atlas has no transparency (RGBA alpha always 255) and you don't need tint, call:
53
+ * @param {Camera2D} camera
54
+ */
55
+ _draw(canvas: any, camera: Camera2D): void;
56
+ /**
57
+ * Utility: set pivot to center of sprite
58
+ */
59
+ centerOrigin(): void;
60
+ }
61
+ /**
62
+ *
63
+ *
64
+ * why separate from Sprite:
65
+ * - Not all sprites need animation (static decorations)
66
+ * - Animation state (current frame, time accumulator) is extra memory
67
+ * - Keeps Sprite class lean for performance
68
+ *
69
+ * Common use case: character walk cycles, enemy attack patterns
70
+ */
71
+ export class AnimatedSprite extends Sprite {
72
+ animations: any;
73
+ currentAnimation: any;
74
+ currentFrameIndex: number;
75
+ frameTimer: number;
76
+ playing: boolean;
77
+ loop: boolean;
78
+ onAnimationFinished: any;
79
+ /**
80
+ * start playing an animation
81
+ * @param {string} animName
82
+ * @param {boolean} restart
83
+ * @returns
84
+ */
85
+ play(animName: string, restart?: boolean): void;
86
+ /**
87
+ * stop animation (freeze on current frame)
88
+ */
89
+ stop(): void;
90
+ /**
91
+ * pause (can resume with play())
92
+ */
93
+ pause(): void;
94
+ /**
95
+ * update animation state
96
+ *
97
+ * how frame timing works:
98
+ * - animation has target FPS (e.g., 12 fps = 0.083s per frame)
99
+ * - accumulate delta time until we hit frame duration
100
+ * - advance to next frame
101
+ * - loop or stop at end
102
+ *
103
+ * @param {number} delta
104
+ * @returns
105
+ */
106
+ _process(delta: number): void;
107
+ /**
108
+ * check if specific animation is playing
109
+ * @param {string} animName
110
+ * @returns
111
+ */
112
+ isPlaying(animName?: string): boolean;
113
+ /**
114
+ * get current animation progress (0.0 to 1.0)
115
+ */
116
+ getProgress(): number;
117
+ }
118
+ /**
119
+ * spriteAtlas - helper for managing shared atlases
120
+ *
121
+ *
122
+ * - Multiple sprites often share the same atlas (all enemies, all UI icons)
123
+ * - Loading atlas once and reusing saves memory
124
+ * - Provides utilities for common atlas patterns (grid, packed)
125
+ */
126
+ export class SpriteAtlas {
127
+ /**
128
+ * Utility: generate sequential frame array
129
+ * Example: getFrameRange(0, 7) -> [0,1,2,3,4,5,6,7]
130
+ */
131
+ static getFrameRange(start: any, end: any): any[];
132
+ constructor(renderer: any, path: any, options?: {});
133
+ path: any;
134
+ image: any;
135
+ frameWidth: any;
136
+ frameHeight: any;
137
+ framesPerRow: number;
138
+ framesPerCol: number;
139
+ totalFrames: number;
140
+ /**
141
+ * create a sprite from this atlas
142
+ * @param {*} name
143
+ * @param {*} frame
144
+ * @param {*} options
145
+ * @returns
146
+ */
147
+ createSprite(name: any, frame?: any, options?: any): Sprite;
148
+ /**
149
+ * Create animated sprite from this atlas
150
+ * @param {*} name
151
+ * @param {*} animations
152
+ * @param {*} options
153
+ * @returns
154
+ */
155
+ createAnimatedSprite(name: any, animations: any, options?: any): AnimatedSprite;
156
+ }
157
+ import { Node } from './core.js';
158
+ import { Camera2D } from './camera.js';
@@ -0,0 +1,21 @@
1
+ export class Tiled extends Node {
2
+ constructor(renderer: any, path: any, opts?: {}, opaque?: any[]);
3
+ basePath: string;
4
+ opts: {};
5
+ opaque: any[];
6
+ renderer: any;
7
+ json: any;
8
+ lastgid: any[];
9
+ tiles: any[];
10
+ layers: any[];
11
+ collisionObjects: any[];
12
+ processTilesets(tilesets: any): void;
13
+ /**
14
+ *
15
+ * @param {Array<any>} c
16
+ */
17
+ collisionLayerChildren(c: Array<any>): void;
18
+ processLayers(layers: any): void;
19
+ printDebug(): void;
20
+ }
21
+ import { Node } from './core.js';
@@ -0,0 +1,17 @@
1
+ export const vec2Pool: Vec2Pool;
2
+ declare class Vec2Pool {
3
+ constructor(initialSize?: number);
4
+ available: Vec2[];
5
+ inUse: Set<any>;
6
+ totalCreated: number;
7
+ acquire(x?: number, y?: number): Vec2;
8
+ release(vec: any): void;
9
+ reset(): void;
10
+ stats(): {
11
+ available: number;
12
+ inUse: number;
13
+ total: number;
14
+ };
15
+ }
16
+ import { Vec2 } from "planck";
17
+ export {};
@@ -1 +1,11 @@
1
1
  export * from "./engine/core.js";
2
+ export * from "./engine/cam.js";
3
+ export * from "./engine/controllers.js";
4
+ export * from "./engine/lib.js";
5
+ export * from "./engine/audio.js";
6
+ export * from "./engine/Charactercontrollerv2.js";
7
+ export * from "./engine/lerp.js";
8
+ export * from "./engine/particles.js";
9
+ export * from "./engine/physicsv2.js";
10
+ export * from "./engine/sprite.js";
11
+ export * from "./engine/tiled.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexus-2d",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "main": "index.js",
5
5
  "author": "sk",
6
6
  "license": "GPL-3.0-or-later",
@@ -8,7 +8,10 @@
8
8
  "access": "public"
9
9
  },
10
10
  "dependencies": {
11
- "tessera.js": "^0.2.5"
11
+ "planck": "^1.4.2"
12
+ },
13
+ "peerDependencies": {
14
+ "tessera.js": "^1.0.2"
12
15
  },
13
16
  "type": "module",
14
17
  "module": "dist/esm/index.js",
@@ -37,4 +40,4 @@
37
40
  "rollup-plugin-terser": "^7.0.2",
38
41
  "typescript": "^5.9.3"
39
42
  }
40
- }
43
+ }