emeraldengine 2.2.1 → 3.1.0

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.
Files changed (208) hide show
  1. package/README.md +2198 -968
  2. package/dist/types/index.d.ts +75 -32
  3. package/dist/types/src/Animator.d.ts +50 -0
  4. package/dist/types/{BitmapText.d.ts → src/BitmapText.d.ts} +19 -21
  5. package/dist/types/src/Camera.d.ts +122 -0
  6. package/dist/types/src/CameraController.d.ts +107 -0
  7. package/dist/types/src/CanvasText.d.ts +91 -0
  8. package/dist/types/src/CollisionLayers.d.ts +58 -0
  9. package/dist/types/{Color.d.ts → src/Color.d.ts} +6 -6
  10. package/dist/types/src/Coroutine.d.ts +111 -0
  11. package/dist/types/src/DebugOverlay.d.ts +86 -0
  12. package/dist/types/src/Drawable.d.ts +271 -0
  13. package/dist/types/src/Easing.d.ts +22 -0
  14. package/dist/types/src/Emerald.d.ts +420 -0
  15. package/dist/types/src/EmeraldDB.d.ts +159 -0
  16. package/dist/types/{FPSCounter.d.ts → src/FPSCounter.d.ts} +1 -3
  17. package/dist/types/src/GLUtils.d.ts +4 -0
  18. package/dist/types/{Instance.d.ts → src/Instance.d.ts} +37 -15
  19. package/dist/types/{InstancedTexture.d.ts → src/InstancedTexture.d.ts} +75 -23
  20. package/dist/types/src/Interpolator.d.ts +66 -0
  21. package/dist/types/src/Material.d.ts +87 -0
  22. package/dist/types/src/MathUtils.d.ts +81 -0
  23. package/dist/types/src/ParticleEmitter.d.ts +131 -0
  24. package/dist/types/src/Physics.d.ts +337 -0
  25. package/dist/types/src/Pool.d.ts +53 -0
  26. package/dist/types/src/PostEffects.d.ts +68 -0
  27. package/dist/types/src/PostProcessor.d.ts +124 -0
  28. package/dist/types/src/RenderTarget.d.ts +56 -0
  29. package/dist/types/src/Scene.d.ts +62 -0
  30. package/dist/types/src/ScreenEffects.d.ts +111 -0
  31. package/dist/types/src/Serializer.d.ts +86 -0
  32. package/dist/types/src/Shaders.d.ts +2 -0
  33. package/dist/types/{Shapes.d.ts → src/Shapes.d.ts} +4 -6
  34. package/dist/types/src/SpatialGrid.d.ts +50 -0
  35. package/dist/types/src/SpriteBatch.d.ts +89 -0
  36. package/dist/types/src/StateMachine.d.ts +59 -0
  37. package/dist/types/src/Storage.d.ts +89 -0
  38. package/dist/types/{Texture.d.ts → src/Texture.d.ts} +3 -4
  39. package/dist/types/src/TextureAtlas.d.ts +55 -0
  40. package/dist/types/src/Tilemap.d.ts +91 -0
  41. package/dist/types/src/Time.d.ts +53 -0
  42. package/dist/types/src/Timer.d.ts +54 -0
  43. package/dist/types/src/Transform.d.ts +94 -0
  44. package/dist/types/src/Tween.d.ts +81 -0
  45. package/dist/types/src/UI.d.ts +121 -0
  46. package/dist/types/src/components/Behaviour.d.ts +71 -0
  47. package/dist/types/{components → src/components}/BoxCollider.d.ts +14 -14
  48. package/dist/types/src/components/BoxColliderDebug.d.ts +15 -0
  49. package/dist/types/{components → src/components}/CircleCollider.d.ts +14 -12
  50. package/dist/types/src/components/CircleColliderDebug.d.ts +15 -0
  51. package/dist/types/src/components/Collider.d.ts +102 -0
  52. package/dist/types/src/components/GameObject.d.ts +135 -0
  53. package/dist/types/src/components/PolygonCollider.d.ts +33 -0
  54. package/dist/types/src/components/RigidBody.d.ts +456 -0
  55. package/dist/types/src/importers/Aseprite.d.ts +79 -0
  56. package/dist/types/src/importers/ForgeLevel.d.ts +97 -0
  57. package/dist/types/src/importers/TiledMap.d.ts +62 -0
  58. package/dist/types/{lights → src/lights}/DirectionalLight.d.ts +7 -9
  59. package/dist/types/{lights → src/lights}/PointLight.d.ts +6 -9
  60. package/dist/types/src/managers/AssetManager.d.ts +116 -0
  61. package/dist/types/src/managers/AudioManager.d.ts +259 -0
  62. package/dist/types/{managers → src/managers}/CameraManager.d.ts +8 -8
  63. package/dist/types/{managers → src/managers}/EventManager.d.ts +46 -32
  64. package/dist/types/src/managers/GLManager.d.ts +84 -0
  65. package/dist/types/src/managers/GLState.d.ts +37 -0
  66. package/dist/types/src/managers/Gamepad.d.ts +102 -0
  67. package/dist/types/src/managers/IDManager.d.ts +31 -0
  68. package/dist/types/src/managers/InputManager.d.ts +381 -0
  69. package/dist/types/src/managers/NetworkManager.d.ts +93 -0
  70. package/dist/types/src/managers/RenderStats.d.ts +34 -0
  71. package/dist/types/src/managers/SceneManager.d.ts +44 -0
  72. package/dist/types/src/managers/ShaderManager.d.ts +55 -0
  73. package/dist/types/src/managers/TextureManager.d.ts +102 -0
  74. package/dist/types/src/particlesystem/Particle.d.ts +64 -0
  75. package/dist/types/{particlesystem → src/particlesystem}/ParticleSettings.d.ts +32 -24
  76. package/dist/types/{particlesystem → src/particlesystem}/Particles.d.ts +20 -12
  77. package/dist/types/src/physics/AABB.d.ts +92 -0
  78. package/dist/types/src/physics/Body.d.ts +435 -0
  79. package/dist/types/src/physics/BodyType.d.ts +6 -0
  80. package/dist/types/src/physics/BroadPhase.d.ts +210 -0
  81. package/dist/types/src/physics/Collision.d.ts +102 -0
  82. package/dist/types/src/physics/Contact.d.ts +206 -0
  83. package/dist/types/src/physics/ContactSolver.d.ts +108 -0
  84. package/dist/types/src/physics/Distance.d.ts +54 -0
  85. package/dist/types/src/physics/DistanceJoint.d.ts +90 -0
  86. package/dist/types/src/physics/Fixture.d.ts +221 -0
  87. package/dist/types/src/physics/Island.d.ts +52 -0
  88. package/dist/types/src/physics/Joint.d.ts +59 -0
  89. package/dist/types/src/physics/Math2D.d.ts +371 -0
  90. package/dist/types/src/physics/RevoluteJoint.d.ts +119 -0
  91. package/dist/types/src/physics/Settings.d.ts +22 -0
  92. package/dist/types/src/physics/Shapes.d.ts +207 -0
  93. package/dist/types/src/physics/TimeOfImpact.d.ts +22 -0
  94. package/dist/types/src/physics/World.d.ts +274 -0
  95. package/dist/types/src/physics/index.d.ts +34 -0
  96. package/index.js +78 -0
  97. package/package.json +73 -60
  98. package/src/Animator.js +95 -0
  99. package/src/BitmapText.js +6 -5
  100. package/src/Camera.js +183 -0
  101. package/src/CameraController.js +192 -0
  102. package/src/CanvasText.js +281 -0
  103. package/src/CollisionLayers.js +86 -0
  104. package/src/Color.js +26 -18
  105. package/src/Coroutine.js +259 -0
  106. package/src/DebugOverlay.js +246 -0
  107. package/src/Drawable.js +842 -582
  108. package/src/Easing.js +57 -0
  109. package/src/Emerald.js +1150 -459
  110. package/src/EmeraldDB.js +328 -0
  111. package/src/FPSCounter.js +43 -43
  112. package/src/GLUtils.js +60 -67
  113. package/src/Instance.js +41 -5
  114. package/src/InstancedTexture.js +308 -127
  115. package/src/Interpolator.js +124 -0
  116. package/src/Material.js +202 -0
  117. package/src/MathUtils.js +134 -0
  118. package/src/ParticleEmitter.js +284 -0
  119. package/src/Physics.js +431 -40
  120. package/src/Pool.js +85 -0
  121. package/src/PostEffects.js +296 -0
  122. package/src/PostProcessor.js +304 -0
  123. package/src/RenderTarget.js +134 -0
  124. package/src/Scene.js +115 -83
  125. package/src/ScreenEffects.js +266 -0
  126. package/src/Serializer.js +131 -0
  127. package/src/Shaders.js +150 -165
  128. package/src/Shapes.js +118 -129
  129. package/src/SpatialGrid.js +111 -0
  130. package/src/SpriteBatch.js +299 -0
  131. package/src/StateMachine.js +82 -0
  132. package/src/Storage.js +175 -47
  133. package/src/Texture.js +58 -67
  134. package/src/TextureAtlas.js +96 -0
  135. package/src/Tilemap.js +274 -0
  136. package/src/Time.js +51 -6
  137. package/src/Timer.js +99 -0
  138. package/src/Transform.js +100 -7
  139. package/src/Tween.js +160 -0
  140. package/src/UI.js +394 -0
  141. package/src/components/Behaviour.js +90 -0
  142. package/src/components/BoxCollider.js +29 -12
  143. package/src/components/BoxColliderDebug.js +3 -4
  144. package/src/components/CircleCollider.js +26 -12
  145. package/src/components/CircleColliderDebug.js +25 -24
  146. package/src/components/Collider.js +150 -34
  147. package/src/components/GameObject.js +130 -21
  148. package/src/components/PolygonCollider.js +55 -0
  149. package/src/components/RigidBody.js +556 -8
  150. package/src/importers/Aseprite.js +142 -0
  151. package/src/importers/ForgeLevel.js +581 -0
  152. package/src/importers/TiledMap.js +158 -0
  153. package/src/lights/DirectionalLight.js +6 -15
  154. package/src/lights/PointLight.js +4 -4
  155. package/src/managers/AssetManager.js +239 -0
  156. package/src/managers/AudioManager.js +565 -146
  157. package/src/managers/EventManager.js +488 -477
  158. package/src/managers/GLManager.js +57 -0
  159. package/src/managers/GLState.js +70 -0
  160. package/src/managers/Gamepad.js +126 -0
  161. package/src/managers/IDManager.js +24 -2
  162. package/src/managers/InputManager.js +905 -0
  163. package/src/managers/NetworkManager.js +178 -0
  164. package/src/managers/RenderStats.js +34 -0
  165. package/src/managers/SceneManager.js +30 -0
  166. package/src/managers/ShaderManager.js +0 -2
  167. package/src/managers/TextureManager.js +218 -0
  168. package/src/particlesystem/Particle.js +82 -7
  169. package/src/particlesystem/ParticleSettings.js +21 -3
  170. package/src/particlesystem/Particles.js +80 -31
  171. package/src/physics/AABB.js +207 -0
  172. package/src/physics/Body.js +862 -0
  173. package/src/physics/BodyType.js +16 -0
  174. package/src/physics/BroadPhase.js +641 -0
  175. package/src/physics/Collision.js +534 -0
  176. package/src/physics/Contact.js +500 -0
  177. package/src/physics/ContactSolver.js +526 -0
  178. package/src/physics/Distance.js +403 -0
  179. package/src/physics/DistanceJoint.js +227 -0
  180. package/src/physics/Fixture.js +346 -0
  181. package/src/physics/Island.js +203 -0
  182. package/src/physics/Joint.js +78 -0
  183. package/src/physics/Math2D.js +573 -0
  184. package/src/physics/RevoluteJoint.js +278 -0
  185. package/src/physics/Settings.js +78 -0
  186. package/src/physics/Shapes.js +549 -0
  187. package/src/physics/TimeOfImpact.js +87 -0
  188. package/src/physics/World.js +731 -0
  189. package/src/physics/index.js +79 -0
  190. package/dist/types/Drawable.d.ts +0 -157
  191. package/dist/types/Emerald.d.ts +0 -73
  192. package/dist/types/GLUtils.d.ts +0 -6
  193. package/dist/types/Physics.d.ts +0 -139
  194. package/dist/types/Scene.d.ts +0 -39
  195. package/dist/types/Shaders.d.ts +0 -4
  196. package/dist/types/Storage.d.ts +0 -46
  197. package/dist/types/Time.d.ts +0 -22
  198. package/dist/types/Transform.d.ts +0 -41
  199. package/dist/types/components/BoxColliderDebug.d.ts +0 -19
  200. package/dist/types/components/CircleColliderDebug.d.ts +0 -19
  201. package/dist/types/components/Collider.d.ts +0 -53
  202. package/dist/types/components/GameObject.d.ts +0 -72
  203. package/dist/types/components/RigidBody.d.ts +0 -104
  204. package/dist/types/managers/AudioManager.d.ts +0 -60
  205. package/dist/types/managers/GLManager.d.ts +0 -47
  206. package/dist/types/managers/IDManager.d.ts +0 -21
  207. package/dist/types/managers/SceneManager.d.ts +0 -22
  208. package/dist/types/particlesystem/Particle.d.ts +0 -42
