-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`clipImageSprite` no longer sets the `width` and `height` only one `source_loaded` promise is ever made by `Sprite`
- Loading branch information
Showing
6 changed files
with
321 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<script src="./index.ts" type="module"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Sprite, JAtlasManager } from "../../src/mod.ts" | ||
|
||
const | ||
FPS = 60, | ||
W = 800, | ||
H = 600, | ||
canvas = document.createElement("canvas")!, | ||
ctx = canvas.getContext("2d")!, | ||
sprites: Sprite[] = [] | ||
|
||
JAtlasManager.fromURL("./manuscript.jpg.jatlas.json") | ||
.then(async (new_atlas_man) => { | ||
await new_atlas_man.source_loaded | ||
await new_atlas_man.entries_loaded | ||
window.atlas_man = new_atlas_man | ||
for (const id of Object.keys(new_atlas_man.entries)) { | ||
const | ||
new_sprite = new_atlas_man.getEntryImageSprite(parseFloat(id)), | ||
scale = 0.33 | ||
new_sprite.source_loaded | ||
.then((s) => { | ||
const { width, height } = s.bitmap! | ||
s.setConfig({ | ||
x: Math.random() * W, | ||
y: Math.random() * H, | ||
width: width * scale, | ||
height: height * scale, | ||
}) | ||
}) | ||
sprites.push(new_sprite) | ||
} | ||
}) | ||
|
||
|
||
document.body.appendChild(canvas) | ||
canvas.width = W | ||
canvas.height = H | ||
let t = 0 | ||
const | ||
drawAll = () => { | ||
ctx.resetTransform() | ||
ctx.fillStyle = "yellow" | ||
ctx.fillRect(0, 0, W, H) | ||
for (const sprite of sprites) { | ||
sprite.coords[0] += 50 / FPS * Math.random() | ||
sprite.coords[1] += 50 / FPS * Math.random() | ||
if (sprite.coords[0] > W) sprite.coords[0] = 0 | ||
if (sprite.coords[1] > H) sprite.coords[1] = 0 | ||
sprite.draw(ctx) | ||
} | ||
t += 1 / FPS | ||
}, | ||
RUN = setInterval(requestAnimationFrame, 1 / FPS, drawAll) | ||
|
||
Object.assign(window, { | ||
drawAll, RUN, canvas, ctx, sprites | ||
}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.