@hi-ashleyj/llama 0.8.0 → 0.8.2

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.
@@ -2,7 +2,7 @@
2
2
  import { onMount } from "svelte";
3
3
  export let zIndex = 0;
4
4
  export let staticMode = false;
5
- let hasRenderedOnce = false;
5
+ let shouldRenderNextFrame = true;
6
6
  let canvas;
7
7
  $: ctx = (typeof canvas !== "undefined") ? canvas.getContext("2d") : null;
8
8
  let targets = new Set();
@@ -21,12 +21,12 @@ let register = setupLayer({
21
21
  requestFrame: () => {
22
22
  if (!staticMode)
23
23
  return;
24
- draw();
24
+ shouldRenderNextFrame = true;
25
25
  }
26
26
  });
27
27
  onMount(() => {
28
- return register({ draw, isStatic: () => { if (!hasRenderedOnce) {
29
- hasRenderedOnce = true;
28
+ return register({ draw, isStatic: () => { if (shouldRenderNextFrame) {
29
+ shouldRenderNextFrame = false;
30
30
  draw();
31
31
  } return staticMode; } });
32
32
  });
@@ -44,4 +44,4 @@ onMount(() => {
44
44
  height: 100%;
45
45
  object-fit: contain;
46
46
  }
47
- </style>
47
+ </style>
@@ -9,20 +9,22 @@ export let stroke = undefined;
9
9
  export let alignH = "left";
10
10
  export let alignV = "top";
11
11
  $: computedFont = ((style) ? style + " " : "") + size + "px " + font;
12
- const draw = function ({ ctx }, { x, y }) {
12
+ const draw = function ({ ctx }, { x, y, w, h }) {
13
13
  if (!text)
14
14
  return;
15
15
  ctx.beginPath();
16
16
  ctx.textAlign = alignH;
17
17
  ctx.textBaseline = alignV;
18
18
  ctx.font = computedFont;
19
+ let actualX = x + (alignH === "right" ? w : alignH === "center" ? w / 2 : 0);
20
+ let actualY = y + (alignV === "bottom" ? h : alignV === "middle" ? (h / 2) + (size * 0.10) : 0);
19
21
  if (fill) {
20
22
  ctx.fillStyle = fill;
21
- ctx.fillText(text, x, y);
23
+ ctx.fillText(text, actualX, actualY);
22
24
  }
23
25
  if (stroke) {
24
26
  ctx.strokeStyle = stroke;
25
- ctx.strokeText(text, x, y);
27
+ ctx.strokeText(text, actualX, actualY);
26
28
  }
27
29
  };
28
30
  let register = setupDrawable({});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hi-ashleyj/llama",
3
3
  "description": "A (Very Incomplete) 2D Canvas Game Engine powered by Svelte",
4
- "version": "0.8.0",
4
+ "version": "0.8.2",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",