package/index.js CHANGED
@@ -9,9 +9,42 @@ import { Physics, Vector2, Vector3 } from "./src/Physics.js";
9
9
  import Scene from "./src/Scene.js";
10
10
  import { Square2D, Triangle2D, Circle2D } from "./src/Shapes.js";
11
11
  import Storage from "./src/Storage.js";
12
+ import EmeraldDB from "./src/EmeraldDB.js";
12
13
  import Texture from "./src/Texture.js";
13
14
  import Time from "./src/Time.js";
14
15
  import Transform from "./src/Transform.js";
16
+ import MathUtils from "./src/MathUtils.js";
17
+ import Pool from "./src/Pool.js";
18
+ import Animator from "./src/Animator.js";
19
+ import Tilemap from "./src/Tilemap.js";
20
+ import CameraController from "./src/CameraController.js";
21
+ import Camera from "./src/Camera.js";
22
+ import Easing from "./src/Easing.js";
23
+ import Tween from "./src/Tween.js";
24
+ import Timer from "./src/Timer.js";
25
+ import StateMachine from "./src/StateMachine.js";
26
+ import SpatialGrid from "./src/SpatialGrid.js";
27
+ import TextureAtlas from "./src/TextureAtlas.js";
28
+ import CanvasText from "./src/CanvasText.js";
29
+ import DebugOverlay from "./src/DebugOverlay.js";
30
+ import Serializer from "./src/Serializer.js";
31
+ import Coroutine from "./src/Coroutine.js";
32
+ import Interpolator from "./src/Interpolator.js";
33
+ import ScreenEffects from "./src/ScreenEffects.js";
34
+ import SpriteBatch from "./src/SpriteBatch.js";
35
+ import ParticleEmitter from "./src/ParticleEmitter.js";
36
+ import CollisionLayers from "./src/CollisionLayers.js";
37
+ import TiledMap from "./src/importers/TiledMap.js";
38
+ import Aseprite from "./src/importers/Aseprite.js";
39
+ import ForgeLevel from "./src/importers/ForgeLevel.js";
40
+ import RenderTarget from "./src/RenderTarget.js";
41
+ import RenderStats from "./src/managers/RenderStats.js";
42
+ import PostProcessor, { PostEffect } from "./src/PostProcessor.js";
43
+ import PostEffects, { BloomEffect } from "./src/PostEffects.js";
44
+ import Material from "./src/Material.js";
45
+ import UI from "./src/UI.js";
46
+ import InputManager from "./src/managers/InputManager.js";
47
+ import Gamepad from "./src/managers/Gamepad.js";
15
48
  import Particle from "./src/particlesystem/Particle.js";
