kaplay 3001.0.9 → 3001.0.12

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 (55) hide show
  1. package/CHANGELOG.md +2 -1682
  2. package/README.md +3 -3
  3. package/dist/declaration/app/app.d.ts.map +1 -1
  4. package/dist/declaration/app/index.d.ts +3 -3
  5. package/dist/declaration/assets/asset.d.ts +1 -1
  6. package/dist/declaration/assets/asset.d.ts.map +1 -1
  7. package/dist/declaration/assets/sprite.d.ts +12 -2
  8. package/dist/declaration/assets/sprite.d.ts.map +1 -1
  9. package/dist/declaration/components/draw/shader.d.ts +6 -0
  10. package/dist/declaration/components/draw/shader.d.ts.map +1 -1
  11. package/dist/declaration/components/draw/sprite.d.ts.map +1 -1
  12. package/dist/declaration/components/misc/animate.d.ts.map +1 -1
  13. package/dist/declaration/components/physics/area.d.ts +4 -4
  14. package/dist/declaration/components/physics/area.d.ts.map +1 -1
  15. package/dist/declaration/components/physics/effectors.d.ts.map +1 -1
  16. package/dist/declaration/components/physics/index.d.ts +4 -4
  17. package/dist/declaration/components/transform/follow.d.ts +6 -0
  18. package/dist/declaration/components/transform/follow.d.ts.map +1 -1
  19. package/dist/declaration/components/transform/pos.d.ts +13 -4
  20. package/dist/declaration/components/transform/pos.d.ts.map +1 -1
  21. package/dist/declaration/gfx/draw/drawDebug.d.ts.map +1 -1
  22. package/dist/declaration/gfx/gfxApp.d.ts +1 -0
  23. package/dist/declaration/gfx/gfxApp.d.ts.map +1 -1
  24. package/dist/declaration/gfx/stack.d.ts +0 -1
  25. package/dist/declaration/gfx/stack.d.ts.map +1 -1
  26. package/dist/declaration/gfx/texPacker.d.ts +2 -1
  27. package/dist/declaration/gfx/texPacker.d.ts.map +1 -1
  28. package/dist/declaration/gfx/viewport.d.ts +3 -0
  29. package/dist/declaration/gfx/viewport.d.ts.map +1 -1
  30. package/dist/declaration/index.d.ts +78 -10
  31. package/dist/declaration/index.d.ts.map +1 -1
  32. package/dist/declaration/kaplay.d.ts +1 -0
  33. package/dist/declaration/kaplay.d.ts.map +1 -1
  34. package/dist/declaration/math/clamp.d.ts +2 -0
  35. package/dist/declaration/math/clamp.d.ts.map +1 -0
  36. package/dist/declaration/math/color.d.ts.map +1 -1
  37. package/dist/declaration/math/math.d.ts +0 -1
  38. package/dist/declaration/math/math.d.ts.map +1 -1
  39. package/dist/declaration/types.d.ts +55 -25
  40. package/dist/declaration/types.d.ts.map +1 -1
  41. package/dist/doc.d.ts +301 -426
  42. package/dist/kaboom.cjs +5 -5
  43. package/dist/kaboom.cjs.map +4 -4
  44. package/dist/kaboom.js +5 -5
  45. package/dist/kaboom.js.map +4 -4
  46. package/dist/kaboom.mjs +5 -5
  47. package/dist/kaboom.mjs.map +4 -4
  48. package/dist/kaplay.cjs +5 -5
  49. package/dist/kaplay.cjs.map +4 -4
  50. package/dist/kaplay.js +5 -5
  51. package/dist/kaplay.js.map +4 -4
  52. package/dist/kaplay.mjs +5 -5
  53. package/dist/kaplay.mjs.map +4 -4
  54. package/kaplay.webp +0 -0
  55. package/package.json +15 -10
package/CHANGELOG.md CHANGED
@@ -1,1684 +1,4 @@
1
1
  # Changelog