16
49
  import Particles from "./src/particlesystem/Particles.js";
17
50
  import ParticleSettings from "./src/particlesystem/ParticleSettings.js";
@@ -19,15 +52,20 @@ import AudioManager from "./src/managers/AudioManager.js";
19
52
  import CameraManager from "./src/managers/CameraManager.js";
20
53
  import EventManager from "./src/managers/EventManager.js";
21
54
  import SceneManager from "./src/managers/SceneManager.js";
55
+ import TextureManager from "./src/managers/TextureManager.js";
56
+ import AssetManager from "./src/managers/AssetManager.js";
57
+ import NetworkManager from "./src/managers/NetworkManager.js";
22
58
  import DirectionalLight from "./src/lights/DirectionalLight.js";
23
59
  import PointLight from "./src/lights/PointLight.js";
24
60
  import BoxCollider from "./src/components/BoxCollider.js";
25
61
  import BoxColliderDebug from "./src/components/BoxColliderDebug.js";
26
62
  import CircleCollider from "./src/components/CircleCollider.js";
27
63
  import CircleColliderDebug from "./src/components/CircleColliderDebug.js";
64
+ import PolygonCollider from "./src/components/PolygonCollider.js";
28
65
  import Collider from "./src/components/Collider.js";
29
66
  import GameObject from "./src/components/GameObject.js";
30
67
  import RigidBody from "./src/components/RigidBody.js";
68
+ import Behaviour from "./src/components/Behaviour.js";
31
69
 
32
70
  export {
33
71
  Emerald,
@@ -45,9 +83,44 @@ export {
45
83
  Triangle2D,
46
84
  Circle2D,
47
85
  Storage,
86
+ EmeraldDB,
48
87
  Texture,
49
88
  Time,
50
89
  Transform,
90
+ MathUtils,
91
+ Pool,
92
+ Animator,
93
+ Tilemap,
94
+ CameraController,
95
+ Camera,
96
+ Easing,
97
+ Tween,
98
+ Timer,
99
+ StateMachine,
100
+ SpatialGrid,
101
+ TextureAtlas,
102
+ CanvasText,
103
+ DebugOverlay,
104
+ Serializer,
105
+ Coroutine,
106
+ Interpolator,
107
+ ScreenEffects,
108
+ SpriteBatch,
109
+ ParticleEmitter,
110
+ CollisionLayers,
111
+ TiledMap,
112
+ Aseprite,
113
+ ForgeLevel,
114
+ RenderTarget,
115
+ RenderStats,
116
+ PostProcessor,
117
+ PostEffect,
118
+ PostEffects,
119
+ BloomEffect,
120
+ Material,
121
+ UI,
122
+ InputManager,
123
+ Gamepad,
51
124
  Particle,
52
125
  Particles,
53
126
  ParticleSettings,
@@ -55,13 +128,18 @@ export {
55
128
  CameraManager,
56
129
  EventManager,
57
130
  SceneManager,
131
+ TextureManager,
132
+ AssetManager,
133
+ NetworkManager,
58
134
  DirectionalLight,
59
135
  PointLight,
60
136
  BoxCollider,
61
137
  BoxColliderDebug,
62
138
  CircleCollider,
63
139
  CircleColliderDebug,
140
+ PolygonCollider,
64
141
  Collider,
65
142
  GameObject,
66
143
  RigidBody,
144
+ Behaviour,
67
145
  };
package/package.json CHANGED
@@ -1,62 +1,75 @@
1
1
  {
2
- "name": "emeraldengine",
3
- "version": "2.2.1",
4
- "description": "2D graphics library for Web",
5
- "type": "module",
6
- "main": "index.js",
7
- "module": "index.js",
8
- "types": "dist/types/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/types/index.d.ts",
12
- "import": "./index.js",
13
- "default": "./index.js"
14
- }
15
- },
16
- "files": [
17
- "index.js",
18
- "src",
19
- "dist/types"
20
- ],
21
- "sideEffects": false,
22
- "engines": {
23
- "node": ">=12.0.0"
24
- },
25
- "keywords": [
26
- "2D",
27
- "graphics",
28
- "game",
29
- "engine",
30
- "webgl",
31
- "webgl2",
32
- "canvas",
33
- "gamedev",
34
- "rendering",
35
- "sprite",
36
- "particle-system",
37
- "physics"
38
- ],
39
- "dependencies": {
40
- "gl-matrix": "^3.4.3",
41
- "planck": "^1.4.2"
42
- },
43
- "peerDependencies": {
44
- "colyseus.js": "^0.16.16"
45
- },
46
- "peerDependenciesMeta": {
47
- "colyseus.js": {
48
- "optional": true
49
- }
50
- },
51
- "author": "vahan-gev",
52
- "license": "MIT",
53
- "homepage": "https://github.com/vahan-gev/emeraldengine#readme",
54
- "bugs": {
55
- "url": "https://github.com/vahan-gev/emeraldengine/issues"
56
- },
57
- "repository": {
58
- "type": "git",
59
- "url": "git+https://github.com/vahan-gev/emeraldengine.git"
60
- },
61
- "devDependencies": {}
2
+ "name": "emeraldengine",
3
+ "version": "3.1.0",
4
+ "description": "2D graphics library for Web",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "module": "index.js",
8
+ "types": "dist/types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/types/index.d.ts",
12
+ "import": "./index.js",
13
+ "default": "./index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "index.js",
18
+ "src",
19
+ "dist/types"
20
+ ],
21
+ "sideEffects": false,
22
+ "engines": {
23
+ "node": ">=12.0.0"
24
+ },
25
+ "keywords": [
26
+ "2D",
27
+ "graphics",
28
+ "game",
29
+ "engine",
30
+ "webgl",
31
+ "webgl2",
32
+ "canvas",
33
+ "gamedev",
34
+ "rendering",
35
+ "sprite",
36
+ "particle-system",
37
+ "physics"
38
+ ],
39
+ "dependencies": {
40
+ "gl-matrix": "^3.4.3"
41
+ },
42
+ "peerDependencies": {
43
+ "colyseus.js": "^0.16.16"
44
+ },
45
+ "peerDependenciesMeta": {
46
+ "colyseus.js": {
47
+ "optional": true
48
+ }
49
+ },
50
+ "author": "vahan-gev",
51
+ "license": "MIT",
52
+ "homepage": "https://github.com/vahan-gev/emeraldengine#readme",
53
+ "bugs": {
54
+ "url": "https://github.com/vahan-gev/emeraldengine/issues"
55
+ },
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "git+https://github.com/vahan-gev/emeraldengine.git"
59
+ },
60
+ "scripts": {
61
+ "test": "node --test test/*.test.mjs",
62
+ "types": "tsc -p tsconfig.json",
63
+ "prepublishOnly": "npm run types && npm test",
64
+ "format": "prettier --write \"src/**/*.js\" \"test/**/*.mjs\" index.js",
65
+ "format:check": "prettier --check \"src/**/*.js\" index.js"
66
+ },
67
+ "devDependencies": {
68
+ "@colyseus/schema": "^3.0.76",
69
+ "colyseus": "^0.16.5",
70
+ "colyseus.js": "^0.16.22",
71
+ "prettier": "^3.3.0",
72
+ "typescript": "^5.9.3",
73
+ "vite": "^5.4.0"
74
+ }
62
75
  }