2
2
 
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is (mostly) based on
6
- [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
7
- adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
-
9
- ## [3001.0.9] - 2025-01-15
10
-
11
- ### Added
12
-
13
- - Added new option in `LoadSpriteOpt` for loading sprites in an individual
14
- spritesheet - @chqs-git
15
- ```js
16
- loadSprite(
17
- "player",
18
- "sprites/player.png",
19
- {
20
- singular: true,
21
- },
22
- );
23
- ```
24
- - **(examples)** Added a new `particle` example! - @lajbel
25
-
26
- ### Changed
27
-
28
- - Improved `lifespan()` explanation - @lajbel
29
- - **(examples)** `particle` example renamed to `lifespan` - @lajbel
30
-
31
- ### Fixed
32
-
33
- - Fixed a bug where `lifespan()` was working incorrectly - @lajbel
34
-
35
- ## [3001.0.8] - 2025-01-15
36
-
37
- ### Fixed
38
-
39
- - Fixed a bug where alpha channel wasn't correctly setted - @mflerackers
40
-
41
- ## [3001.0.7] - 2025-01-15
42
-
43
- ### Added
44
-
45
- - Added `kaplay({ spriteAtlasPadding })` for setting the space between the
46
- sprites in the sprite atlas - @marianyp
47
-
48
- ```js
49
- kaplay({
50
- spriteAtlasPadding: 10, // 10 pixels of space between each sprite
51
- });
52
- ```
53
-
54
- ### Changed
55
-
56
- - Now you cannot pass parameters that are not a component or string to `.use()`.
57
- Otherwise it will throw an error - @lajbel
58
-
59
- ### Fixed
60
-
61
- - Fixed a bug where font atlas were working strange - @mflerackers
62
-
63
- ## [3001.0.6] "Santa Events" - 2024-12-27
64
-
65
- ### Added
66
-
67
- - Added `trigger(event, tag, ...args)` for global triggering events on a
68
- specific tag (**experimental**) - @lajbel
69
-
70
- ```js
71
- trigger("shoot", "target", 140);
72
-
73
- on("shoot", "target", (obj, score) => {
74
- obj.destroy();
75
- debug.log(140); // every bomb was 140 score points!
76
- });
77
- ```
78
-
79
- - Added `{ override?: true }` in `CharTransform` for overridding text styles -
80
- @dragoncoder047
81
-
82
- ```js
83
- add([
84
- pos(100, 150),
85
- text("With override: Hello [foo]styled[/foo] text", {
86
- transform: {
87
- color: BLACK, // Default text color for every character
88
- },
89
- styles: {
90
- foo: {
91
- color: RED, // [foo] will be red
92
- override: true, // will override the black def color
93
- },
94
- },
95
- }),
96
- ]);
97
- ```
98
-
99
- - Added `{ indentAll?: boolean }` in `TextCompOpt` to indent every new line -
100
- @dragoncoder047
101
-
102
- - Added TypeScript definition for all App Events and missing Game Object
103
- Events - @lajbel
104
-
105
- ### Fixed
106
-
107
- - Fixed an incorrect mention to the component in `TextInputComp` type -
108
- @dragoncoder047
109
-
110
- ## [3001.0.5] - 2024-12-18
111
-
112
- ### Added
113
-
114
- - Added tags and components separation in `KAPLAYOpt.tagsAsComponents`
115
- (**experimental**)
116
- - Added `.is()`, `.tag()` and `.untag()` to `GameObjRaw`, check, add and remove
117
- (**experimental**)
118
- - Added `.has()` to `GameObjRaw`, to check if a game object has a component tags
119
- (**experimental**)
120
- - Added events for listen to comps being removed or added `onUse()` and
121
- `onUnused()` (**experimental**)
122
- - Added `k.cancel()` to cancel the current event (**experimental**)
123
- - ```js
124
- onKeyPress("space", () => {
125
- // do something
126
- // cancel the event
127
- return cancel();
128
- });
129
- ```
130
- - Added `getDefaultLayer()` to get the default layer (**experimental**)
131
- - Added `getLayers()` to get the layers list (**experimental**)
132
- - Added many JSDoc specifiers on many functions (@require, @deprecated, @since,
133
- @group, etc)
134
-
135
- ### Changed
136
-
137
- - Added `.use()`, `.unuse()` and `.has()` to `GameObjRaw`, to add, remove and
138
- check components. This only works with `KAPLAYOpt.tagsAsComponents` set to
139
- `true` (**experimental**)
140
-
141
- ### Deprecated
142
-
143
- - Deprecated camera methods `camScale()`, `camPos()` and `camRot()` in favor of
144
- `setCamScale()`, `getCamScale()`, `setCamPos()`, `getCamPos()`, `setCamRot()`
145
- and `getCamRot`.
146
- - Deprecated `camTransform()` in favor of `getCamTransform()`.
147
- - Deprecated `camFlash()` in favor of `flash()`, for a `shake()`-like name.
148
-
149
- ### Fixed
150
-
151
- - Fixed artifacts present in some TrueType fonts.
152
- - Fixed `.use()` and `.unuse()` with area components.
153
-
154
- ## [3001.0.0] "Spooky Beans!" - 2024-10-31
155
-
156
- ### Input
157
-
158
- - Added input bindings, `onButtonPress`, `onButtonRelease`, `onButtonDown`, and
159
- it's corresponding boolean versions, `isButtonPressed`, `isButtonDown` and
160
- `isButtonReleased`.
161
-
162
- ```js
163
- kaplay({
164
- // bind your buttons
165
- buttons: {
166
- jump: {
167
- keyboard: ["space", "up"],
168
- keyboardCode: "Space", // you can also use key codes
169
- gamepad: ["south"],
170
- },
171
- },
172
- });
173
-
174
- onButtonPress("jump", () => {
175
- player.jump();
176
- });
177
- ```
178
-
179
- - added `getButton(btn)` and `setButton(btn)` to get and set button bindings
180
-
181
- ```js
182
- // ["space", "up"]
183
- debug.log(getButton("jump").keyboard);
184
-
185
- // change the jump button in keyboard to "w"
186
- setButton("jump", {
187
- keyboard: ["w"],
188
- // gamepad binding is not changed
189
- });
190
- ```
191
-
192
- - added `getLastInputDeviceType()` to get what was the last pressed device
193
-
194
- ```js
195
- onButtonPress(() => {
196
- const lastInputDevice = getLastInputDeviceType(); // keyboard, mouse or gamepad
197
- // change icons, etc
198
- });
199
- ```
200
-
201
- - added `pressButton(btn)` and `releaseButton(btn)` to simulate button press and
202
- release
203
-
204
- ```js
205
- pressButton("jump"); // triggers onButtonPress and starts onButtonDown
206
- releaseButton("jump"); // triggers onButtonRelease and stops onButtonDown
207
- ```
208
-
209
- - added the possibility of use arrays in all input handlers
210
-
211
- ```js
212
- onKeyPress(["w", "up"], () => {
213
- player.jump();
214
- });
215
- ```
216
-
217
- - now gamepad events return what gamepad triggered the action
218
-
219
- ```js
220
- onGamepadButtonPress("south", (btn, gp) => {
221
- console.log(gp.index); // gamepad number on navigator's gamepad list
222
- });
223
- ```
224
-
225
- ### Physics
226
-
227
- - added effector components: `areaEffector()`, `buoyancyEffector()`,
228
- `pointEffector()`, `surfaceEffector()`.
229
- - added `constantForce()` component.
230
- - added `patrol()` component to move along a list of waypoints.
231
- - added `sentry()` component to notify when certain objects are in sight.
232
- - added `NavMesh` class for pathfinding on a mesh.
233
- - added `pathfinder()` component to calculate a list of waypoints on a graph.
234
- - now collision checks are only done if there's area objects.
235
-
236
- ### Game Object
237
-
238
- - added `getTreeRoot()` to get the game's root object, which is the parent of
239
- all other objects
240
-
241
- ```js
242
- // get the root object
243
- const root = getTreeRoot();
244
- root.add(); // same as add()
245
- root.get(); // same as get()
246
- ```
247
-
248
- - added `GameObjRaw.tags` to get a game object's tags.
249
-
250
- ```js
251
- const obj = add([sprite("bean"), "enemy", "dangerous"]);
252
-
253
- // get the tags
254
- debug.log(obj.tags); // ["enemy", "dangerous"]
255
- ```
256
-
257
- ### Components
258
-
259
- - added support to setters/getters syntax in `ScaleComp` and `SpriteComp`
260
- components
261
-
262
- ```js
263
- const obj = add([sprite("bean"), scale(2)]);
264
-
265
- // set it with = syntax
266
- obj.scale = vec2(3, 4);
267
- obj.sprite = "bag";
268
- ```
269
-
270
- ### Rendering and Animation
271
-
272
- - added the `animate()` component to _animate_ the properties of an object using
273
- keyframes. Check out
274
- [Animation Example](https://play.kaplayjs.com/?example=animation)
275
-
276
- ```js
277
- // prop to animate, frames, options
278
- rotatingBean.animate("angle", [0, 360], {
279
- duration: 2,
280
- direction: "forward",
281
- });
282
- ```
283
-
284
- - added `particles()` component to emit and draw particles.
285
-
286
- - readded `layers()` and the `layer()` component.
287
-
288
- Before the `z()` component, there was a `layer()` component that allowed you
289
- to control the draw order of objects. It was removed in v3000, but now it's
290
- back from the void.
291
-
292
- ```js
293
- // define the layers
294
- layers(
295
- [
296
- "bg",
297
- "game",
298
- "ui",
299
- // the default layer
300
- ],
301
- "game",
302
- );
303
-
304
- // use the layer component
305
- add([sprite("bg"), layer("bg")]);
306
- ```
307
-
308
- - added `SpriteComp.getCurAnim()` to get the current animation data
309
-
310
- ```js
311
- const obj = add([sprite("bean", { anim: "walk" })]);
312
-
313
- // get the current animation name
314
- debug.log(obj.getCurAnim().name); // "walk"
315
- ```
316
-
317
- - added `SpriteComp.getAnim()` for get any animation data
318
-
319
- ```js
320
- loadSprite("bean", "bean.png", {
321
- sliceX: 4,
322
- sliceY: 1,
323
- anims: {
324
- walk: {
325
- from: 0,
326
- to: 3,
327
- },
328
- },
329
- });
330
-
331
- const obj = add([sprite("bean")]);
332
-
333
- // get the animation data
334
- debug.log(obj.getAnim("walk")); // { from: 0, to: 3 }
335
- ```
336
-
337
- - added `SpriteComp.hasAnim()` to check if an animation exists
338
-
339
- ```js
340
- const obj = add([sprite("bean", { anim: "walk" })]);
341
-
342
- // check if an animation exists
343
- debug.log(obj.hasAnim("walk")); // true
344
- ```
345
-
346
- - added `camFlash()` to flash the screen.
347
-
348
- ```js
349
- camFlash(0.5, 0.5, 0.5, 0.5);
350
- ```
351
-
352
- - added support for radius in individual corners for `RectComp` component.
353
-
354
- ```js
355
- add([
356
- rect(100, 100, {
357
- radius: [10, 20, 30, 40],
358
- }),
359
- ]);
360
- ```
361
-
362
- - (**! break**) removed compatibilty to use two KAPLAY frames in the same page,
363
- due to perfomance improvements
364
-
365
- - fix error screen not showing with not Error object
366
-
367
- - Added `SpriteComp.animFrame` to get the frame of the current animation (not on
368
- the spritesheet)
369
-
370
- ### Audio
371
-
372
- - now you can pass an `AudioBuffer` to `loadSound()`
373
- - added `loadMusic()` to load streaming audio (doesn't block in loading screen).
374
-
375
- ```js
376
- loadMusic("bgm", "bgm.mp3");
377
-
378
- // play the music
379
- play("bgm");
380
- ```
381
-
382
- ### Math
383
-
384
- - added `Vec2.fromArray()` to convert an array to a `Vec2`.
385
-
386
- ```js
387
- const point = Vec2.fromArray([100, 200]); // vec2(100, 200);
388
- ```
389
-
390
- - added `Vec2.toArray()` to convert a `Vec2` to an array.
391
-
392
- ```js
393
- const point = vec2(100, 200);
394
- const arr = point.toArray(); // [100, 200]
395
- ```
396
-
397
- - added `chooseMultiple()` to choose a random element from an array.
398
-
399
- ```js
400
- const numbers = [1, 2, 3, 4, 5];
401
- const random = chooseMultiple(numbers, 3); // [3, 1, 5]
402
- ```
403
-
404
- - added `shuffle()` to shuffle an array.
405
-
406
- ```js
407
- const numbers = [1, 2, 3, 4, 5];
408
- shuffle(numbers); // [3, 1, 5, 2, 4]
409
- ```
410
-
411
- ### Debug mode
412
-
413
- - added `outline()`, `shader()`, and `area()` properties to `debug.inspect`.
414
- - added `KAPLAYOpt.debugKey` for customizing the key used to toggle debug mode.
415
-
416
- ```js
417
- kaplay({
418
- debugKey: "l",
419
- });
420
- ```
421
-
422
- - added compatibility with custom properties in debug mode
423
-
424
- ```js
425
- const obj = add([
426
- sprite("bean"),
427
- {
428
- health: 100, // on debug.inspect
429
- damage: 10, // on debug.inspect
430
- hp() {
431
- this.health -= this.damage;
432
- }, // not on debug.inspect
433
- },
434
- ]);
435
-
436
- // see the custom properties in debug mode
437
- debug.inspect = true;
438
- ```
439
-
440
- - Now `debug.log()` accepts multiple argument of any type, like `console.log()`.
441
-
442
- ### Helpers
443
-
444
- - added `getSceneName()` to get the current scene name
445
- - added `Color.toArray()` to convert a color to an array
446
- - added global raycast function and raycast method to level
447
- - added support for textured polygons
448
- - added support for concave polygon drawing
449
- - added support for arrays in uniforms
450
- - added support for texture larger than 2048x2048
451
- - added support for gravity direction
452
- - added line join (bevel, miter, round) and line caps (square, round)
453
- - added quadratic bezier and Catmull-Rom evaluation
454
- - added evaluation of the first and second derivatives for all splines
455
- - added higher order easing functions linear, steps and cubic-bezier
456
-
457
- ### TypeScript
458
-
459
- - Now you can type `get()` with a type parameter and passing component types.
460
- (**v4000**)
461
-
462
- ```ts
463
- const player = get<BodyComp>("player");
464
- ```
465
-
466
- - Now `Key` also accepts a string as an acceptable value.
467
- - Now `text()` component doesn't require to pass a string.
468
- - Now `camScale()` and `camPos()` accept only 1 number as parameter.
469
- - Now `shake()` can be called without args.
470
- - Now `loadShader()` and `loadShaderURL()` accepts null for unused parameters.
471
- - Now `RectCompOpt` accepts a array of numbers for `radius`.
472
-
473
- ### Deprecations
474
-
475
- > All changes applies for both v3001 and v4000
476
-
477
- - deprecated `kaboom()` in favor of `kaplay()` (you can still use `kaboom*`)
478
- - deprecated `SpriteComp.curAnim()` in favor of `SpriteComp.getCurAnim().name`
479
- - deprecated `fadeIn` component in favor of `OpacityComp.fadeIn()`
480
- - deprecated `Event`, `EventHandler` and `EventController` in favor of `KEvent`,
481
- `KEventHandler` and `KEventController`
482
-
483
- ### Bug fixes
484
-
485
- > All changes applies for both v3001 and v4000
486
-
487
- - **(break)** much typescript definitions was fixed, if you use typescript now
488
- maybe you see new errors that make your code strict
489
- - fix error screen not showing with not Error object
490
- - fix error where debug screen was scaling bad the blue rectangles
491
- - fix error where error screen was not showing when the error was thrown in a
492
- input event
493
- - fix error where fonts was cropped in the bottom
494
- - fix an error where `stay()` object loose their input events on scene change
495
-
496
- ### v3000.1.17
497
-
498
- - exposed `vel` property on `BodyComp`
499
-
500
- ### v3000.1.16
501
-
502
- - fixed error not being logged
503
- - fixed error screen scaling error in letterbox mode
504
-
505
- ### v3000.1.15
506
-
507
- - fixed `loadRoot()` not working sometimes
508
- - fixed audio being resumed when the tab is switched on but `debug.paused` is
509
- true
510
-
511
- ### v3000.1.12
512
-
513
- - fixed `color()` and `rgb()` not working
514
-
515
- ### v3000.1.11
516
-
517
- - added option `kaboom({ focus: false })` to disable focus on start
518
- - fixed `rand()` typing for numbers
519
- - fixed mouse position in fullscreen
520
- - added `Color#toHSL()`
521
-
522
- ### v3000.1.10
523
-
524
- - fixed test code accidentally getting shipped (where a screenshot will be
525
- downloaded every time you press space)
526
-
527
- ### v3000.1.9
528
-
529
- - added `fill` option to `rect()`, `circle()` and `sprite()`
530
- - fixed view getting cut off in letterbox mode
531
-
532
- ### v3000.1.8
533
-
534
- - fixed `scale` option acting weird when width and height are defined (by
535
- @hirnsalat)
536
-
537
- ### v3000.1.7
538
-
539
- - fixed `debug.paused` not pausing audio
540
- - added `mask()` component
541
- - added support for colored font outline
542
-
543
- ```js
544
- loadFont("apl386", "/examples/fonts/apl386.ttf", {
545
- outline: {
546
- width: 8,
547
- color: rgb(0, 0, 255),
548
- },
549
- });
550
- ```
551
-
552
- - fixed `wave()` not starting at `0` when time is `0`
553
- - kaboom now only displays error screen for kaboom's own error, instead of
554
- catching all errors in current window
555
- - added `KaboomError` class for errors related to current kaboom instance
556
- - setting `obj.text` with `text()` component now immediately updates `width` and
557
- `height` property
558
-
559
- ```js
560
- const obj = add([text("oh hi"), pos(100, 200)]);
561
-
562
- // before
563
- obj.text = "bye";
564
- console.log(obj.width); // still the width of "oh hi" until next render
565
-
566
- // before
567
- obj.text = "bye";
568
- console.log(obj.width); // will be updated to the width of "bye"
569
- ```
570
-
571
- ### v3000.1.6
572
-
573
- - fixed `loadSound` typing to accept `ArrayBuffer`
574
-
575
- ### v3000.1.5
576
-
577
- - added `Event#clear()` method
578
- - fixed `add()` without argument
579
-
580
- ### v3000.1.4
581
-
582
- - added `audio.stop()` method
583
-
584
- ```js
585
- const music = play("music");
586
- music.stop();
587
- ```
588
-
589
- ### v3000.1.3
590
-
591
- - fixed `onCollideUpdate()` still runs when object is paused
592
- - allow `add()` and `make()` without arguments
593
- - added `debug.numObjects()`
594
- - added `width` and `height` properties to `SpriteData`
595
-
596
- ```js
597
- // get sprite size
598
- getSprite("bean").then((spr) => {
599
- console.log(spr.width, spr.height);
600
- });
601
- ```
602
-
603
- ### v3000.1.2
604
-
605
- - fixed audio not pausing when tab hidden and `backgroundAudio` not set
606
- - fixed `debug.timeScale` not working
607
- - fixed `debug.paused` not able to resume
608
- - fixed `quad` option not working in `sprite()` component
609
- - added `onHide()` and `onShow()` for tab visibility event
610
-
611
- ### v3000.1.1
612
-
613
- - fixed some indirect `fixed` related issues
614
-
615
- ## [3000.1.0] - 2023-08-18 (kaboom.js)
616
-
617
- - added game object level input handling
618
-
619
- ```js
620
- // add a scene game object
621
- const scene = add([]);
622
-
623
- const bean = scene.add([sprite("bean"), pos(100, 200), area(), body()]);
624
-
625
- scene.onKeyPress("space", () => {
626
- bean.jump();
627
- });
628
-
629
- scene.onMousePress(() => {
630
- bean.jump();
631
- });
632
-
633
- // setting scene.paused will pause all the input events
634
- scene.paused = true;
635
-
636
- // destroying scene will cancel all its input events
637
- scene.destroy();
638
-
639
- const ui = add([]);
640
-
641
- ui.add(makeButton());
642
-
643
- // these will only work if ui game object is active
644
- ui.onMousePress(() => {
645
- // ...
646
- });
647
-
648
- // before you'll have to manually clean up events on obj.onDestroy()
649
- const scene = add([]);
650
- const evs = [];
651
- scene.onDestroy(() => {
652
- evs.forEach((ev) => ev.cancel());
653
- });
654
- evs.push(
655
- k.onKeyPress("space", () => {
656
- doSomeSceneSpecificStuff();
657
- }),
658
- );
659
- ```
660
-
661
- - added `make()` to create game object without adding to the scene
662
-
663
- ```js
664
- const obj = make([sprite("bean"), pos(120, 60)]);
665
-
666
- add(obj);
667
- ```
668
-
669
- - fixed children not inheriting `fixed()` from parent
670
-
671
- ```js
672
- // before
673
- const ui = add([fixed()]);
674
-
675
- ui.add([
676
- rect(),
677
- // have to also give all children game objects fixed()
678
- fixed(),
679
- ]);
680
-
681
- // now
682
- const ui = add([fixed()]);
683
-
684
- // you don't have to add fixed() to children
685
- ui.add([rect(100, 100)]);
686
- ```
687
-
688
- - fixed `AreaComp#onClick()` event not getting cleaned up when game object is
689
- destroyed
690
- - fixed typo `isTouchScreen()` -> `isTouchscreen()`
691
- - fixed inspect mode doesn't show the properties box of indirect children game
692
- objects
693
- - fixed some problem causing kaboom to not work with vite
694
- - fixed "destroy" event not run on children game objects
695
- - calling `shake()` when another shake is happening adds to the shake instead of
696
- reset it?
697
- - fixed incorrect touch position when canvas is not at top left of page
698
-
699
- ## [3000.0.0] - 2023-05-25 (kaboom.js)
700
-
701
- ### Game Objects
702
-
703
- - added scene graph, game objects are now stored in a tree-like structure and
704
- can have children with `obj.add()`
705
-
706
- ```js
707
- const bean = add([sprite("bean"), pos(160, 120)]);
708
-
709
- const sword = bean.add([
710
- sprite("sword"),
711
- // transforms will be relative to parent bean object
712
- pos(20, 20),
713
- rotate(20),
714
- ]);
715
-
716
- const hat = bean.add([
717
- sprite("hat"),
718
- // transforms will be relative to parent bean object
719
- pos(0, -10),
720
- ]);
721
-
722
- // children will be moved alongside the parent
723
- bean.moveBy(100, 200);
724
-
725
- // children will be destroyed alongside the parent
726
- bean.destroy();
727
- ```
728
-
729
- - added `recursive` and `liveUpdate` options to `get()`
730
-
731
- ```js
732
- const enemies = get("enemy", {
733
- // get from all children and descendants, instead of only direct children
734
- recursive: true,
735
- // live update the returned list to listen to onAdd and onDestroy events
736
- liveUpdate: true,
737
- });
738
-
739
- console.log(enemies.length); // 3
740
-
741
- add([sprite("bigbird"), "enemy"]);
742
-
743
- console.log(enemies.length); // 4
744
- ```
745
-
746
- - changed object update order from reversed to not reversed
747
- - (**BREAK**) removed `GameObj#every()` and `GameObj#revery()` in favor of
748
- `obj.get("*").forEach()`
749
- - (**BREAK**) renamed `GameObj#_id` to `GameObj#id`
750
- - `addLevel()` now returns a `GameObj` which has all individual grid objects as
751
- its children game objects, with `LevelComp` containing its previous methods
752
- - added `onAdd()` and `onDestroy()` events to listen to added / destroyed game
753
- objects
754
-
755
- ### Components
756
-
757
- - added support for getter and setters in component properties
758
-
759
- #### Area
760
-
761
- - added collision support for rotate shapes and polygons
762
- - added option `collisionIgnore` to `area()` component, which accepts a list of
763
- tags to ignore when checking collision
764
-
765
- ```js
766
- const bean = add([
767
- sprite("bean"),
768
- pos(100, 80),
769
- area({
770
- collisionIgnore: ["cloud", "particle"],
771
- }),
772
- ]);
773
- ```
774
-
775
- - added `Area#getCollisions` to get a list of all current collisions happening
776
-
777
- ```js
778
- for (const col of player.getCollisions()) {
779
- const c = col.target;
780
- if (c.is("chest")) {
781
- c.open();
782
- }
783
- }
784
- ```
785
-
786
- - added `Area#onCollideUpdate()` and `onCollideUpdate()` to register an event
787
- that runs every frame when 2 objects are colliding
788
- - added `Area#onCollideEnd()` and `onCollideEnd()` to register an event that
789
- runs once when 2 objects stop colliding
790
- - added `Area#onHover()` and `onHover()` to register an event that runs once
791
- when an object(s) is hovered over
792
- - added `Area#onHoverEnd()` and `onHoverEnd()` to register an event that runs
793
- once when an object(s) stops being hovered over
794
- - (**BREAK**) renamed `onHover()` to `onHoverUpdate()` (it registers an event
795
- that runs every frame when an object is hovered over)
796
- - (**BREAK**) renamed `pushOut()` to `resolveCollision()`
797
-
798
- #### Body
799
-
800
- - added `Body#onFall()` which fires when object starts falling
801
- - added `Body#onPhysicsResolve()` and `Body#onBeforePhysicsResolve()` to
802
- register events relating to collision resolution
803
-
804
- ```js
805
- // make semi-solid platforms that doesn't block player when player is jumping over it
806
- player.onBeforePhysicsResolve((collision) => {
807
- if (collision.target.is(["platform", "soft"]) && player.isJumping()) {
808
- collision.preventResolution();
809
- }
810
- });
811
- ```
812
-
813
- - (**BREAK**) removed `solid()` in favor of `body({ isStatic: true })`
814
- - added option `body({ mass: 3 })` to define how hard a non-static body is to be
815
- pushed by another non-static body
816
- - added option `body({ stickToPlatform: false })` to turn off object moving with
817
- platform
818
- - (**BREAK**) removed `Body#doubleJump()` in favor of `doubleJump()` component
819
- - (**BREAK**) renamed `Body#weight` to `Body#gravityScale`
820
- - (**BREAK**) renamed `Body#onFall()` to `Body#onFallOff()` which triggers when
821
- object fall off a platform
822
- - (**BREAK**) defining `setGravity()` is now required for enabling gravity,
823
- `body()` by default will only prevent objects from going through each other
824
-
825
- #### Others
826
-
827
- - (**BREAK**) renamed `origin()` to `anchor()`, so it won't mess up typescript
828
- in global mode
829
- - (**BREAK**) `anchor` (previously `origin`) no longer controls text alignment,
830
- use `text({ align: "left" })` option instead
831
- - added `doubleJump()` component to enable double jump (or any number of jumps)
832
- - (**BREAK**) renamed `outview()` to `offscreen()`, and uses a much faster check
833
- (but less accurate) for if object is offscreen
834
- - removed `offset` option in favor of a simpler `distance` option
835
- - renamed `onExitView()` and `onEnterView()` to `onExitScreen()` and
836
- `onEnterScreen()`
837
- - (**BREAK**) removed `cleanup()` component in favor of
838
- `offscreen({ destroy: true })`
839
- - added `OpacityComp#fadeOut()`
840
- - added `fadeIn()` component
841
- - `stay()` now accepts a list of scenes to stay for, like
842
- `stay(["gameover", "menu"])`
843
- - (**BREAK**) changed `SpriteComp#flipX` and `SpriteComp#flipY` to properties
844
- instead of functions
845
- - (**BREAK**) `sprite.onAnimStart()` and `sprite.onAnimEnd()` now triggers on
846
- any animation
847
-
848
- ```js
849
- // before
850
- obj.onAnimEnd("walk", () => {
851
- // do something
852
- });
853
-
854
- // v3000
855
- obj.onAnimEnd((anim) => {
856
- if (anim === "walk") {
857
- // do something
858
- }
859
- });
860
- ```
861
-
862
- - (**BREAK**) `ScaleComp#scale` will always be a `Vec2` not `number`
863
- - `shader()` comp `uniform` parameter now supports a callback that returns the
864
- uniform every frame
865
-
866
- ```js
867
- const player = add([
868
- sprite("bean"),
869
- // will calculate and send u_time every frame
870
- shader("flashy", () => ({
871
- u_time: time(),
872
- })),
873
- ]);
874
- ```
875
-
876
- ### Assets
877
-
878
- - added `loadProgress()` that returns a `0.0 - 1.0` that indicates current asset
879
- loading progress
880
- - added option `loadingScreen` to `kaboom()` where you can turn off the default
881
- loading screen
882
- - added `onLoadUpdate()` to register a custom loading screen (see "loader"
883
- example)
884
-
885
- ```js
886
- // custom loading screen
887
- onLoadUpdate((progress) => {
888
- drawCircle({
889
- pos: center(),
890
- radius: 32,
891
- end: map(progress, 0, 1, 0, 360),
892
- });
893
- });
894
- ```
895
-
896
- - added support for multiple sprite sources as frames in `loadSprite()`
897
-
898
- ```js
899
- loadSprite("player", [
900
- "sprites/player_idle.png",
901
- "sprites/player_run.png",
902
- "sprites/player_jump.png",
903
- ]);
904
- ```
905
-
906
- - (**BREAK**) added `loadShaderURL()`, `loadShader()` now only load shader code
907
- not files
908
-
909
- ### Text
910
-
911
- - added `loadFont()` to load `.ttf`, `.otf`, `.woff2` or any font supported by
912
- browser `FontFace`
913
-
914
- ```js
915
- // Load a custom font from a .ttf file
916
- loadFont("FlowerSketches", "/examples/fonts/FlowerSketches.ttf");
917
-
918
- // Load a custom font with options
919
- loadFont("apl386", "/examples/fonts/apl386.ttf", {
920
- outline: 4,
921
- filter: "linear",
922
- });
923
- ```
924
-
925
- - (**BREAK**) renamed previous `loadFont()` to `loadBitmapFont()`
926
- - (**BREAK**) removed built-in `apl386`, `apl386o`, `sink`, `sinko` (still
927
- available under `examples/fonts`)
928
- - changed default font size to `36`
929
- - (**BREAK**) changed to bbcode syntax for styled text
930
-
931
- ```js
932
- // before
933
- "[oh hi].green here's some [styled].wavy text";
934
- // v3000
935
- "[green]oh hi[/green] here's some [wavy]styled[/wavy] text";
936
- ```
937
-
938
- ### Graphics
939
-
940
- - fixed visual artifacts on text rendering
941
- - added `colors` option to `drawPolygon()` that controls the color of each
942
- corner
943
- - added `gradient` option to `drawRect()` that specifies the start and end color
944
- - added `drawMasked()` and `drawSubtracted()`
945
- - added `pushRotateX()`, `pushRotateY()` and `pushRotateZ()`
946
- - added `pixelDensity` option to `kaboom()`
947
- - (**BREAK**) changed position vertex format from `vec3` to `vec2` (which is
948
- passed in as the first argument of custom `frag` and `vert` shader functions)
949
- - added `usePostEffect()` to add post process shader
950
-
951
- ```js
952
- loadShader(
953
- "invert",
954
- null,
955
- `
956
- vec4 frag(vec2 pos, vec2 uv, vec4 color, sampler2D tex) {
957
- vec4 c = def_frag();
958
- return vec4(1.0 - c.r, 1.0 - c.g, 1.0 - c.b, c.a);
959
- }
960
- `,
961
- );
962
-
963
- usePostEffect("invert");
964
- ```
965
-
966
- - shader error logs now yields the correct line number
967
- - added `slice9` option to `loadSprite()` to enable
968
- [9 slice scaling](https://en.wikipedia.org/wiki/9-slice_scaling)
969
-
970
- ```js
971
- loadSprite("grass", "/sprites/grass.png", {
972
- slice9: {
973
- left: 8,
974
- right: 8,
975
- top: 8,
976
- bottom: 8,
977
- },
978
- });
979
-
980
- const g = add([sprite("grass")]);
981
-
982
- onMouseMove(() => {
983
- const mpos = mousePos();
984
- // updating width / height will scale the image but not the sliced frame
985
- g.width = mpos.x;
986
- g.height = mpos.y;
987
- });
988
- ```
989
-
990
- ### Audio
991
-
992
- - added option `kaboom({ backgroundAudio: false })` to not pause audio when tab
993
- not active
994
- - changed `speed`, `detune`, `volume`, `loop` in `AudioPlay` from functions to
995
- properties
996
- - added `onEnd()` event for `const pb = play("sound")`
997
-
998
- ```js
999
- // before
1000
- const music = play("song");
1001
- music.speed(2);
1002
- music.volume(0.5);
1003
- music.loop(true);
1004
-
1005
- // v3000
1006
- const music = play("song");
1007
- music.speed = 2;
1008
- music.volume = 0.5;
1009
- music.loop = true;
1010
- ```
1011
-
1012
- ### Input
1013
-
1014
- - added `onScroll(action: (delta: Vec2) => void)` to listen mouse wheel scroll
1015
- - fixed touches not treated as mouse
1016
- - (**BREAK**) changed `onTouchStart()`, `onTouchMove()` and `onTouchEnd()`
1017
- callback signature to `(pos: Vec2, touch: Touch) => void` (exposes the native
1018
- `Touch` object)
1019
- - added `onGamepadButtonPress()`, `onGamepadButtonDown()`,
1020
- `onGamepadButtonRelease()`
1021
- - added `isGamepadButtonPressed()`, `isGamepadButtonDown()`,
1022
- `isGamepadButtonReleased()`
1023
- - added `onGamepadStick()` to handle gamepad axes info for left and right sticks
1024
- - added `getConnectedGamepads()`
1025
- - added `onGamepadConnect()` and `onGamepadDisconnect()`
1026
- - added `gamepads` option to `kaboom()` to define custom gamepads
1027
-
1028
- ### Level
1029
-
1030
- - (**BREAK**) changed `addLevel()` options API
1031
- - renamed `width` and `height` to `tileWidth` and `tileHeight`
1032
- - renamed `any` to `wildcardTile`
1033
- - now all tile symbols are defined in the `tiles` object
1034
-
1035
- ```js
1036
- // before
1037
- addLevel(["@ ^ $$", "======="], {
1038
- width: 32,
1039
- height: 32,
1040
- "=": () => [sprite("grass"), area(), body({ isStatic: true })],
1041
- $: () => [sprite("coin"), area(), "coin"],
1042
- any: (symbol) => {
1043
- if (symbol === "@") {
1044
- return [
1045
- /* ... */
1046
- ];
1047
- }
1048
- },
1049
- });
1050
-
1051
- // v3000
1052
- addLevel(["@ ^ $$", "======="], {
1053
- tileWidth: 32,
1054
- tileHeight: 32,
1055
- tiles: {
1056
- "=": () => [sprite("grass"), area(), body({ isStatic: true })],
1057
- $: () => [sprite("coin"), area(), "coin"],
1058
- },
1059
- wildcardTile: (symbol) => {
1060
- if (symbol === "@") {
1061
- return [
1062
- /* ... */
1063
- ];
1064
- }
1065
- },
1066
- });
1067
- ```
1068
-
1069
- ### Misc
1070
-
1071
- - sprites are now automatically packed, improving performance
1072
- - (**BREAK**) renamed `gravity()` into `getGravity()` and `setGravity()`
1073
- - (**BREAK**) removed all deprecated functions in v2000.2
1074
- - (**BREAK**) raised esbuild target to `esnext`
1075
- - added `setBackground()` and `getBackground()` in addition to `background`
1076
- option in `kaboom()`
1077
- - moved type defs for global functions to `import "kaboom/global"`
1078
-
1079
- ```js
1080
- // if use global functions
1081
- import "kaboom";
1082
- import "kaboom/global"; // required to load global types
1083
-
1084
- kaboom();
1085
-
1086
- // will have definition
1087
- add();
1088
- ```
1089
-
1090
- ```js
1091
- // if don't use global function
1092
- import "kaboom";
1093
-
1094
- kaboom({ global: false });
1095
-
1096
- // type error, won't pollute global namespace if not manually import "kaboom/global"
1097
- add();
1098
- ```
1099
-
1100
- - added `tween()` for tweening, and a set of built-in easing functions in
1101
- `easings`
1102
-
1103
- ```js
1104
- onMousePress(() => {
1105
- tween(
1106
- bean.pos.x,
1107
- mousePos().x,
1108
- 1,
1109
- (val) => (bean.pos.x = val),
1110
- easings.easeOutBounce,
1111
- );
1112
- tween(
1113
- bean.pos.y,
1114
- mousePos().y,
1115
- 1,
1116
- (val) => (bean.pos.y = val),
1117
- easings.easeOutBounce,
1118
- );
1119
- });
1120
- ```
1121
-
1122
- - (**BREAK**) changed all event handlers to return a `EventController` object
1123
- instead of a function to cancel event
1124
-
1125
- ```js
1126
- // before
1127
- const cancel = onUpdate(() => {
1128
- /* ... */
1129
- });
1130
- cancel();
1131
-
1132
- // v3000
1133
- const ev = onUpdate(() => {
1134
- /* ... */
1135
- });
1136
- ev.paused = true;
1137
- ev.cancel();
1138
- ```
1139
-
1140
- - timers can now be paused
1141
-
1142
- ```js
1143
- const timer = wait(4, () => {
1144
- /* ... */
1145
- });
1146
- timer.paused = true;
1147
- timer.resume();
1148
-
1149
- const timer = loop(1, () => {
1150
- /* ... */
1151
- });
1152
- timer.paused = true;
1153
- timer.resume();
1154
- ```
1155
-
1156
- - `kaboom()` now automatically focuses the canvas
1157
- - added `quit()` to end everything
1158
- - added `download()`, `downloadText()`, `downloadJSON()`, `downloadBlob()`
1159
- - added `Recording#stop()` to stop the recording and returns the video data as
1160
- mp4 Blob
1161
- - added `debug.numFrames()` to get the total number of frames elapsed
1162
- - added `onError()` to handle error or even custom error screen
1163
- - added `onResize()` to register an event that runs when canvas resizes
1164
- - added `setCursorLocked()` and `isCursorLocked()`
1165
- - (**BREAK**) renamed `cursor()` to `setCursor()`
1166
- - (**BREAK**) renamed `fullscreen()` to `setFullscreen()`
1167
- - (**BREAK**) renamed `isTouch()` to `isTouchscreen()`
1168
- - (**BREAK**) removed `layers()` in favor of parent game objects (see "layers"
1169
- example)
1170
- - (**BREAK**) removed `load()` event for components, use `onLoad()` in `add()`
1171
- event
1172
- - (**BREAK**) removed `debug.objCount()` in favor of `getAll().length`
1173
- - added `debug.numFrames()` to get the current frame count
1174
-
1175
- ## [2000.2.6] - 2022-01-27 (kaboom.js)
1176
-
1177
- - fixed text always being wrapped if updated
1178
- - fixed text comp properties `letterSpacing`, `charSpacing`, `transform`,
1179
- `styles` not being exposed
1180
-
1181
- ### v2000.2.5
1182
-
1183
- - fixed updating `font` property on gameobj not updating the text font
1184
-
1185
- ### v2000.2.4
1186
-
1187
- - fixed `focus()` not properly exported
1188
- - deprecated `focus()` in favor of `canvas.focus()` due to name collision
1189
-
1190
- ### v2000.2.3
1191
-
1192
- - fixed `kaboom.d.ts` completely messed up
1193
-
1194
- ### v2000.2.2
1195
-
1196
- - fixed doc for `TextCompOpt#styles` and `DrawTextOpt#styles`
1197
-
1198
- ### v2000.2.1
1199
-
1200
- - fixed updates not running at all when `kaboom({ debug: false })`
1201
-
1202
- ## [2000.2.0] "Fancy Text Mode" 2022-01-23 (kaboom.js)
1203
-
1204
- - added `formatText()` and `drawFormattedText()`
1205
- - added `charSpacing` and `lineSpacing` in `TextCompOpt` and `DrawTextOpt`
1206
- - added optional `transitions` argument in `state()` to define allowed
1207
- transitions
1208
- - added `StateComp#onStateTransition` to register event for specific transitions
1209
- - added syntax to style a piece of text `"this is a [styled].wavy text"` and
1210
- `style` option in `TextCompOpt` and `DrawTextOpt` to define the styles with
1211
- `CharTransformFunc`
1212
- - deprecated `dir()` in favor of `Vec2.fromAngle()`
1213
- - fixed `onTouchEnd()` fired on `touchmove`
1214
- - added `outview()` component to control behavior when object leaves visible
1215
- area
1216
- - deprecated `cleanup(delay?: number)` in favor of `cleanup(opt?: CleanupOpt)`
1217
- - deprecated `mouseWorldPos()` in favor of `toWorld(mousePos())`
1218
- - deprecated `rng()` in favor of `new RNG()`
1219
- - added classes `Vec2`, `Color`, `Mat4`, `Timer`, `Quad`, `RNG`, `Line`, `Rect`,
1220
- `Circle`
1221
- - added deprecation warning
1222
- - fixed letterbox view mode
1223
- - allow non-stretch letterbox
1224
- - fixed mouse position malfunction in fullscreen, stretch and letterbox mode
1225
-
1226
- ### [2000.1.8]
1227
-
1228
- - fixed `Color#eq()` not giving correct result
1229
-
1230
- ### v2000.1.7
1231
-
1232
- - fixed not having export if installed from github repo with npm
1233
- - fixed event canceller returned by raw `onUpdate()` and `onDraw()` crashing
1234
-
1235
- ### v2000.1.6
1236
-
1237
- - fixed debug widget scale
1238
-
1239
- ### v2000.1.5
1240
-
1241
- - fixed `enterState()` not passing args to `onStateEnter()` callback
1242
-
1243
- ### v2000.1.4
1244
-
1245
- - fixed `state()` to not require registering `onStateUpdate()` before using any
1246
- state
1247
-
1248
- ### v2000.1.2
1249
-
1250
- - fixed `onKeyRelease()` wrongfully check for key press instead of release
1251
-
1252
- ### v2000.1.1
1253
-
1254
- - fixed `StateComp#enterState()` not accepting any state
1255
-
1256
- ## [2000.1.0] "Record Mode" - 2021-11-04 (kaboom.js)
1257
-
1258
- - added `hsl2rgb()` for converting HSL color to kaboom RGB
1259
- - added `record()` to start a screen recording
1260
- - added F5 to screenshot and F6 to toggle record mode in debug mode
1261
- - added `DrawTextOpt#transform()` and `TextCompOpt#transform()` for defining
1262
- style and transformation for each character
1263
- - added `state()` component for finite state machine
1264
- - added support for multiple tags in `get()` and `every()`
1265
- - added UI indicator for `debug.paused` and `debug.timeScale`
1266
- - changed inspect mode UI style
1267
- - added color constants `WHITE`, `BLACK`, `BLUE`, `GREEN`, `RED`, `MAGENTA`,
1268
- `CYAN`, `YELLOW`
1269
- - added new API style (`on` prefix for all event handler function, `is` prefix
1270
- for all boolean state getters)
1271
- - `onLoad()`
1272
- - `onUpdate()`
1273
- - `onDraw()`
1274
- - `onKeyPress()`
1275
- - `onKeyPressRepeat()`
1276
- - `onKeyDown()`
1277
- - `onKeyRelease()`
1278
- - `onMousePress()`
1279
- - `onMouseDown()`
1280
- - `onMouseRelease()`
1281
- - `onMoueMove()`
1282
- - `onTouchStart()`
1283
- - `onTouchMove()`
1284
- - `onTouchEnd()`
1285
- - `onCollide()`
1286
- - `onClick()`
1287
- - `onHover()`
1288
- - `isFocused()`
1289
- - `isKeyDown()`
1290
- - `isKeyPressed()`
1291
- - `isKeyPressedRepeat()`
1292
- - `isKeyDown()`
1293
- - `isMouseDown()`
1294
- - `isMousePressed()`
1295
- - `isMouseReleased()`
1296
- - `isMouseMoved()`
1297
- - `isMouseMoved()`
1298
- - `GameObj#onUpdate()`
1299
- - `GameObj#onDraw()`
1300
- - `AreaComp#onCollide()`
1301
- - `AreaComp#onHover()`
1302
- - `AreaComp#onClick()`
1303
- - `BodyComp#onGround()`
1304
- - `BodyComp#onFall()`
1305
- - `BodyComp#onHeadbutt()`
1306
- - `BodyComp#onDoubleJump()`
1307
- - `BodyComp#isGrounded()`
1308
- - `BodyComp#isFalling()`
1309
- - `SpriteComp#onAnimEnd()`
1310
- - `SpriteComp#onAnimStart()`
1311
- - `HealthComp#onDeath()`
1312
- - `HealthComp#onHurt()`
1313
- - `HealthComp#onHeal()`
1314
- - `AudioPlay#isStopped()`
1315
- - `AudioPlay#isPaused()`
1316
-
1317
- ## [2000.0.0] "Burp Mode" - 2021-10-20 (kaboom.js)
1318
-
1319
- - version jumped to v2000.0.0 (still semver, just big)
1320
- - added `burp()` for easy burping
1321
- - added decent typescript / autocomplete support and jsdocs
1322
- - introducing new character "bean" ![bean](assets/sprites/bean.png)
1323
- - added `loadBean()` to load `"bean"` as a default sprite
1324
- - changed default font to [APL386](https://abrudz.github.io/APL386/), as
1325
- `"apl386o"` (default outlined version) and `"apl386"`
1326
- - included font
1327
- [kitchen sink](https://polyducks.itch.io/kitchen-sink-textmode-font) as
1328
- `"sinko"` (outlined version) and `"sink"` (standard version with extended
1329
- characters for text-mode games)
1330
- - added `font` field in `KaboomOpt` to set the default font
1331
- - added `loadSpriteAtlas(src, entries)` to load sprite atlas
1332
- - inspect mode now displays every comp's state
1333
- - **BREAK** added continuous collision resolution which checks collision in
1334
- `move()` if 2 objects are both "solid" (objects now won't pass through other
1335
- solid object at high speed or low framerate)
1336
-
1337
- ```js
1338
- // before
1339
- add([sprite("player"), area()]);
1340
-
1341
- add([sprite("rock"), solid()]);
1342
-
1343
- keyDown("left", () => {
1344
- player.move(-120, 0);
1345
- });
1346
-
1347
- player.action(() => {
1348
- player.resolve(); // or pushOutAll() in beta versions
1349
- });
1350
-
1351
- // after
1352
- const player = add([sprite("player"), area(), solid()]);
1353
-
1354
- // both should be solid
1355
- add([sprite("rock"), area(), solid()]);
1356
-
1357
- keyDown("left", () => {
1358
- // this will handle collision resolution for you, if the other obj is also "solid"
1359
- player.move(-120, 0);
1360
- });
1361
- ```
1362
-
1363
- - added comp `opacity()` to set opacity
1364
- - added comp `health()` to manage health related logic
1365
- - added comp `move()` to manage projectile-like behavior
1366
- - added comp `cleanup()` to auto destroy obj when it leaves screen
1367
- - added comp `outline()` to draw a lil outline
1368
- - added comp `timer()` to attach timers to a game obj
1369
- - added comp `fixed()` to make a game obj unaffected by camera
1370
- - added comp `stay()` to make a game obj stay after scene switch
1371
- - added comp `lifespan()` to destroy game obj after certain amount of time
1372
- - added comp `z()` to define draw order for objs on the same layer
1373
- - added `weight` to `BodyComp` and `BodyCompOpt` to control the gravity
1374
- multiplier
1375
- - added `djump()` to `BodyComp` for double jump
1376
- - added `dir()` to calculate directional vector from angle
1377
- - added constants `LEFT`, `RIGHT`, `UP`, `DOWN` for unit directional vector
1378
- - added `fullscreen()` to enable real fullscreen mode
1379
- - **BREAK** separated color and opacity, removed `rgba()` in favor of `rgb`, use
1380
- component `opacity()` to define opacity
1381
- - **BREAK** changed color from 0-1 range to 0-255, angles from radians to
1382
- degrees
1383
-
1384
- ```js
1385
- // before
1386
- add([rotate(Math.PI / 2), color(0, 0.5, 1.0, 0.5)]);
1387
-
1388
- // after
1389
- add([rotate(90), color(0, 127, 255), opacity(0.5)]);
1390
- ```
1391
-
1392
- - `global` and `debug` flag now are enabled by default, need to turn off
1393
- manually if you don't want
1394
- - added input events `touchStart(id, pos)`, `touchMove(id, pos)`,
1395
- `touchEnd(id, pos)`, `mouseMove(pos)`
1396
- - added `mouseDeltaPos()`
1397
- - added `touchToMouse` to control if touch events should be translated to mouse
1398
- events
1399
- - added `mousePos()` now gets the screen mouse pos, use `mouseWorldPos()` to get
1400
- the mouse position affected by camera
1401
- - added `anim` field in `SpriteCompOpt` to play an anim on start
1402
- - better type support for components
1403
- - `scene()` and `start()` (also removed in favor of `go()`) are optional now, if
1404
- you don't need multiple scenes yet you can just go directly
1405
-
1406
- ```js
1407
- kaboom();
1408
- // no mandatory scene() to start kabooming
1409
- add(...);
1410
- keyPress(...);
1411
- ```
1412
-
1413
- - **BREAK** `area()` is now explicit and not automatically added by `sprite()`,
1414
- `rect()`, and `text()`, removed each `noArea` or `area` config field
1415
- - **BREAK** `area()` now takes an `AreaCompOpt`, where you can define the area
1416
- size, scale, and hover cursor
1417
-
1418
- ```js
1419
- add([
1420
- sprite("bean"),
1421
- area(), // empty area will derive from sprite size
1422
- area({ scale: 0.5 }), // 0.5x the sprite size
1423
- area({ offset: vec2(0, 12), width: 4, height: 12 }), // more control over the collider region
1424
- ]);
1425
- ```
1426
-
1427
- - **BREAK** renamed `isCollided()` to `isColliding()`, `isHovered()` to
1428
- `isHovering()`
1429
- - **BREAK** removed `overlaps()` and `isOverlapped()` and replaced with
1430
- `isColliding()` and `collides()` only checks doesn't return true when 2
1431
- objects are just touching each other, use `isTouching()` to check if they're
1432
- not colliding but just touching each other
1433
- - added `isTouching()` to check if 2 objects are collided or just touching other
1434
- - audio is now paused when you leave the tab
1435
- - audio is now paused on `debug.paused = true`
1436
- - added local storage helper `getData(key, default?)` and `setData(key, data)`
1437
- - added `loadShader(id, vert, frag, isUrl)`
1438
- - added `shader()` comp for attaching custom shader to an obj
1439
- - different layers do not prevent collisions now
1440
- - **BREAK** changed last argument of `loadFont()` to `FontLoadOpt`
1441
- - all event handlers like `keyPress()`, `mouseClick()`, `action()`, `collides()`
1442
- now returns a function to cancel that listener
1443
- - added `require` on component definitions, making it possible to declare
1444
- dependencies for components, e.g.
1445
-
1446
- ```js
1447
- function alwaysRight() {
1448
- return {
1449
- // the id of this component
1450
- id: "alwaysRight",
1451
- // list of component ids that this requires
1452
- require: ["pos"],
1453
- update() {
1454
- // so you can use `move()` from pos() component with no worry
1455
- this.move(100, 0);
1456
- },
1457
- };
1458
- }
1459
- ```
1460
-
1461
- - **BREAK** overlapping component fields are not allowed, e.g. you can't have a
1462
- custom comp that has a `collides` field if it already have a `area` component,
1463
- since it already has that
1464
- - **BREAK** changed `text(txt, size, conf)` to `text(txt, conf)` with `size` as
1465
- a field
1466
- - added `obj.c(id)` for getting a specific comp's state (by default all comps'
1467
- states are mounted to the obj by `Object.defineProperty`)
1468
-
1469
- ```js
1470
- // both works
1471
- obj.play("anim");
1472
- obj.c("sprite").play("anim");
1473
- ```
1474
-
1475
- - pedit, aseprite plugins are now included by default
1476
- - added `addKaboom()` for quick kaboom explosion
1477
- - `load*()` now accepts `null` as name and not load into assets manager, instead
1478
- just return the resource data handle
1479
- - **BREAK** renamed event `headbump` to `headbutt`
1480
- - **BREAK** renamed event `grounded` to `ground`
1481
- - added `width`, `height`, and `tiled` attrib to `SpriteCompOpt`, for better
1482
- control over sprite size and tiled sprite support
1483
- - **BREAK** renamed `resolve()` to `pushOutAll()` on `area` comp
1484
- - added `pushOut()` for pushing a single object out from another with `area`
1485
- comp
1486
- - fixed `"add"` event getting called twice for tagged objs
1487
- - added `moveTo(dest: Vec2, speed?: number)` to `pos()` comp
1488
- - added `keyPress()` (and all other key events) with no arg to check for any key
1489
- - **BREAK** renamed `camShake()` to `shake()`
1490
- - added `flipX` and `flipY` on `sprite()` comp configuration, and `flipX()`
1491
- `flipY()` methods
1492
- - **BREAK** remove `flipX()` and `flipY()` on `scale()` comp
1493
- - **BREAK** removed `start()` in favor of `go()`
1494
- - **BREAK** removed `changeSprite()` in favor of `use(sprite("newsprite"))`
1495
- - tags and components are converged, tags are just empty components now
1496
- - added `unuse()` to remove a component or tag
1497
- - **BREAK** removed `rmTag()` in favor of `unuse()`
1498
- - **BREAK** removed `camIgnore()` in favor of `fixed()`
1499
- - **BREAK** renamed `makeRng()` to `rng()`
1500
- - sprite animation now supports defining properties like loop and speed in load
1501
- step and play step
1502
-
1503
- ```js
1504
- loadSprite("hero", "hero.png", {
1505
- sliceX: 9,
1506
- anims: {
1507
- idle: { from: 0, to: 3, speed: 3, loop: true },
1508
- run: { from: 4, to: 7, speed: 10, loop: true },
1509
- hit: 8,
1510
- },
1511
- });
1512
- ```
1513
-
1514
- - **BREAK** changed `.play(anim, ifLoop)` under `sprite()` to accept a dict of
1515
- properties `.play(anim, { loop: true, speed: 60, pingpong: true })`
1516
- - **BREAK** now every symbol definition in `addLevel()` should be a function
1517
- returning the component list, to ensure there's no weird shared states
1518
-
1519
- ```js
1520
- addLevel(["* *", "* *", "======"], {
1521
- "*": () => [sprite("wall"), area(), solid()],
1522
- "=": () => [sprite("floor"), area(), solid()],
1523
- });
1524
- ```
1525
-
1526
- - **BREAK** renamed `clearColor` to `background`
1527
- - added collision detection functions `testLineLine()`, `testRectRect()`,
1528
- `testRectLine()` etc.
1529
- - added drawing functions `drawSprite()`, `drawRect()`, `drawCircle()`,
1530
- `drawPolygon()`, `drawEllipse()`, `drawLine()`, `drawLines()`
1531
- - added transformation functions `pushTransform()`, `popTransform()`,
1532
- `pushTranslate()`, `pushRotate()`, `pushScale()`
1533
- - **BREAK** removed `areaWidth()` and `areaHeight()` since they won't make sense
1534
- if the area shape is not rectangle, use `worldArea()` if you need area data
1535
-
1536
- ```js
1537
- const area = player.worldArea();
1538
- if (area.shape === "rect") {
1539
- const width = area.p2.x - area.p1.x;
1540
- const height = area.p2.y - area.p1.y;
1541
- }
1542
- ```
1543
-
1544
- ### v0.5.1
1545
-
1546
- - added plugins npm package support e.g.
1547
- `import asepritePlugin from "kaboom/plugins/aseprite"`
1548
-
1549
- ## [0.5.0] "Sticky Type" - 2021-05-11 (kaboom.js)
1550
-
1551
- - platforms are now sticky
1552
- - moved to TypeScript
1553
- - improved graphics performance
1554
- - improved inspect drawing performance
1555
- - added on-screen log that catches all kinds of errors
1556
- - added `cursor()`
1557
- - added `curPlatform()` by `body()`
1558
- - added `falling()` by `body()`
1559
- - added `changeSprite()` by `sprite()`
1560
- - added `duration()` and `time()` for the handle returned by `play()`
1561
- - added optional `seek` field to the audio play conf `play([conf])`
1562
- - added `LoopHandle` returned by `loop()` that has a `stop()`
1563
- - added a default background (can be dismissed by setting `clearColor`)
1564
- - fixed `sound.pause()` to work on firefox
1565
- - fixed collisions not treating explicit default layer the same as implicit
1566
- default layer
1567
- - fixed unable to play another anim in `onAnimEnd()`
1568
- - fixed scene switches happen in the middle of a frame
1569
- - fixed `scale(0)` not working
1570
- - fixed `mousePos()` not returning the camera affected pos with no layers
1571
- - **BREAK** changed `dbg()` to plain `debug` object
1572
- - **BREAK** moved `fps()`, `objCount()`, `stepFrame()`, `log()`, `error()` under
1573
- `debug`
1574
- - **BREAK** removed `debug.logTime`
1575
- - **BREAK** changed component `debugInfo()` hook to `inspect()`
1576
- - **BREAK** removed `timer()` component
1577
- - **BREAK** renamed `removeTag()` to `rmTag()`
1578
- - **BREAK** changed `SpriteAnim` from `[ from, to ]` to
1579
- `{ from: number, to: number }`
1580
- - **BREAK** removed `onAnimPlay()` and `onAnimEnd()` in favor of generic event
1581
- `on("animEnd", (anim: string) => {})`
1582
- - **BREAK** removed `obj.addTag()` in favor of `obj.use()`
1583
- - **BREAK** merged `debug.hoverInfo` and `debug.showArea` into `debug.inspect`
1584
- - **BREAK** removed `sound.resume()` in favor of `sound.play()`
1585
-
1586
- ### v0.4.1
1587
-
1588
- - fixed `on("destroy")` handler getting called twice
1589
- - fixed sprite `play()` not playing
1590
-
1591
- ## [0.4.0] "Multiboom" - UNKNOWN (kaboom.js)
1592
-
1593
- - **BREAK** removed `init()` and `kaboom.global()`, in favor of `kaboom()`, also
1594
- allows multiple kaboom games on one page
1595
-
1596
- ```js
1597
- // replaces init(), and added a 'global' flag for previous kaboom.global()
1598
- kaboom({
1599
- global: true,
1600
- width: 480,
1601
- height: 480,
1602
- });
1603
- ```
1604
-
1605
- or not global
1606
-
1607
- ```js
1608
- const k = kaboom();
1609
- k.scene();
1610
- k.start();
1611
- k.vec2();
1612
- ```
1613
-
1614
- - **BREAK** changed `clearColor` on `kaboom(conf)` to accept a 4 number array
1615
- instead of `rgba()`
1616
- - added a plugin system, see the `multiboom` example and `src/plugins`
1617
- - **BREAK** removed support for `.kbmsprite`, supports newer version of `.pedit`
1618
- through pedit plugin
1619
- - **BREAK** `loadAseprite()` and made it an external plugin under
1620
- `plugins/aseprite.js`
1621
- - added `sceneData()` for custom scene data kv store
1622
- - fixed `mouseClick` doesn't work on mobile
1623
- - disabled context menu on canvas
1624
- - prevented default behavior for 'tab' and function keys
1625
- - added `numFrames()` by `sprite()`
1626
- - added `screenshot()` that returns of a png base64 data url for a screenshot
1627
-
1628
- ## [0.3.0] "King Dedede...Bug!" - UNKNOWN
1629
-
1630
- - **BREAK** removed `pause()` and `paused()` in favor to `kaboom.debug.paused`
1631
- - **BREAK** removed `velY`, `curPlatform` and `maxVel` fields by `body()`
1632
- - **BREAK** changed `curAnim` by `sprite()` to method `curAnim()`
1633
- - fixed `dt()` surge on page visibility change (#20)
1634
- - pause audio when page is not visible
1635
- - added built in debug control with `init({ debug: true, })`
1636
- - `` ` ``: toggle `showLog` (default on with `debug: true`)
1637
- - `f1`: toggle `showArea`
1638
- - `f2`: toggle `hoverInfo`
1639
- - `f8`: toggle `paused`
1640
- - `f7`: decrease `timeScale`
1641
- - `f9`: increase `timeScale`
1642
- - `f10`: `stepFrame()`
1643
- - added on screen logging with `log()` and `error()`
1644
- - fixed `loadRoot()` sometimes doesn't work in async tasks
1645
-
1646
- ## [0.2.0] "Hear the Tremble" - UNKNOWN
1647
-
1648
- - **BREAK** removed `aseSpriteSheet` conf field from
1649
- `loadSprite(name, src, conf)`
1650
- - added `pause()`, `resume()`, `stop()`, `loop()`, `unloop()`, `volume()`,
1651
- `detune()`, `speed()` methods to the handle returned by `play()`
1652
- - added `camShake()` for built in camera shake
1653
- - added `loadAseprite(name, imgSrc, jsonSrc)`
1654
- - added area component generation for `text()`
1655
- - added `noArea` to conf field of `sprite()`, `rect()` and `text()`, allowing to
1656
- disable auto area component generation
1657
- - added a `quad` field to sprite comp creation config
1658
- `sprite(id, { quad: quad(0, 0, 0.5, 0.5) })`
1659
- - fixed `resolve()` not working if the obj also has `solid`, so it does not
1660
- check for itself (#8)
1661
- - `mousePos()` accepts a layer argument, which returns the mouse position
1662
- affected by camera transform if that layer is not `camIgnore()`-ed
1663
- - fixed camera position getting calculated before completing every object's
1664
- update (#14)
1665
- - fixed some cases `on("grounded", f)` called multiple times when moving on a
1666
- smooth platform
1667
- - added `revery()` to iterate objects in reverse order
1668
- - added `readd()` to re-add an object to the scene without triggering events
1669
- - added `level.spawn()`
1670
-
1671
- ## [0.1.0] "Oh Hi Mark" -
1672
-
1673
- - **BREAK** changed default origin point to `"topleft"`, so if you want object
1674
- origin point to be at center you'll need to manual `origin("center")`
1675
- - **BREAK** integrated `kit/physics` and `kit/level` to main lib
1676
- - **BREAK** makes `collides()` only run on first collision, not run every frame
1677
- during the same collision
1678
- - **BREAK** `camPos()` by default focuses to center, so `camPos(player.pos)`
1679
- puts player in the center of the screen
1680
- - **BREAK** renamed `kaboom.import()` to `kaboom.global()`
1681
- - added an arg field to `start(scene, ...)` to forward args to start scene
1682
- - added `camScale()`, `camRot()` and `camIgnore()`
1683
- - added `obj.overlaps()` by `area()`, and `overlaps()`
1684
- - added 3 ext fonts under `ext/fonts`
3
+ The changelog of this project can be found
4
+ (here)[https://github.com/kaplayjs/kaplay/blob/master/CHANGELOG.md]