@@ -0,0 +1,95 @@
1
+ import Behaviour from "./components/Behaviour.js";
2
+ import Drawable from "./Drawable.js";
3
+
4
+ /**
5
+ * @class Animator
6
+ * @description A component that manages named animation clips for a Texture (or
7
+ * any Drawable) on the same GameObject. Register clips once, then switch between
8
+ * them by name, handy for character states like idle/run/jump.
9
+ *
10
+ * @example
11
+ * const anim = new Animator();
12
+ * anim.addClip("idle", [0, 1, 2, 3], { speed: 150 });
13
+ * anim.addClip("jump", [8, 9], { speed: 100, loop: false });
14
+ * obj.addComponent(texture);
15
+ * obj.addComponent(anim);
16
+ * anim.play("idle");
17
+ */
18
+ class Animator extends Behaviour {
19
+ constructor() {
20
+ super();
21
+ this.clips = new Map();
22
+ this.current = null;
23
+ this.drawable = null;
24
+ }
25
+
26
+ /**
27
+ * @method addClip
28
+ * @description Registers a named clip.
29
+ * @param {string} name - The clip name
30
+ * @param {number[]} frames - Frame indices to play
31
+ * @param {Object} [options] - { speed = 100, loop = true }
32
+ * @returns {Animator} - this
33
+ */
34
+ addClip(name, frames, options = {}) {
35
+ const { speed = 100, loop = true } = options;
36
+ this.clips.set(name, { frames, speed, loop });
37
+ return this;
38
+ }
39
+
40
+ start() {
41
+ this._resolveDrawable();
42
+ }
43
+
44
+ /** @private */
45
+ _resolveDrawable() {
46
+ if (!this.drawable && this.gameObject && this.gameObject.getComponent) {
47
+ this.drawable = this.gameObject.getComponent(Drawable);
48
+ }
49
+ return this.drawable;
50
+ }
51
+
52
+ /**
53
+ * @method play
54
+ * @description Plays a registered clip. No-op if it's already current.
55
+ * @param {string} name - The clip name
56
+ * @returns {Animator} - this
57
+ */
58
+ play(name) {
59
+ if (this.current === name) return this;
60
+ const clip = this.clips.get(name);
61
+ const drawable = this._resolveDrawable();
62
+ if (!clip || !drawable) return this;
63
+
64
+ this.current = name;
65
+ if (clip.loop) {
66
+ drawable.playAnimation(clip.frames, clip.speed);
67
+ } else {
68
+ drawable.playAnimationOnce(clip.frames, null, clip.speed, () => {
69
+ if (this.current === name) this.current = null;
70
+ });
71
+ }
72
+ return this;
73
+ }
74
+
75
+ /**
76
+ * @method stop
77
+ * @description Stops the current animation.
78
+ */
79
+ stop() {
80
+ const drawable = this._resolveDrawable();
81
+ if (drawable) drawable.stopAnimation();
82
+ this.current = null;
83
+ }
84
+
85
+ /**
86
+ * @method getCurrent
87
+ * @description Returns the name of the currently playing clip (or null).
88
+ * @returns {string|null}
89
+ */
90
+ getCurrent() {
91
+ return this.current;
92
+ }
93
+ }
94
+
95
+ export default Animator;
package/src/BitmapText.js CHANGED
@@ -35,7 +35,7 @@ class BitmapText {
35
35
  color,
36
36
  position,
37
37
  rotation,
38
- useLighting = false // Default to false for text as it's typically UI
38
+ useLighting = false
39
39
  ) {
40
40
  this.text = text;
41
41
  this.texturePath = texturePath;
@@ -61,7 +61,6 @@ class BitmapText {
61
61
  for (let i = 0; i < letters.length; i++) {
62
62
  this.letterDictionary[letters[i]] = i;
63
63
  }
64
- // Initialize the bitmap font texture
65
64
  this.texture = new InstancedTexture(
66
65
  this.texturePath,
67
66
  text.length,
@@ -75,14 +74,14 @@ class BitmapText {
75
74
  this.useLighting
76
75
  );
77
76
 
78
- // Apply the color to the texture if provided
79
77
  if (this.color) {
80
78
  this.texture.setColor(this.color);
81
79
  }
82
80
 
83
- // Apply the lighting setting to the texture
84
81
  this.texture.setUseLighting(this.useLighting);
85
82
 
83
+ this.texture.setStatic(true);
84
+
86
85
  this.gameObject.addComponent(this.texture);
87
86
  for (let i = 0; i < text.length; i++) {
88
87
  const letter = text[i];
@@ -163,7 +162,6 @@ class BitmapText {
163
162
  * @param {Vector3} position - The position to set
164
163
  */
165
164
  setPosition(position) {
166
- // Vector3
167
165
  this.position = position;
168
166
  this.gameObject.transform.position = position;
169
167
 
@@ -184,6 +182,7 @@ class BitmapText {
184
182
  instanceIndex++;
185
183
  }
186
184
  }
185
+ this.texture.markDirty();
187
186
  }
188
187
 
189
188
  /**
@@ -212,6 +211,7 @@ class BitmapText {
212
211
  instanceIndex++;
213
212
  }
214
213
  }
214
+ this.texture.markDirty();
215
215
  }
216
216
 
217
217
  /**
@@ -239,6 +239,7 @@ class BitmapText {
239
239
  instanceIndex++;
240
240
  }
241
241
  }
242
+ this.texture.markDirty();
242
243
  }
243
244
  }
244
245
 
package/src/Camera.js ADDED
@@ -0,0 +1,183 @@
1
+ import Transform from "./Transform.js";
2
+ import { Vector2, Vector3 } from "./Physics.js";
3
+
4
+ /**
5
+ * @class Camera
6
+ * @description A view into the scene with its own transform (position, zoom,
7
+ * rotation) and a viewport rectangle. Multiple cameras can be added to an
8
+ * Emerald instance to render split-screen or picture-in-picture. The viewport
9
+ * is expressed in normalized [0..1] coordinates with the origin at the
10
+ * bottom-left of the canvas (matching WebGL).
11
+ *
12
+ * Backward compatible with the previous inline camera: position is stored
13
+ * negated internally, and setPosition/getPosition/setZoom/getZoom behave the
14
+ * same, so EventManager and CameraController are unaffected.
15
+ *
16
+ * @example
17
+ * const left = new Camera({ viewport: { x: 0, y: 0, width: 0.5, height: 1 } });
18
+ * const right = new Camera({ viewport: { x: 0.5, y: 0, width: 0.5, height: 1 } });
19
+ * emerald.setCameras([left, right]);
20
+ */
21
+ class Camera {
22
+ constructor(options = {}) {
23
+ this.transform = new Transform(new Vector3(0, 0, 0), 0, new Vector2(1, 1));
24
+
25
+ const vp = options.viewport || {};
26
+ this.viewport = {
27
+ x: vp.x ?? 0,
28
+ y: vp.y ?? 0,
29
+ width: vp.width ?? 1,
30
+ height: vp.height ?? 1,
31
+ };
32
+
33
+ this.active = options.active !== false;
34
+ this.clearColor = options.clearColor || null;
35
+
36
+ this.ignoreLayers = new Set(options.ignoreLayers || []);
37
+
38
+ this.onlyLayers = options.onlyLayers ? new Set(options.onlyLayers) : null;
39
+
40
+ this.excludeFromPost = options.excludeFromPost === true;
41
+
42
+ this.pixelSnap = options.pixelSnap === true;
43
+ }
44
+
45
+ /**
46
+ * @method setPixelSnap
47
+ * @description When true, the camera's rendered position is rounded to whole
48
+ * screen pixels each frame (the stored position stays smooth). Use it for
49
+ * pixel-art games to eliminate sub-pixel shimmer and tile seams while a
50
+ * smooth-follow camera moves. Ignored while the camera is rotated.
51
+ * @param {boolean} snap
52
+ * @returns {Camera} - this
53
+ */
54
+ setPixelSnap(snap) {
55
+ this.pixelSnap = snap !== false;
56
+ return this;
57
+ }
58
+
59
+ /**
60
+ * @method setExcludeFromPost
61
+ * @description When true, this camera renders straight to the screen AFTER the
62
+ * post-processing pass instead of into the post-processed scene buffer. Use it
63
+ * for HUD/UI cameras so effects like bloom don't affect the interface.
64
+ * @param {boolean} exclude
65
+ * @returns {Camera} - this
66
+ */
67
+ setExcludeFromPost(exclude) {
68
+ this.excludeFromPost = exclude !== false;
69
+ return this;
70
+ }
71
+
72
+ /**
73
+ * @method setOnlyLayers
74
+ * @description Restricts the camera to rendering only the given layers (or
75
+ * pass null to clear the restriction).
76
+ * @param {number[]|null} layers
77
+ * @returns {Camera} - this
78
+ */
79
+ setOnlyLayers(layers) {
80
+ this.onlyLayers = layers ? new Set(layers) : null;
81
+ return this;
82
+ }
83
+
84
+ /**
85
+ * @method setIgnoreLayers
86
+ * @description Replaces the set of layers this camera skips when rendering.
87
+ * @param {number[]} layers - Layer indices to ignore
88
+ * @returns {Camera} - this
89
+ */
90
+ setIgnoreLayers(layers) {
91
+ this.ignoreLayers = new Set(layers);
92
+ return this;
93
+ }
94
+
95
+ /**
96
+ * @method ignoreLayer
97
+ * @description Adds a single layer to the ignore set.
98
+ * @param {number} layer
99
+ * @returns {Camera} - this
100
+ */
101
+ ignoreLayer(layer) {
102
+ this.ignoreLayers.add(layer);
103
+ return this;
104
+ }
105
+
106
+ /**
107
+ * @method setPosition
108
+ * @description Sets the world-space center of the camera.
109
+ */
110
+ setPosition(x, y, z = 0) {
111
+ this.transform.position.x = -x;
112
+ this.transform.position.y = -y;
113
+ this.transform.position.z = -z;
114
+ }
115
+
116
+ /**
117
+ * @method getPosition
118
+ * @description Returns the world-space center of the camera.
119
+ */
120
+ getPosition() {
121
+ return {
122
+ x: -this.transform.position.x,
123
+ y: -this.transform.position.y,
124
+ z: -this.transform.position.z,
125
+ };
126
+ }
127
+
128
+ /**
129
+ * @method setZoom
130
+ * @description Sets the zoom (1 = default, >1 zooms in).
131
+ */
132
+ setZoom(zoom) {
133
+ const z = Math.max(0.0001, zoom);
134
+ this.transform.scale.x = z;
135
+ this.transform.scale.y = z;
136
+ }
137
+
138
+ /**
139
+ * @method getZoom
140
+ * @returns {number}
141
+ */
142
+ getZoom() {
143
+ return this.transform.scale.x;
144
+ }
145
+
146
+ /**
147
+ * @method setRotation
148
+ * @description Sets the camera rotation in radians.
149
+ */
150
+ setRotation(radians) {
151
+ this.transform.rotation = radians;
152
+ }
153
+
154
+ /**
155
+ * @method getRotation
156
+ * @returns {number}
157
+ */
158
+ getRotation() {
159
+ return this.transform.rotation;
160
+ }
161
+
162
+ /**
163
+ * @method setViewport
164
+ * @description Sets the normalized viewport rectangle (origin bottom-left).
165
+ * @returns {Camera} - this
166
+ */
167
+ setViewport(x, y, width, height) {
168
+ this.viewport = { x, y, width, height };
169
+ return this;
170
+ }
171
+
172
+ /**
173
+ * @method setActive
174
+ * @description Enables/disables rendering of this camera.
175
+ * @returns {Camera} - this
176
+ */
177
+ setActive(active) {
178
+ this.active = active;
179
+ return this;
180
+ }
181
+ }
182
+
183
+ export default Camera;